summaryrefslogtreecommitdiff
path: root/goodies/inc/b3dtex.hxx
blob: e10188d901256efe31183853e56b62c55e233449 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: b3dtex.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 02:13:41 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _B3D_B3DTEX_HXX
#define _B3D_B3DTEX_HXX

#ifndef _SV_OPENGL_HXX
#include <vcl/opengl.hxx>
#endif

#ifndef _SV_BITMAPEX_HXX
#include <vcl/bitmapex.hxx>
#endif

#ifndef _TOOLS_COLOR_HXX
#include <tools/color.hxx>
#endif

#ifndef _SV_SALBTYPE_HXX
#include <vcl/salbtype.hxx>
#endif

#ifndef _TOOLS_TIME_HXX
#include <tools/time.hxx>
#endif

// Vorausdeklarationen
class BitmapReadAccess;
class BitmapColor;

/*************************************************************************
|*
|* define for lifetime of a texture in texture cache.
|* Parameter of Time(...) call, so hrs, min, sec, 100thsec.
|* Timer for cache uses ten secs delays
|*
\************************************************************************/

#define B3D_TEXTURE_LIFETIME                0, 1, 0

/*************************************************************************
|*
|* Long-Zeiger fuer OpenGL Texturdatenuebergabe
|*
\************************************************************************/

#ifdef WIN
typedef UINT8 huge* GL_UINT8;
#else
typedef UINT8*      GL_UINT8;
#endif

/*************************************************************************
|*
|* Art der Pixeldaten der Textur
|*
\************************************************************************/

enum Base3DTextureKind
{
    Base3DTextureLuminance = 1,
    Base3DTextureIntensity,
    Base3DTextureColor
};

/*************************************************************************
|*
|* Modus der Textur
|*
\************************************************************************/

enum Base3DTextureMode
{
    Base3DTextureReplace = 1,
    Base3DTextureModulate,
    Base3DTextureBlend
};

/*************************************************************************
|*
|* Filtermodus der Textur
|*
\************************************************************************/

enum Base3DTextureFilter
{
    Base3DTextureNearest = 1,
    Base3DTextureLinear
};

/*************************************************************************
|*
|* Wrapping-Modus
|*
\************************************************************************/

enum Base3DTextureWrap
{
    Base3DTextureClamp = 1,
    Base3DTextureRepeat,
    Base3DTextureSingle
};

/*************************************************************************
|*
|* Defines fuer Maskenbildung um Entscheidung innerhalb von ModifyColor
|* zu beschleunigen
|*
\************************************************************************/

#define B3D_TXT_KIND_LUM        0x00
#define B3D_TXT_KIND_INT        0x01
#define B3D_TXT_KIND_COL        0x02

#define B3D_TXT_MODE_REP        0x04
#define B3D_TXT_MODE_MOD        0x08
#define B3D_TXT_MODE_BND        0x0C

#define B3D_TXT_FLTR_NEA        0x10

/*************************************************************************
|*
|* Klassen fuer TexturAttribute beim Anfordern von Texturen
|*
\************************************************************************/

#define TEXTURE_ATTRIBUTE_TYPE_COLOR            0x0000
#define TEXTURE_ATTRIBUTE_TYPE_BITMAP           0x0001
#define TEXTURE_ATTRIBUTE_TYPE_GRADIENT         0x0002
#define TEXTURE_ATTRIBUTE_TYPE_HATCH            0x0003

class TextureAttributes
{
private:
    void*           mpFloatTrans;
    BOOL            mbGhosted;

public:
    TextureAttributes(BOOL bGhosted, void* pFT);

    virtual BOOL operator==(const TextureAttributes&) const;
    virtual UINT16 GetTextureAttributeType() const =0;

    BOOL GetGhostedAttribute() { return mbGhosted; }
    void* GetFloatTransAttribute() { return mpFloatTrans; }
};

class TextureAttributesColor : public TextureAttributes
{
private:
    Color           maColorAttribute;

public:
    TextureAttributesColor(BOOL bGhosted, void* pFT, Color aColor);

    virtual BOOL operator==(const TextureAttributes&) const;
    virtual UINT16 GetTextureAttributeType() const;

    Color GetColorAttribute() { return maColorAttribute; }
};

class TextureAttributesBitmap : public TextureAttributes
{
private:
    Bitmap          maBitmapAttribute;

public:
    TextureAttributesBitmap(BOOL bGhosted, void* pFT, Bitmap aBmp);

    virtual BOOL operator==(const TextureAttributes&) const;
    virtual UINT16 GetTextureAttributeType() const;

    Bitmap GetBitmapAttribute() { return maBitmapAttribute; }
};

class TextureAttributesGradient : public TextureAttributes
{
private:
    void*           mpFill;
    void*           mpStepCount;

public:
    TextureAttributesGradient(BOOL bGhosted, void* pFT, void* pF, void *pSC);

    virtual BOOL operator==(const TextureAttributes&) const;
    virtual UINT16 GetTextureAttributeType() const;

    void* GetFillAttribute() { return mpFill; }
    void* GetStepCountAttribute() { return mpStepCount; }
};

class TextureAttributesHatch : public TextureAttributes
{
private:
    void*           mpFill;

public:
    TextureAttributesHatch(BOOL bGhosted, void* pFT, void* pF);

    virtual BOOL operator==(const TextureAttributes&) const;
    virtual UINT16 GetTextureAttributeType() const;

    void* GetHatchFillAttribute() { return mpFill; }
};

/*************************************************************************
|*
|* Klasse fuer Texturen in Base3D
|*
\************************************************************************/

class B3dTexture
{
protected:
    // Die Bitmap(s) der Textur
    Bitmap                  aBitmap;
    AlphaMask               aAlphaMask;
    BitmapReadAccess*       pReadAccess;
    BitmapReadAccess*       pAlphaReadAccess;

    // Attribute bei der Generierung
    TextureAttributes*      pAttributes;

    // Gibt die Haeufigkeit der Benutzung wieder
    Time                    maTimeStamp;

    // Farbe fuer Base3DTextureBlend - Modus
    BitmapColor             aColBlend;

    // Farbe, wenn keine Textur an einer Stelle liegt
    BitmapColor             aColTexture;

    // Art der Textur
    Base3DTextureKind       eKind;

    // Modus der Textur
    Base3DTextureMode       eMode;

    // Filter
    Base3DTextureFilter     eFilter;

    // Wrapping-Modes fuer beide Freiheitsgrade
    Base3DTextureWrap       eWrapS;
    Base3DTextureWrap       eWrapT;

    // Entscheidungsvariable
    UINT8                   nSwitchVal;

    // Vorbestimmbare interne booleans
    unsigned                bTextureKindChanged : 1;

    // Konstruktor / Destruktor
    B3dTexture(TextureAttributes& rAtt,
        BitmapEx& rBmpEx,
        Base3DTextureKind=Base3DTextureColor,
        Base3DTextureMode=Base3DTextureReplace,
        Base3DTextureFilter=Base3DTextureNearest,
        Base3DTextureWrap eS=Base3DTextureSingle,
        Base3DTextureWrap eT=Base3DTextureSingle);
    virtual ~B3dTexture();

    // Interne Zugriffsfunktion auf die BitMapFarben
    inline const BitmapColor GetBitmapColor(long nX, long nY);
    inline const sal_uInt8 GetBitmapTransparency(long nX, long nY);

    // Generate switch val for optimized own texture mapping
    void SetSwitchVal();

    // time stamp and texture cache methods
    void Touch() { maTimeStamp = Time() + Time(B3D_TEXTURE_LIFETIME); }
    const Time& GetTimeStamp() const { return maTimeStamp; }

public:
    // Zugriff auf die Attribute der Textur
    TextureAttributes& GetAttributes();

    // Zugriff auf Bitmap
    Bitmap& GetBitmap() { return aBitmap; }
    AlphaMask& GetAlphaMask() { return aAlphaMask; }
    BitmapEx GetBitmapEx() { return BitmapEx(aBitmap, aAlphaMask); }
    const Size GetBitmapSize() { return aBitmap.GetSizePixel(); }

    // Texturfunktion
    void ModifyColor(Color& rCol, double fS, double fT);

    // Art der Pixeldaten lesen/bestimmen
    void SetTextureKind(Base3DTextureKind eNew);
    Base3DTextureKind GetTextureKind() { return eKind; }

    // Texturmodus lesen/bestimmen
    void SetTextureMode(Base3DTextureMode eNew);
    Base3DTextureMode GetTextureMode() { return eMode; }

    // Filtermodus lesen/bestimmen
    void SetTextureFilter(Base3DTextureFilter eNew);
    Base3DTextureFilter GetTextureFilter() { return eFilter; }

    // Wrapping fuer beide Freiheitsgrade lesen/bestimmen
    void SetTextureWrapS(Base3DTextureWrap eNew);
    Base3DTextureWrap GetTextureWrapS() { return eWrapS; }
    void SetTextureWrapT(Base3DTextureWrap eNew);
    Base3DTextureWrap GetTextureWrapT() { return eWrapT; }

    // Blend-Color lesen/bestimmen
    void SetBlendColor(Color rNew);
    Color GetBlendColor();

    // Textur-Ersatz-Color lesen/bestimmen
    void SetTextureColor(Color rNew);
    Color GetTextureColor();

protected:
    // Zugriff auf Konstruktor/Destruktor nur fuer die verwaltenden Klassen
    friend class Base3D;
    friend class Base3DOpenGL;
    friend class B3dGlobalData;
    friend class B3dTextureStore;
};

/*************************************************************************
|*
|* erweiterte Klasse fuer Texturen in Base3DOpenGL
|*
\************************************************************************/

class B3dTextureOpenGL : public B3dTexture
{
private:
    // Name dieser Textur in OpenGL
    GLuint                  nTextureName;

    // Konstruktor / Destruktor
    B3dTextureOpenGL(TextureAttributes& rAtt,
        BitmapEx& rBmpEx,
        OpenGL& rOGL,
        Base3DTextureKind=Base3DTextureColor,
        Base3DTextureMode=Base3DTextureReplace,
        Base3DTextureFilter=Base3DTextureNearest,
        Base3DTextureWrap eS=Base3DTextureClamp,
        Base3DTextureWrap eT=Base3DTextureClamp);
    virtual ~B3dTextureOpenGL();

    // In OpenGL die Textur zerstoeren
    void DestroyOpenGLTexture(OpenGL&);

public:
    // Setze diese Textur in OpenGL als aktuelle Textur
    void MakeCurrentTexture(OpenGL&);

    // Erzeuge diese Textur als OpenGL-Textur
    void CreateOpenGLTexture(OpenGL&);

protected:
    // Zugriff auf Konstruktor/Destruktor nur fuer die verwaltenden Klassen
    friend class Base3D;
    friend class Base3DOpenGL;
    friend class B3dTextureStore;
};


#endif          // _B3D_B3DTEX_HXX