~hikiko/nux/arb-srgba-shader

« back to all changes in this revision

Viewing changes to NuxGraphics/GLResource.h

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-02 03:28:11 UTC
  • Revision ID: neil.patel@canonical.com-20100902032811-i2m18tfb6pkasnvt
Remove Win EOL chars

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
 
22
22
 
23
 
#ifndef GLRESOURCE_H
24
 
#define GLRESOURCE_H
25
 
 
26
 
#include "NuxCore/NKernel.h"
27
 
#include "NuxCore/NNamespace.h"
28
 
#include "NuxCore/NSystemTypes.h"
29
 
#include "NuxCore/Error.h"
30
 
#include "NuxCore/FilePath.h"
31
 
#include "NuxCore/Color.h"
32
 
#include "NuxCore/Rect.h"
33
 
#include "NuxCore/Point.h"
34
 
#include "NuxCore/Size.h"
35
 
#include "NuxImage/BitmapFormats.h"
36
 
#include "NuxCore/NParsing.h"
37
 
 
38
 
#include "NuxCore/Math/MathUtility.h"
39
 
#include "NuxCore/Math/Constants.h"
40
 
#include "NuxCore/Math/Vector3.h"
41
 
#include "NuxCore/Math/Vector4.h"
42
 
#include "NuxCore/Math/Matrix3.h"
43
 
#include "NuxCore/Math/Matrix4.h"
44
 
#include "NuxCore/Math/Spline.h"
45
 
#include "NuxCore/Math/MathFunctions.h"
46
 
 
47
 
#include "NuxImage/ImageSurface.h"
48
 
#include "NuxImage/Tga.h"
49
 
#include "NuxImage/Bmp.h"
50
 
#include "NuxImage/NPng.h"
51
 
 
52
 
#define NAMESPACE_BEGIN_OGL  namespace nux {
53
 
#define NAMESPACE_END_OGL    }
54
 
 
55
 
NAMESPACE_BEGIN_OGL
56
 
class IOpenGLResource;
57
 
 
58
 
class NTexture;
59
 
class NTexture2D;
60
 
class NRectangleTexture;
61
 
class NTextureCube;
62
 
class NTextureVolume;
63
 
class NAnimatedTexture;
64
 
 
65
 
class NVertexBuffer;
66
 
class NIndexBuffer;
67
 
 
68
 
class NGLTexture2D;
69
 
class NGLRectangleTexture;
70
 
class NGLTextureCube;
71
 
class NGLTextureVolume;
72
 
class NGLAnimatedTexture;
73
 
 
74
 
NAMESPACE_END_OGL
75
 
 
76
 
#include "RunTimeStats.h"
77
 
#include "GlobalGraphicsInitializer.h"
78
 
 
79
 
#define NUX_ENABLE_CG_SHADERS 0
80
 
 
81
 
#if defined(INL_OS_WINDOWS)
82
 
    #include "OpenGL/Glew/glew.h"
83
 
    #include "OpenGL/Glew/wglew.h"
84
 
 
85
 
    GLEWContext* glewGetContext();
86
 
    WGLEWContext* wglewGetContext();
87
 
 
88
 
    #if (NUX_ENABLE_CG_SHADERS)
89
 
        #include "CG/cg.h"
90
 
        #include "CG/cgGL.h"
91
 
        #pragma comment( lib, "cg.lib" )
92
 
        #pragma comment( lib, "cgGL.lib"  )
93
 
    #endif
94
 
 
95
 
#elif defined(INL_OS_LINUX)
96
 
    #define GLEW_MX
97
 
    #include "GL/glew.h"
98
 
    #include "GL/glxew.h"
99
 
    
100
 
    GLEWContext* glewGetContext();
101
 
    GLXEWContext* glxewGetContext();
102
 
 
103
 
    #if (NUX_ENABLE_CG_SHADERS)
104
 
        #include "Cg/cg.h"
105
 
        #include "Cg/cgGL.h"
106
 
    #endif
107
 
#endif
108
 
 
109
 
#include "GLError.h"
110
 
 
111
 
#define CG_FRAGMENT_PROFILE CG_PROFILE_FP30
112
 
#define CG_VERTEX_PROFILE CG_PROFILE_VP30
113
 
 
114
 
#define INL_BUFFER_OFFSET(i) ((BYTE *)NULL + (i))
115
 
 
116
 
 
117
 
NAMESPACE_BEGIN_OGL
118
 
 
119
 
enum
120
 
{
121
 
    OGL_OK = 0,
122
 
    OGL_ERROR,
123
 
    OGL_ERROR_UNKNOWN,
124
 
    OGL_INVALID_SURFACE_LEVEL,
125
 
    OGL_INVALID_CALL,
126
 
    OGL_INVALID_LOCK,
127
 
    OGL_INVALID_UNLOCK,
128
 
    OGL_INVALID_TEXTURE,
129
 
    OGL_FORCE_DWORD            = 0x7fffffff /* force 32-bit size enum */
130
 
};
131
 
 
132
 
extern const TCHAR* OGLDeviceErrorMessages[];
133
 
 
134
 
#define OGL_OK 0
135
 
#define OGL_CALL(call)              \
136
 
    {                               \
137
 
        int Result = call;          \
138
 
        if(Result != OGL_OK)          \
139
 
        {nuxError(TEXT("OGL Object Error: Error # %d - (%s) "), Result,  *OGLDeviceErrorMessages[Result] );}   \
140
 
    }
141
 
 
142
 
//if(Result!=OGL_OK) {nuxError(TEXT("OGL Object Error: Error # %d - %s"), Result, OGLDeviceErrorMessages[Result]);}
143
 
 
144
 
enum TEXTURE_FORMAT
145
 
{
146
 
    TEXTURE_FMT_UNKNOWN              = 0,
147
 
    TEXTURE_FMT_ALPHA                = GL_ALPHA,
148
 
    TEXTURE_FMT_ALPHA8               = GL_ALPHA8,
149
 
    TEXTURE_FMT_ALPHA16              = GL_ALPHA16,
150
 
 
151
 
    TEXTURE_FMT_LUMINANCE            = GL_LUMINANCE,
152
 
    TEXTURE_FMT_LUMINANCE8           = GL_LUMINANCE8,
153
 
    TEXTURE_FMT_LUMINANCE16          = GL_LUMINANCE16,
154
 
 
155
 
    TEXTURE_FMT_LUMINANCE_ALPHA      = GL_LUMINANCE_ALPHA,
156
 
    TEXTURE_FMT_LUMINANCE8_ALPHA8    = GL_LUMINANCE8_ALPHA8,
157
 
    TEXTURE_FMT_LUMINANCE16_ALPHA16  = GL_LUMINANCE16_ALPHA16,
158
 
 
159
 
    TEXTURE_FMT_INTENSITY            = GL_INTENSITY,
160
 
    TEXTURE_FMT_INTENSITY8           = GL_INTENSITY8,
161
 
    TEXTURE_FMT_INTENSITY16          = GL_INTENSITY16,
162
 
 
163
 
    TEXTURE_FMT_GL_DEPTH_COMPONENT   = GL_DEPTH_COMPONENT,
164
 
    TEXTURE_FMT_GL_DEPTH_COMPONENT24 = GL_DEPTH_COMPONENT24,
165
 
 
166
 
    TEXTURE_FMT_RGBA                 = GL_RGBA,
167
 
    TEXTURE_FMT_RGBA8                = GL_RGBA8,
168
 
    TEXTURE_FMT_RGBA16               = GL_RGBA16,
169
 
 
170
 
    TEXTURE_FMT_RGBA16F_ARB          = GL_RGBA16F_ARB,
171
 
    TEXTURE_FMT_RGBA32F_ARB          = GL_RGBA32F_ARB,
172
 
    TEXTURE_FMT_RGB                  = GL_RGB,
173
 
    TEXTURE_FMT_RGB8                 = GL_RGB8,
174
 
    TEXTURE_FMT_RGB16                = GL_RGB16,
175
 
    TEXTURE_FMT_RGB16F_ARB           = GL_RGB16F_ARB,
176
 
    TEXTURE_FMT_RGB32F_ARB           = GL_RGB32F_ARB,
177
 
 
178
 
    TEXTURE_FMT_COMPRESSED_RGB_S3TC_DXT1_EXT   = GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
179
 
    TEXTURE_FMT_COMPRESSED_RGBA_S3TC_DXT1_EXT  = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
180
 
    TEXTURE_FMT_COMPRESSED_RGBA_S3TC_DXT3_EXT  = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
181
 
    TEXTURE_FMT_COMPRESSED_RGBA_S3TC_DXT5_EXT  = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
182
 
    TEXTURE_FMT_FORCE_DWORD                    = 0x7fffffff /* force 32-bit size enum */
183
 
};
184
 
 
185
 
struct PixelFormatReadInfo
186
 
{
187
 
    const TCHAR*        Name;
188
 
    GLenum          Format;     // format use for glReadPixels
189
 
    GLenum          type;       // type use for glReadPixels
190
 
    // Format specific internal flags, e.g. whether SRGB is supported with this format
191
 
    DWORD                       Flags;
192
 
    bool                        Supported;
193
 
};
194
 
 
195
 
enum eCUBEMAP_FACES
196
 
{
197
 
    CUBEMAP_FACE_POSITIVE_X     = GL_TEXTURE_CUBE_MAP_POSITIVE_X,
198
 
    CUBEMAP_FACE_NEGATIVE_X     = GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
199
 
    CUBEMAP_FACE_POSITIVE_Y     = GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
200
 
    CUBEMAP_FACE_NEGATIVE_Y     = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
201
 
    CUBEMAP_FACE_POSITIVE_Z     = GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
202
 
    CUBEMAP_FACE_NEGATIVE_Z     = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
203
 
 
204
 
    CUBEMAP_FACE_FORCE_DWORD    = 0x7fffffff
205
 
};
206
 
 
207
 
enum VBO_USAGE
208
 
{
209
 
    VBO_USAGE_UNKNOWN   = 0,
210
 
    VBO_USAGE_STATIC    = GL_STATIC_DRAW,
211
 
    VBO_USAGE_DYNAMIC   = GL_DYNAMIC_DRAW,
212
 
    VBO_USAGE_STREAM    = GL_STREAM_DRAW,
213
 
    VBO_USAGE_FORCE_DWORD    = 0x7fffffff /* force 32-bit size enum */
214
 
};
215
 
 
216
 
enum INDEX_FORMAT
217
 
{
218
 
    INDEX_FORMAT_UNKNOWN   = 0,
219
 
    INDEX_FORMAT_USHORT    = GL_UNSIGNED_SHORT,
220
 
    INDEX_FORMAT_UINT      = GL_UNSIGNED_INT,
221
 
    INDEX_FORMAT_FORCE_DWORD    = 0x7fffffff /* force 32-bit size enum */
222
 
};
223
 
 
224
 
// Primitives supported by draw-primitive API
225
 
typedef enum {
226
 
    PRIMITIVE_TYPE_POINTLIST             = GL_POINTS,
227
 
    PRIMITIVE_TYPE_LINELIST              = GL_LINES,
228
 
    PRIMITIVE_TYPE_LINESTRIP             = GL_LINE_STRIP,
229
 
    PRIMITIVE_TYPE_TRIANGLELIST          = GL_TRIANGLES,
230
 
    PRIMITIVE_TYPE_TRIANGLESTRIP         = GL_TRIANGLE_STRIP,
231
 
    PRIMITIVE_TYPE_TRIANGLEFAN           = GL_TRIANGLE_FAN,
232
 
    PRIMITIVE_TYPE_QUADLIST              = GL_QUADS,
233
 
    PRIMITIVE_TYPE_QUADSTRIP             = GL_QUAD_STRIP,
234
 
    PRIMITIVE_TYPE_FORCE_DWORD           = 0x7fffffff /* force 32-bit size enum */
235
 
} PRIMITIVE_TYPE;
236
 
 
237
 
enum OpenGLResourceType
238
 
{
239
 
    RTINDEXBUFFER,
240
 
    RTVERTEXBUFFER,
241
 
    RTSURFACE,
242
 
    RTVOLUME,
243
 
    RTBASETEXTURE,
244
 
    RTTEXTURE,
245
 
    RTTEXTURERECTANGLE,
246
 
    RTCUBETEXTURE,
247
 
    RTVOLUMETEXTURE,
248
 
    RTANIMATEDTEXTURE,
249
 
    RTVERTEXDECLARATION,
250
 
    RTQUERY,
251
 
    RTFRAMEBUFFEROBJECT,
252
 
    RT_GLSL_VERTEXSHADER,
253
 
    RT_GLSL_PIXELSHADER,
254
 
    RT_GLSL_SHADERPROGRAM,
255
 
    RT_CG_VERTEXSHADER,
256
 
    RT_CG_PIXELSHADER,
257
 
    RT_FORCE_DWORD           = 0x7fffffff /* force 32-bit size enum */
258
 
};
259
 
 
260
 
/* Multi-Sample buffer types */
261
 
typedef enum
262
 
{
263
 
    MULTISAMPLE_TYPE_NONE            =  0,
264
 
    MULTISAMPLE_TYPE_NONMASKABLE     =  1,
265
 
    MULTISAMPLE_TYPE_2_SAMPLES       =  2,
266
 
    MULTISAMPLE_TYPE_3_SAMPLES       =  3,
267
 
    MULTISAMPLE_TYPE_4_SAMPLES       =  4,
268
 
    MULTISAMPLE_TYPE_5_SAMPLES       =  5,
269
 
    MULTISAMPLE_TYPE_6_SAMPLES       =  6,
270
 
    MULTISAMPLE_TYPE_7_SAMPLES       =  7,
271
 
    MULTISAMPLE_TYPE_8_SAMPLES       =  8,
272
 
    MULTISAMPLE_TYPE_9_SAMPLES       =  9,
273
 
    MULTISAMPLE_TYPE_10_SAMPLES      = 10,
274
 
    MULTISAMPLE_TYPE_11_SAMPLES      = 11,
275
 
    MULTISAMPLE_TYPE_12_SAMPLES      = 12,
276
 
    MULTISAMPLE_TYPE_13_SAMPLES      = 13,
277
 
    MULTISAMPLE_TYPE_14_SAMPLES      = 14,
278
 
    MULTISAMPLE_TYPE_15_SAMPLES      = 15,
279
 
    MULTISAMPLE_TYPE_16_SAMPLES      = 16,
280
 
    MULTISAMPLE_TYPE_FORCE_DWORD     = 0x7fffffff /* force 32-bit size enum */
281
 
} MULTISAMPLE_TYPE;
282
 
 
283
 
typedef enum
284
 
{
285
 
    MEM_POOL_DEFAULT = 0,
286
 
    MEM_POOL_MANAGED = 1,
287
 
    MEM_POOL_SYSTEMMEM = 2,
288
 
    MEM_POOL_SCRATCH = 3,
289
 
    MEM_POOL_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */
290
 
} MEM_POOL;
291
 
 
292
 
 
293
 
typedef struct {
294
 
    OpenGLResourceType ResourceType;
295
 
    unsigned int Width;
296
 
    unsigned int Height;
297
 
    unsigned int Depth;
298
 
    BitmapFormat PixelFormat;
299
 
    unsigned int RowPitch;
300
 
    unsigned int SlicePitch;
301
 
    unsigned int BitsPerPixel;
302
 
    unsigned int WidthInBlocks;
303
 
    unsigned int HeightInBlocks;
304
 
    unsigned int DepthInBlocks;
305
 
    unsigned int BytesPerBlock;
306
 
    int ExpBias;
307
 
    DWORD Flags;
308
 
    MULTISAMPLE_TYPE MultiSampleType;
309
 
} TEXTURE_DESC;
310
 
 
311
 
typedef struct _SURFACE_DESC
312
 
{
313
 
    BitmapFormat    PixelFormat;
314
 
    OpenGLResourceType     Type;
315
 
    DWORD               Usage;
316
 
    MEM_POOL             Pool;
317
 
 
318
 
    MULTISAMPLE_TYPE MultiSampleType;
319
 
    DWORD               MultiSampleQuality;
320
 
    unsigned int                Width;
321
 
    unsigned int                Height;
322
 
} SURFACE_DESC;
323
 
 
324
 
typedef struct _VOLUME_DESC {
325
 
    BitmapFormat PixelFormat;
326
 
    OpenGLResourceType Type;
327
 
    DWORD Usage;
328
 
    MEM_POOL Pool;
329
 
    unsigned int Width;
330
 
    unsigned int Height;
331
 
    unsigned int Depth;
332
 
} VOLUME_DESC;
333
 
 
334
 
typedef struct _ANIMATEDTEXTURE_DESC {
335
 
    BitmapFormat PixelFormat;
336
 
    OpenGLResourceType Type;
337
 
    DWORD Usage;
338
 
    MEM_POOL Pool;
339
 
    unsigned int Width;
340
 
    unsigned int Height;
341
 
    unsigned int Depth;
342
 
} ANIMATEDTEXTURE_DESC;
343
 
 
344
 
typedef struct _VERTEXBUFFER_DESC {
345
 
    VBO_USAGE Usage;
346
 
    unsigned int Size;
347
 
} VERTEXBUFFER_DESC;
348
 
 
349
 
typedef struct _INDEXBUFFER_DESC {
350
 
    INDEX_FORMAT Format;
351
 
    VBO_USAGE Usage;
352
 
    unsigned int Size;
353
 
} INDEXBUFFER_DESC;
354
 
 
355
 
typedef struct _LOCKED_RECT
356
 
{
357
 
    int Pitch;
358
 
    void * pBits;
359
 
} SURFACE_LOCKED_RECT;
360
 
 
361
 
typedef struct _SURFACE_RECT { 
362
 
    long left;      //Specifies the x-coordinate of the lower-left corner of the rectangle. 
363
 
    long top;       //Specifies the y-coordinate of the lower-left corner of the rectangle.
364
 
    long right;     //Specifies the x-coordinate of the upper-right corner of the rectangle. 
365
 
    long bottom;    //Specifies the y-coordinate of the upper-right corner of the rectangle. 
366
 
} SURFACE_RECT;
367
 
 
368
 
 
369
 
/* Structures for LockBox */
370
 
typedef struct _VOLUME_BOX
371
 
{
372
 
    unsigned int                Left;
373
 
    unsigned int                Top;
374
 
    unsigned int                Right;
375
 
    unsigned int                Bottom;
376
 
    unsigned int                Front;
377
 
    unsigned int                Back;
378
 
} VOLUME_BOX;
379
 
 
380
 
typedef struct _VOLUME_LOCKED_BOX
381
 
{
382
 
    int                 RowPitch;
383
 
    int                 SlicePitch;
384
 
    void*               pBits;
385
 
} VOLUME_LOCKED_BOX;
386
 
 
387
 
typedef enum _ATTRIB_DECL_TYPE
388
 
{
389
 
    ATTRIB_DECLTYPE_UNKNOWN = 0,
390
 
    ATTRIB_DECLTYPE_FLOAT1,
391
 
    ATTRIB_DECLTYPE_FLOAT2,
392
 
    ATTRIB_DECLTYPE_FLOAT3,
393
 
    ATTRIB_DECLTYPE_FLOAT4,
394
 
    ATTRIB_DECLTYPE_COLOR,
395
 
    ATTRIB_DECLTYPE_UBYTE4,
396
 
    ATTRIB_DECLTYPE_SHORT2,
397
 
    ATTRIB_DECLTYPE_SHORT4,
398
 
    ATTRIB_DECLTYPE_UBYTE4N,
399
 
    ATTRIB_DECLTYPE_SHORT2N,
400
 
    ATTRIB_DECLTYPE_SHORT4N,
401
 
    ATTRIB_DECLTYPE_USHORT2N,
402
 
    ATTRIB_DECLTYPE_USHORT4N,
403
 
    ATTRIB_DECLTYPE_UDEC3,
404
 
    ATTRIB_DECLTYPE_DEC3N,
405
 
    ATTRIB_DECLTYPE_FLOAT16_2,
406
 
    ATTRIB_DECLTYPE_FLOAT16_4,
407
 
    ATTRIB_DECLTYPE_UNUSED,
408
 
    ATTRIB_DECLTYPE_FORCE_DWORD           = 0x7fffffff /* force 32-bit size enum */
409
 
} ATTRIB_DECL_TYPE;
410
 
 
411
 
typedef enum _ATTRIB_COMPONENT_TYPE
412
 
{
413
 
    ATTRIB_CT_UNKNOWN           =   0,
414
 
    ATTRIB_CT_BYTE              =   GL_BYTE,
415
 
    ATTRIB_CT_UNSIGNED_BYTE     =   GL_UNSIGNED_BYTE,
416
 
    ATTRIB_CT_SHORT             =   GL_SHORT,
417
 
    ATTRIB_CT_UNSIGNED_SHORT    =   GL_UNSIGNED_SHORT,
418
 
    ATTRIB_CT_INT               =   GL_INT,
419
 
    ATTRIB_CT_UNSIGNED_INT      =   GL_UNSIGNED_INT,
420
 
    ATTRIB_CT_FLOAT             =   GL_FLOAT,
421
 
    ATTRIB_CT_HALF_FLOAT        =   GL_HALF_FLOAT_ARB,
422
 
//    ATTRIB_CT_2_BYTES           =   GL_2_BYTES,
423
 
//    ATTRIB_CT_3_BYTES           =   GL_3_BYTES,
424
 
//    ATTRIB_CT_4_BYTES           =   GL_4_BYTES,
425
 
    ATTRIB_CT_DOUBLE            =   GL_DOUBLE,
426
 
// Type can be GL_UNSIGNED_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE
427
 
    ATTRIB_CT_FORCE_DWORD           = 0x7fffffff /* force 32-bit size enum */
428
 
} ATTRIB_COMPONENT_TYPE;
429
 
 
430
 
// Binding Semantics
431
 
typedef enum
432
 
{
433
 
    ATTRIB_USAGE_DECL_POSITION       = 0,
434
 
    ATTRIB_USAGE_DECL_BLENDWEIGHT    = 1,
435
 
    ATTRIB_USAGE_DECL_NORMAL         = 2,
436
 
    ATTRIB_USAGE_DECL_COLOR          = 3,
437
 
    ATTRIB_USAGE_DECL_COLOR1         = 4,
438
 
    ATTRIB_USAGE_DECL_FOGCOORD       = 5,
439
 
    ATTRIB_USAGE_DECL_PSIZE          = 6,
440
 
    ATTRIB_USAGE_DECL_BLENDINDICES   = 7,
441
 
    ATTRIB_USAGE_DECL_TEXCOORD       = 8,
442
 
    ATTRIB_USAGE_DECL_TEXCOORD0      = 8,
443
 
    ATTRIB_USAGE_DECL_TEXCOORD1      = 9,
444
 
    ATTRIB_USAGE_DECL_TEXCOORD2      = 10,
445
 
    ATTRIB_USAGE_DECL_TEXCOORD3      = 11,
446
 
    ATTRIB_USAGE_DECL_TEXCOORD4      = 12,
447
 
    ATTRIB_USAGE_DECL_TEXCOORD5      = 13,
448
 
    ATTRIB_USAGE_DECL_TEXCOORD6      = 14,
449
 
    ATTRIB_USAGE_DECL_TEXCOORD7      = 15,
450
 
    ATTRIB_USAGE_DECL_TANGENT        = 14,
451
 
    ATTRIB_USAGE_DECL_BINORMAL       = 15,
452
 
    ATTRIB_USAGE_DECL_FORCE_DWORD           = 0x7fffffff /* force 32-bit size enum */
453
 
} ATTRIB_USAGE_DECL;
454
 
 
455
 
typedef enum {
456
 
    QUERY_TYPE_VCACHE                 = 4,
457
 
    QUERY_TYPE_RESOURCEMANAGER        = 5,
458
 
    QUERY_TYPE_VERTEXSTATS            = 6,
459
 
    QUERY_TYPE_EVENT                  = 8,
460
 
    QUERY_TYPE_OCCLUSION              = 9,
461
 
    QUERY_TYPE_SCREENEXTENT           = 10,
462
 
    QUERY_TYPE_FORCE_DWORD            = 0x7fffffff /* force 32-bit size enum */
463
 
} QUERY_TYPE;
464
 
 
465
 
// Flags field for Issue
466
 
#define ISSUE_END (1 << 0) // Tells the runtime to issue the end of a query, changing it's state to "non-signaled".
467
 
#define ISSUE_BEGIN (1 << 1) // Tells the runtime to issue the begining of a query.
468
 
 
469
 
struct VERTEXELEMENT
470
 
{
471
 
    VERTEXELEMENT()
472
 
    {
473
 
        Stream = 0;
474
 
        Offset = 0;
475
 
        Type = ATTRIB_CT_UNKNOWN;
476
 
        NumComponent = 0;
477
 
        Usage = ATTRIB_USAGE_DECL_POSITION;
478
 
        UsageIndex = 0;
479
 
        Method = 0;
480
 
    }
481
 
 
482
 
    VERTEXELEMENT(WORD stream, WORD offset, ATTRIB_COMPONENT_TYPE type, BYTE numcomponents, ATTRIB_USAGE_DECL usage, BYTE usageindex, BYTE method = 0)
483
 
    {
484
 
        Stream = stream;
485
 
        Offset = offset;
486
 
        Type = type;
487
 
        NumComponent = numcomponents;
488
 
        Usage = usage;
489
 
        UsageIndex = usageindex;
490
 
        Method = method;
491
 
    }
492
 
 
493
 
    WORD Stream;
494
 
    WORD Offset;
495
 
    
496
 
    // Type can be GL_UNSIGNED_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE ...
497
 
    ATTRIB_COMPONENT_TYPE Type;
498
 
    //DWORD Stride;
499
 
    
500
 
    // This can be 1, 2, 3 or 4; For a position (xyzw), it will be 4. For a texture coordinate (uv) it will be 2.
501
 
    BYTE NumComponent;
502
 
 
503
 
    ATTRIB_USAGE_DECL Usage;
504
 
 
505
 
    // Use this index in association with TEXCOORD or COLOR to identify the texture 
506
 
    // coordinate set or the color set.
507
 
    BYTE UsageIndex;
508
 
 
509
 
    BYTE Method; // Should be always 0 for D3DDECLMETHOD_DEFAULT = 0
510
 
 
511
 
    // The vertex attribute Cg parameter that will be bound to the vertex element;
512
 
//    CGparameter CgParameter;
513
 
//    VERTEXELEMENT()
514
 
//    {
515
 
//        CgParameter = 0;
516
 
//    }
517
 
//    void setCgParameter(CGparameter parameter)
518
 
//    {
519
 
//        cgParameter = parameter;
520
 
//    }
521
 
};
522
 
 
523
 
#define DECL_END VERTEXELEMENT(0xFF/*Stream*/,0/*Offset*/,ATTRIB_CT_UNKNOWN/*Type*/,0/*NumComponent*/,ATTRIB_USAGE_DECL_POSITION/*Usage*/,0/*UsageIndex*/, 0 /*CgParameter*/)
524
 
 
525
 
unsigned int GetVertexElementSize(VERTEXELEMENT vtxelement);
526
 
 
527
 
#define MAXDECLLENGTH    64
528
 
#define MAX_NUM_STREAM  8
529
 
 
530
 
void DecomposeTypeDeclaraction(ATTRIB_DECL_TYPE Type, BYTE &NumComponent, ATTRIB_COMPONENT_TYPE &ComponentType);
531
 
 
532
 
void AddVertexElement(std::vector<VERTEXELEMENT>& Elements,
533
 
                         WORD Stream,
534
 
                         WORD Offset,
535
 
                         //ubiS16 Stride,
536
 
                         ATTRIB_DECL_TYPE Type,
537
 
                         ATTRIB_USAGE_DECL Usage,
538
 
                         BYTE UsageIndex);
539
 
 
540
 
GLenum GetGLPrimitiveType(PRIMITIVE_TYPE InPrimitiveType);
541
 
unsigned int   GetGLElementCount(PRIMITIVE_TYPE InPrimitiveType,
542
 
                                    unsigned int        InPrimitiveCount);
543
 
 
544
 
template<typename T> class TRefGL
545
 
{
546
 
public:
547
 
    T*  Handle;
548
 
 
549
 
private:
550
 
    void CheckReferenceObject()
551
 
    {
552
 
        if(Handle)
553
 
        {
554
 
            if(Handle->GetRefCount() == 0)
555
 
            {
556
 
                delete Handle;
557
 
                //GetThreadGLDeviceFactory()->DestroyDeviceResource<T>(Handle);
558
 
            }
559
 
        }
560
 
        Handle = 0;
561
 
    }
562
 
 
563
 
    //     // Do not allow access to the managed pointer. This also avoid compiler confusion between 
564
 
    //     //  int BindTexture(IOpenGLBaseTexture* texture);
565
 
    //     // and
566
 
    //     //  int BindTexture(TRefGL<IOpenGLBaseTexture> texture);
567
 
    // 
568
 
    //     // Access operators.
569
 
    //     typedef      T*      PtrT;
570
 
    //     operator T*() 
571
 
    //     {
572
 
    //         return Handle;
573
 
    //     }
574
 
 
575
 
public:
576
 
    T* operator -> ()
577
 
    {
578
 
        nuxAssert(Handle);
579
 
        return Handle;
580
 
    }
581
 
 
582
 
    const T* operator -> () const
583
 
    {
584
 
        nuxAssert(Handle);
585
 
        return Handle;
586
 
    }
587
 
 
588
 
    T& operator*()
589
 
    {
590
 
        nuxAssert(Handle);
591
 
        return *Handle;
592
 
    }
593
 
 
594
 
    const T& operator *() const
595
 
    {
596
 
        nuxAssert(Handle);
597
 
        return *Handle;
598
 
    }
599
 
 
600
 
    // Constructor/destructor.
601
 
    TRefGL(T* InHandle = 0)
602
 
        :   Handle(InHandle)
603
 
    {
604
 
        if(Handle)
605
 
            Handle->Increment();
606
 
    }
607
 
 
608
 
    template <typename U>
609
 
    TRefGL(U* InHandle)
610
 
        :   Handle(0)
611
 
    {
612
 
        if(InHandle == 0)
613
 
            return;
614
 
 
615
 
        if(InHandle->Type().IsDerivedFromType(T::StaticObjectType))
616
 
        {
617
 
            Handle = (T*)InHandle;
618
 
        }
619
 
        if(Handle)
620
 
            Handle->Increment();
621
 
    }
622
 
 
623
 
    TRefGL(const TRefGL<T>& Copy)
624
 
        :   Handle(0)
625
 
    {
626
 
        Handle = Copy.Handle;
627
 
        if(Handle)
628
 
            Handle->Increment();
629
 
    }
630
 
 
631
 
    template <typename U>
632
 
    TRefGL(const TRefGL<U>& Copy)
633
 
        :   Handle(0)
634
 
    {
635
 
        // Check if type U is derived from type T
636
 
        // Type() is virtual. Even if we have a TRefGL<IOpenGLBaseTexture> but its internal pointer is a IOpenGLCubeTexture,
637
 
        // Type() returns the static object type inside IOpenGLCubeTexture.
638
 
        // This make this possible
639
 
        //
640
 
        //      TRefGL<IOpenGLBaseTexture> basetex;            // IOpenGLBaseTexture is an abstract base class for IOpenGLTexture2D
641
 
        //      basetex = gGLDeviceFactory->CreateTexture(.....);
642
 
        //      TRefGL<IOpenGLVertexBuffer> vtx(basetex);   // vtx Handle will be null
643
 
        //      TRefGL<IOpenGLTexture2D> tex(basetex);      // tex Handle will be the same as basetex
644
 
        //
645
 
 
646
 
        if(Copy.Handle->Type().IsDerivedFromType(T::StaticObjectType))
647
 
        {
648
 
            Handle = (T*)Copy.Handle;
649
 
        }
650
 
        if(Handle)
651
 
            Handle->Increment();
652
 
    }
653
 
 
654
 
    ~TRefGL()
655
 
    {
656
 
        if(Handle)
657
 
        {
658
 
            Handle->Decrement();
659
 
            CheckReferenceObject();
660
 
        }
661
 
    }
662
 
 
663
 
    // Assignment operator.
664
 
 
665
 
    TRefGL<T>& operator = (T* InHandle)
666
 
    {
667
 
        if(Handle != InHandle)
668
 
        {
669
 
            if(Handle)
670
 
            {
671
 
                Handle->Decrement();
672
 
                CheckReferenceObject();
673
 
            }
674
 
 
675
 
            Handle = InHandle;
676
 
 
677
 
            if(Handle)
678
 
                Handle->Increment();
679
 
        }
680
 
        return *this;
681
 
    }
682
 
 
683
 
    TRefGL<T>& operator = (const TRefGL<T>& Other)
684
 
    {
685
 
        // Avoid self assignment
686
 
        if(Handle == Other.Handle)
687
 
        {
688
 
            return *this;
689
 
        }
690
 
        if(Handle)
691
 
        {
692
 
            Handle->Decrement();
693
 
            CheckReferenceObject();
694
 
        }
695
 
        Handle = Other.Handle;
696
 
        if(Handle)
697
 
            Handle->Increment();
698
 
        return *this;
699
 
    }
700
 
 
701
 
    bool operator == (const TRefGL<T>& Other) const
702
 
    {
703
 
        if(Handle == Other.Handle)
704
 
        {
705
 
            return true;
706
 
        }
707
 
        return false;
708
 
    }
709
 
 
710
 
    bool operator == (const T* Ptr) const
711
 
    {
712
 
        if(Handle == Ptr)
713
 
        {
714
 
            return true;
715
 
        }
716
 
        return false;
717
 
    }
718
 
 
719
 
    template <typename U>
720
 
    bool operator == (const U* Ptr) const
721
 
    {
722
 
        if(Handle == Ptr)
723
 
        {
724
 
            return true;
725
 
        }
726
 
        return false;
727
 
    }
728
 
 
729
 
    template <typename U>
730
 
    bool operator == (TRefGL<U>& Other) const
731
 
    {
732
 
        if(Handle == Other.Handle)
733
 
        {
734
 
            return true;
735
 
        }
736
 
        return false;
737
 
    }
738
 
 
739
 
    bool operator != (const TRefGL<T>& Other) const
740
 
    {
741
 
        if(Handle != Other.Handle)
742
 
        {
743
 
            return true;
744
 
        }
745
 
        return false;
746
 
    }
747
 
 
748
 
    bool operator != (const T* Ptr) const
749
 
    {
750
 
        if(Handle != Ptr)
751
 
        {
752
 
            return true;
753
 
        }
754
 
        return false;
755
 
    }
756
 
 
757
 
    template <typename U>
758
 
    bool operator != (const U* Ptr) const
759
 
    {
760
 
        if(Handle != Ptr)
761
 
        {
762
 
            return true;
763
 
        }
764
 
        return false;
765
 
    }
766
 
 
767
 
    template <typename U>
768
 
    bool operator != (TRefGL<U>& Other) const
769
 
    {
770
 
        if(Handle != Other.Handle)
771
 
        {
772
 
            return true;
773
 
        }
774
 
        return false;
775
 
    }
776
 
 
777
 
    //    // This isn't safe. An assignment like the following is wrong, but it will no flag an error at compile time. 
778
 
    //    // TRefGL<IOpenGLVertexBuffer> vtx;
779
 
    //    // TRefGL<IOpenGLTexture2D> tex;
780
 
    //    // vtx = tex;         // WRONG
781
 
    //
782
 
    //    template<typename U>
783
 
    //        TRefGL<T>& operator=(const TRefGL<U>& Other)
784
 
    //    {
785
 
    //        Handle = (T*)(Other.Handle);
786
 
    //        return *this;
787
 
    //    }
788
 
 
789
 
    // Doing vtx = tex.Castref<IOpenGLVertexBuffer> will return a TRefGL<IOpenGLVertexBuffer> with a null Handle.
790
 
    template<typename U>
791
 
    TRefGL<U> CastRef()
792
 
    {
793
 
        TRefGL<U> t;
794
 
        // Check if type U is derived from type T
795
 
        if(U::StaticObjectType.IsDerivedFromType(T::StaticObjectType))
796
 
        {
797
 
            t = (U*)Handle;
798
 
        }
799
 
        return t;
800
 
    }
801
 
 
802
 
    void Release()
803
 
    {
804
 
        if(Handle)
805
 
        {
806
 
            Handle->Decrement();
807
 
            CheckReferenceObject();
808
 
        }
809
 
        Handle = 0;
810
 
    }
811
 
private:
812
 
    T& GetHandle()
813
 
    {
814
 
        return *Handle;
815
 
    }
816
 
 
817
 
public:
818
 
    bool IsValid()
819
 
    {
820
 
        if(Handle)
821
 
        {
822
 
            return true;
823
 
        }
824
 
        return false;
825
 
    }
826
 
 
827
 
    bool IsNull()
828
 
    {
829
 
        if(Handle)
830
 
        {
831
 
            return false;
832
 
        }
833
 
        return true;
834
 
    }
835
 
};
836
 
 
837
 
NAMESPACE_END_OGL
838
 
 
839
 
#endif // GLRESOURCE_H
840
 
 
 
23
#ifndef GLRESOURCE_H
 
24
#define GLRESOURCE_H
 
25
 
 
26
#include "NuxCore/NKernel.h"
 
27
#include "NuxCore/NNamespace.h"
 
28
#include "NuxCore/NSystemTypes.h"
 
29
#include "NuxCore/Error.h"
 
30
#include "NuxCore/FilePath.h"
 
31
#include "NuxCore/Color.h"
 
32
#include "NuxCore/Rect.h"
 
33
#include "NuxCore/Point.h"
 
34
#include "NuxCore/Size.h"
 
35
#include "NuxImage/BitmapFormats.h"
 
36
#include "NuxCore/NParsing.h"
 
37
 
 
38
#include "NuxCore/Math/MathUtility.h"
 
39
#include "NuxCore/Math/Constants.h"
 
40
#include "NuxCore/Math/Vector3.h"
 
41
#include "NuxCore/Math/Vector4.h"
 
42
#include "NuxCore/Math/Matrix3.h"
 
43
#include "NuxCore/Math/Matrix4.h"
 
44
#include "NuxCore/Math/Spline.h"
 
45
#include "NuxCore/Math/MathFunctions.h"
 
46
 
 
47
#include "NuxImage/ImageSurface.h"
 
48
#include "NuxImage/Tga.h"
 
49
#include "NuxImage/Bmp.h"
 
50
#include "NuxImage/NPng.h"
 
51
 
 
52
#define NAMESPACE_BEGIN_OGL  namespace nux {
 
53
#define NAMESPACE_END_OGL    }
 
54
 
 
55
NAMESPACE_BEGIN_OGL
 
56
class IOpenGLResource;
 
57
 
 
58
class NTexture;
 
59
class NTexture2D;
 
60
class NRectangleTexture;
 
61
class NTextureCube;
 
62
class NTextureVolume;
 
63
class NAnimatedTexture;
 
64
 
 
65
class NVertexBuffer;
 
66
class NIndexBuffer;
 
67
 
 
68
class NGLTexture2D;
 
69
class NGLRectangleTexture;
 
70
class NGLTextureCube;
 
71
class NGLTextureVolume;
 
72
class NGLAnimatedTexture;
 
73
 
 
74
NAMESPACE_END_OGL
 
75
 
 
76
#include "RunTimeStats.h"
 
77
#include "GlobalGraphicsInitializer.h"
 
78
 
 
79
#define NUX_ENABLE_CG_SHADERS 0
 
80
 
 
81
#if defined(INL_OS_WINDOWS)
 
82
    #include "OpenGL/Glew/glew.h"
 
83
    #include "OpenGL/Glew/wglew.h"
 
84
 
 
85
    GLEWContext* glewGetContext();
 
86
    WGLEWContext* wglewGetContext();
 
87
 
 
88
    #if (NUX_ENABLE_CG_SHADERS)
 
89
        #include "CG/cg.h"
 
90
        #include "CG/cgGL.h"
 
91
        #pragma comment( lib, "cg.lib" )
 
92
        #pragma comment( lib, "cgGL.lib"  )
 
93
    #endif
 
94
 
 
95
#elif defined(INL_OS_LINUX)
 
96
    #define GLEW_MX
 
97
    #include "GL/glew.h"
 
98
    #include "GL/glxew.h"
 
99
    
 
100
    GLEWContext* glewGetContext();
 
101
    GLXEWContext* glxewGetContext();
 
102
 
 
103
    #if (NUX_ENABLE_CG_SHADERS)
 
104
        #include "Cg/cg.h"
 
105
        #include "Cg/cgGL.h"
 
106
    #endif
 
107
#endif
 
108
 
 
109
#include "GLError.h"
 
110
 
 
111
#define CG_FRAGMENT_PROFILE CG_PROFILE_FP30
 
112
#define CG_VERTEX_PROFILE CG_PROFILE_VP30
 
113
 
 
114
#define INL_BUFFER_OFFSET(i) ((BYTE *)NULL + (i))
 
115
 
 
116
 
 
117
NAMESPACE_BEGIN_OGL
 
118
 
 
119
enum
 
120
{
 
121
    OGL_OK = 0,
 
122
    OGL_ERROR,
 
123
    OGL_ERROR_UNKNOWN,
 
124
    OGL_INVALID_SURFACE_LEVEL,
 
125
    OGL_INVALID_CALL,
 
126
    OGL_INVALID_LOCK,
 
127
    OGL_INVALID_UNLOCK,
 
128
    OGL_INVALID_TEXTURE,
 
129
    OGL_FORCE_DWORD            = 0x7fffffff /* force 32-bit size enum */
 
130
};
 
131
 
 
132
extern const TCHAR* OGLDeviceErrorMessages[];
 
133
 
 
134
#define OGL_OK 0
 
135
#define OGL_CALL(call)              \
 
136
    {                               \
 
137
        int Result = call;          \
 
138
        if(Result != OGL_OK)          \
 
139
        {nuxError(TEXT("OGL Object Error: Error # %d - (%s) "), Result,  *OGLDeviceErrorMessages[Result] );}   \
 
140
    }
 
141
 
 
142
//if(Result!=OGL_OK) {nuxError(TEXT("OGL Object Error: Error # %d - %s"), Result, OGLDeviceErrorMessages[Result]);}
 
143
 
 
144
enum TEXTURE_FORMAT
 
145
{
 
146
    TEXTURE_FMT_UNKNOWN              = 0,
 
147
    TEXTURE_FMT_ALPHA                = GL_ALPHA,
 
148
    TEXTURE_FMT_ALPHA8               = GL_ALPHA8,
 
149
    TEXTURE_FMT_ALPHA16              = GL_ALPHA16,
 
150
 
 
151
    TEXTURE_FMT_LUMINANCE            = GL_LUMINANCE,
 
152
    TEXTURE_FMT_LUMINANCE8           = GL_LUMINANCE8,
 
153
    TEXTURE_FMT_LUMINANCE16          = GL_LUMINANCE16,
 
154
 
 
155
    TEXTURE_FMT_LUMINANCE_ALPHA      = GL_LUMINANCE_ALPHA,
 
156
    TEXTURE_FMT_LUMINANCE8_ALPHA8    = GL_LUMINANCE8_ALPHA8,
 
157
    TEXTURE_FMT_LUMINANCE16_ALPHA16  = GL_LUMINANCE16_ALPHA16,
 
158
 
 
159
    TEXTURE_FMT_INTENSITY            = GL_INTENSITY,
 
160
    TEXTURE_FMT_INTENSITY8           = GL_INTENSITY8,
 
161
    TEXTURE_FMT_INTENSITY16          = GL_INTENSITY16,
 
162
 
 
163
    TEXTURE_FMT_GL_DEPTH_COMPONENT   = GL_DEPTH_COMPONENT,
 
164
    TEXTURE_FMT_GL_DEPTH_COMPONENT24 = GL_DEPTH_COMPONENT24,
 
165
 
 
166
    TEXTURE_FMT_RGBA                 = GL_RGBA,
 
167
    TEXTURE_FMT_RGBA8                = GL_RGBA8,
 
168
    TEXTURE_FMT_RGBA16               = GL_RGBA16,
 
169
 
 
170
    TEXTURE_FMT_RGBA16F_ARB          = GL_RGBA16F_ARB,
 
171
    TEXTURE_FMT_RGBA32F_ARB          = GL_RGBA32F_ARB,
 
172
    TEXTURE_FMT_RGB                  = GL_RGB,
 
173
    TEXTURE_FMT_RGB8                 = GL_RGB8,
 
174
    TEXTURE_FMT_RGB16                = GL_RGB16,
 
175
    TEXTURE_FMT_RGB16F_ARB           = GL_RGB16F_ARB,
 
176
    TEXTURE_FMT_RGB32F_ARB           = GL_RGB32F_ARB,
 
177
 
 
178
    TEXTURE_FMT_COMPRESSED_RGB_S3TC_DXT1_EXT   = GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
 
179
    TEXTURE_FMT_COMPRESSED_RGBA_S3TC_DXT1_EXT  = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
 
180
    TEXTURE_FMT_COMPRESSED_RGBA_S3TC_DXT3_EXT  = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
 
181
    TEXTURE_FMT_COMPRESSED_RGBA_S3TC_DXT5_EXT  = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
 
182
    TEXTURE_FMT_FORCE_DWORD                    = 0x7fffffff /* force 32-bit size enum */
 
183
};
 
184
 
 
185
struct PixelFormatReadInfo
 
186
{
 
187
    const TCHAR*        Name;
 
188
    GLenum          Format;     // format use for glReadPixels
 
189
    GLenum          type;       // type use for glReadPixels
 
190
    // Format specific internal flags, e.g. whether SRGB is supported with this format
 
191
    DWORD                       Flags;
 
192
    bool                        Supported;
 
193
};
 
194
 
 
195
enum eCUBEMAP_FACES
 
196
{
 
197
    CUBEMAP_FACE_POSITIVE_X     = GL_TEXTURE_CUBE_MAP_POSITIVE_X,
 
198
    CUBEMAP_FACE_NEGATIVE_X     = GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
 
199
    CUBEMAP_FACE_POSITIVE_Y     = GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
 
200
    CUBEMAP_FACE_NEGATIVE_Y     = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
 
201
    CUBEMAP_FACE_POSITIVE_Z     = GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
 
202
    CUBEMAP_FACE_NEGATIVE_Z     = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
 
203
 
 
204
    CUBEMAP_FACE_FORCE_DWORD    = 0x7fffffff
 
205
};
 
206
 
 
207
enum VBO_USAGE
 
208
{
 
209
    VBO_USAGE_UNKNOWN   = 0,
 
210
    VBO_USAGE_STATIC    = GL_STATIC_DRAW,
 
211
    VBO_USAGE_DYNAMIC   = GL_DYNAMIC_DRAW,
 
212
    VBO_USAGE_STREAM    = GL_STREAM_DRAW,
 
213
    VBO_USAGE_FORCE_DWORD    = 0x7fffffff /* force 32-bit size enum */
 
214
};
 
215
 
 
216
enum INDEX_FORMAT
 
217
{
 
218
    INDEX_FORMAT_UNKNOWN   = 0,
 
219
    INDEX_FORMAT_USHORT    = GL_UNSIGNED_SHORT,
 
220
    INDEX_FORMAT_UINT      = GL_UNSIGNED_INT,
 
221
    INDEX_FORMAT_FORCE_DWORD    = 0x7fffffff /* force 32-bit size enum */
 
222
};
 
223
 
 
224
// Primitives supported by draw-primitive API
 
225
typedef enum {
 
226
    PRIMITIVE_TYPE_POINTLIST             = GL_POINTS,
 
227
    PRIMITIVE_TYPE_LINELIST              = GL_LINES,
 
228
    PRIMITIVE_TYPE_LINESTRIP             = GL_LINE_STRIP,
 
229
    PRIMITIVE_TYPE_TRIANGLELIST          = GL_TRIANGLES,
 
230
    PRIMITIVE_TYPE_TRIANGLESTRIP         = GL_TRIANGLE_STRIP,
 
231
    PRIMITIVE_TYPE_TRIANGLEFAN           = GL_TRIANGLE_FAN,
 
232
    PRIMITIVE_TYPE_QUADLIST              = GL_QUADS,
 
233
    PRIMITIVE_TYPE_QUADSTRIP             = GL_QUAD_STRIP,
 
234
    PRIMITIVE_TYPE_FORCE_DWORD           = 0x7fffffff /* force 32-bit size enum */
 
235
} PRIMITIVE_TYPE;
 
236
 
 
237
enum OpenGLResourceType
 
238
{
 
239
    RTINDEXBUFFER,
 
240
    RTVERTEXBUFFER,
 
241
    RTSURFACE,
 
242
    RTVOLUME,
 
243
    RTBASETEXTURE,
 
244
    RTTEXTURE,
 
245
    RTTEXTURERECTANGLE,
 
246
    RTCUBETEXTURE,
 
247
    RTVOLUMETEXTURE,
 
248
    RTANIMATEDTEXTURE,
 
249
    RTVERTEXDECLARATION,
 
250
    RTQUERY,
 
251
    RTFRAMEBUFFEROBJECT,
 
252
    RT_GLSL_VERTEXSHADER,
 
253
    RT_GLSL_PIXELSHADER,
 
254
    RT_GLSL_SHADERPROGRAM,
 
255
    RT_CG_VERTEXSHADER,
 
256
    RT_CG_PIXELSHADER,
 
257
    RT_FORCE_DWORD           = 0x7fffffff /* force 32-bit size enum */
 
258
};
 
259
 
 
260
/* Multi-Sample buffer types */
 
261
typedef enum
 
262
{
 
263
    MULTISAMPLE_TYPE_NONE            =  0,
 
264
    MULTISAMPLE_TYPE_NONMASKABLE     =  1,
 
265
    MULTISAMPLE_TYPE_2_SAMPLES       =  2,
 
266
    MULTISAMPLE_TYPE_3_SAMPLES       =  3,
 
267
    MULTISAMPLE_TYPE_4_SAMPLES       =  4,
 
268
    MULTISAMPLE_TYPE_5_SAMPLES       =  5,
 
269
    MULTISAMPLE_TYPE_6_SAMPLES       =  6,
 
270
    MULTISAMPLE_TYPE_7_SAMPLES       =  7,
 
271
    MULTISAMPLE_TYPE_8_SAMPLES       =  8,
 
272
    MULTISAMPLE_TYPE_9_SAMPLES       =  9,
 
273
    MULTISAMPLE_TYPE_10_SAMPLES      = 10,
 
274
    MULTISAMPLE_TYPE_11_SAMPLES      = 11,
 
275
    MULTISAMPLE_TYPE_12_SAMPLES      = 12,
 
276
    MULTISAMPLE_TYPE_13_SAMPLES      = 13,
 
277
    MULTISAMPLE_TYPE_14_SAMPLES      = 14,
 
278
    MULTISAMPLE_TYPE_15_SAMPLES      = 15,
 
279
    MULTISAMPLE_TYPE_16_SAMPLES      = 16,
 
280
    MULTISAMPLE_TYPE_FORCE_DWORD     = 0x7fffffff /* force 32-bit size enum */
 
281
} MULTISAMPLE_TYPE;
 
282
 
 
283
typedef enum
 
284
{
 
285
    MEM_POOL_DEFAULT = 0,
 
286
    MEM_POOL_MANAGED = 1,
 
287
    MEM_POOL_SYSTEMMEM = 2,
 
288
    MEM_POOL_SCRATCH = 3,
 
289
    MEM_POOL_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */
 
290
} MEM_POOL;
 
291
 
 
292
 
 
293
typedef struct {
 
294
    OpenGLResourceType ResourceType;
 
295
    unsigned int Width;
 
296
    unsigned int Height;
 
297
    unsigned int Depth;
 
298
    BitmapFormat PixelFormat;
 
299
    unsigned int RowPitch;
 
300
    unsigned int SlicePitch;
 
301
    unsigned int BitsPerPixel;
 
302
    unsigned int WidthInBlocks;
 
303
    unsigned int HeightInBlocks;
 
304
    unsigned int DepthInBlocks;
 
305
    unsigned int BytesPerBlock;
 
306
    int ExpBias;
 
307
    DWORD Flags;
 
308
    MULTISAMPLE_TYPE MultiSampleType;
 
309
} TEXTURE_DESC;
 
310
 
 
311
typedef struct _SURFACE_DESC
 
312
{
 
313
    BitmapFormat    PixelFormat;
 
314
    OpenGLResourceType     Type;
 
315
    DWORD               Usage;
 
316
    MEM_POOL             Pool;
 
317
 
 
318
    MULTISAMPLE_TYPE MultiSampleType;
 
319
    DWORD               MultiSampleQuality;
 
320
    unsigned int                Width;
 
321
    unsigned int                Height;
 
322
} SURFACE_DESC;
 
323
 
 
324
typedef struct _VOLUME_DESC {
 
325
    BitmapFormat PixelFormat;
 
326
    OpenGLResourceType Type;
 
327
    DWORD Usage;
 
328
    MEM_POOL Pool;
 
329
    unsigned int Width;
 
330
    unsigned int Height;
 
331
    unsigned int Depth;
 
332
} VOLUME_DESC;
 
333
 
 
334
typedef struct _ANIMATEDTEXTURE_DESC {
 
335
    BitmapFormat PixelFormat;
 
336
    OpenGLResourceType Type;
 
337
    DWORD Usage;
 
338
    MEM_POOL Pool;
 
339
    unsigned int Width;
 
340
    unsigned int Height;
 
341
    unsigned int Depth;
 
342
} ANIMATEDTEXTURE_DESC;
 
343
 
 
344
typedef struct _VERTEXBUFFER_DESC {
 
345
    VBO_USAGE Usage;
 
346
    unsigned int Size;
 
347
} VERTEXBUFFER_DESC;
 
348
 
 
349
typedef struct _INDEXBUFFER_DESC {
 
350
    INDEX_FORMAT Format;
 
351
    VBO_USAGE Usage;
 
352
    unsigned int Size;
 
353
} INDEXBUFFER_DESC;
 
354
 
 
355
typedef struct _LOCKED_RECT
 
356
{
 
357
    int Pitch;
 
358
    void * pBits;
 
359
} SURFACE_LOCKED_RECT;
 
360
 
 
361
typedef struct _SURFACE_RECT { 
 
362
    long left;      //Specifies the x-coordinate of the lower-left corner of the rectangle. 
 
363
    long top;       //Specifies the y-coordinate of the lower-left corner of the rectangle.
 
364
    long right;     //Specifies the x-coordinate of the upper-right corner of the rectangle. 
 
365
    long bottom;    //Specifies the y-coordinate of the upper-right corner of the rectangle. 
 
366
} SURFACE_RECT;
 
367
 
 
368
 
 
369
/* Structures for LockBox */
 
370
typedef struct _VOLUME_BOX
 
371
{
 
372
    unsigned int                Left;
 
373
    unsigned int                Top;
 
374
    unsigned int                Right;
 
375
    unsigned int                Bottom;
 
376
    unsigned int                Front;
 
377
    unsigned int                Back;
 
378
} VOLUME_BOX;
 
379
 
 
380
typedef struct _VOLUME_LOCKED_BOX
 
381
{
 
382
    int                 RowPitch;
 
383
    int                 SlicePitch;
 
384
    void*               pBits;
 
385
} VOLUME_LOCKED_BOX;
 
386
 
 
387
typedef enum _ATTRIB_DECL_TYPE
 
388
{
 
389
    ATTRIB_DECLTYPE_UNKNOWN = 0,
 
390
    ATTRIB_DECLTYPE_FLOAT1,
 
391
    ATTRIB_DECLTYPE_FLOAT2,
 
392
    ATTRIB_DECLTYPE_FLOAT3,
 
393
    ATTRIB_DECLTYPE_FLOAT4,
 
394
    ATTRIB_DECLTYPE_COLOR,
 
395
    ATTRIB_DECLTYPE_UBYTE4,
 
396
    ATTRIB_DECLTYPE_SHORT2,
 
397
    ATTRIB_DECLTYPE_SHORT4,
 
398
    ATTRIB_DECLTYPE_UBYTE4N,
 
399
    ATTRIB_DECLTYPE_SHORT2N,
 
400
    ATTRIB_DECLTYPE_SHORT4N,
 
401
    ATTRIB_DECLTYPE_USHORT2N,
 
402
    ATTRIB_DECLTYPE_USHORT4N,
 
403
    ATTRIB_DECLTYPE_UDEC3,
 
404
    ATTRIB_DECLTYPE_DEC3N,
 
405
    ATTRIB_DECLTYPE_FLOAT16_2,
 
406
    ATTRIB_DECLTYPE_FLOAT16_4,
 
407
    ATTRIB_DECLTYPE_UNUSED,
 
408
    ATTRIB_DECLTYPE_FORCE_DWORD           = 0x7fffffff /* force 32-bit size enum */
 
409
} ATTRIB_DECL_TYPE;
 
410
 
 
411
typedef enum _ATTRIB_COMPONENT_TYPE
 
412
{
 
413
    ATTRIB_CT_UNKNOWN           =   0,
 
414
    ATTRIB_CT_BYTE              =   GL_BYTE,
 
415
    ATTRIB_CT_UNSIGNED_BYTE     =   GL_UNSIGNED_BYTE,
 
416
    ATTRIB_CT_SHORT             =   GL_SHORT,
 
417
    ATTRIB_CT_UNSIGNED_SHORT    =   GL_UNSIGNED_SHORT,
 
418
    ATTRIB_CT_INT               =   GL_INT,
 
419
    ATTRIB_CT_UNSIGNED_INT      =   GL_UNSIGNED_INT,
 
420
    ATTRIB_CT_FLOAT             =   GL_FLOAT,
 
421
    ATTRIB_CT_HALF_FLOAT        =   GL_HALF_FLOAT_ARB,
 
422
//    ATTRIB_CT_2_BYTES           =   GL_2_BYTES,
 
423
//    ATTRIB_CT_3_BYTES           =   GL_3_BYTES,
 
424
//    ATTRIB_CT_4_BYTES           =   GL_4_BYTES,
 
425
    ATTRIB_CT_DOUBLE            =   GL_DOUBLE,
 
426
// Type can be GL_UNSIGNED_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE
 
427
    ATTRIB_CT_FORCE_DWORD           = 0x7fffffff /* force 32-bit size enum */
 
428
} ATTRIB_COMPONENT_TYPE;
 
429
 
 
430
// Binding Semantics
 
431
typedef enum
 
432
{
 
433
    ATTRIB_USAGE_DECL_POSITION       = 0,
 
434
    ATTRIB_USAGE_DECL_BLENDWEIGHT    = 1,
 
435
    ATTRIB_USAGE_DECL_NORMAL         = 2,
 
436
    ATTRIB_USAGE_DECL_COLOR          = 3,
 
437
    ATTRIB_USAGE_DECL_COLOR1         = 4,
 
438
    ATTRIB_USAGE_DECL_FOGCOORD       = 5,
 
439
    ATTRIB_USAGE_DECL_PSIZE          = 6,
 
440
    ATTRIB_USAGE_DECL_BLENDINDICES   = 7,
 
441
    ATTRIB_USAGE_DECL_TEXCOORD       = 8,
 
442
    ATTRIB_USAGE_DECL_TEXCOORD0      = 8,
 
443
    ATTRIB_USAGE_DECL_TEXCOORD1      = 9,
 
444
    ATTRIB_USAGE_DECL_TEXCOORD2      = 10,
 
445
    ATTRIB_USAGE_DECL_TEXCOORD3      = 11,
 
446
    ATTRIB_USAGE_DECL_TEXCOORD4      = 12,
 
447
    ATTRIB_USAGE_DECL_TEXCOORD5      = 13,
 
448
    ATTRIB_USAGE_DECL_TEXCOORD6      = 14,
 
449
    ATTRIB_USAGE_DECL_TEXCOORD7      = 15,
 
450
    ATTRIB_USAGE_DECL_TANGENT        = 14,
 
451
    ATTRIB_USAGE_DECL_BINORMAL       = 15,
 
452
    ATTRIB_USAGE_DECL_FORCE_DWORD           = 0x7fffffff /* force 32-bit size enum */
 
453
} ATTRIB_USAGE_DECL;
 
454
 
 
455
typedef enum {
 
456
    QUERY_TYPE_VCACHE                 = 4,
 
457
    QUERY_TYPE_RESOURCEMANAGER        = 5,
 
458
    QUERY_TYPE_VERTEXSTATS            = 6,
 
459
    QUERY_TYPE_EVENT                  = 8,
 
460
    QUERY_TYPE_OCCLUSION              = 9,
 
461
    QUERY_TYPE_SCREENEXTENT           = 10,
 
462
    QUERY_TYPE_FORCE_DWORD            = 0x7fffffff /* force 32-bit size enum */
 
463
} QUERY_TYPE;
 
464
 
 
465
// Flags field for Issue
 
466
#define ISSUE_END (1 << 0) // Tells the runtime to issue the end of a query, changing it's state to "non-signaled".
 
467
#define ISSUE_BEGIN (1 << 1) // Tells the runtime to issue the begining of a query.
 
468
 
 
469
struct VERTEXELEMENT
 
470
{
 
471
    VERTEXELEMENT()
 
472
    {
 
473
        Stream = 0;
 
474
        Offset = 0;
 
475
        Type = ATTRIB_CT_UNKNOWN;
 
476
        NumComponent = 0;
 
477
        Usage = ATTRIB_USAGE_DECL_POSITION;
 
478
        UsageIndex = 0;
 
479
        Method = 0;
 
480
    }
 
481
 
 
482
    VERTEXELEMENT(WORD stream, WORD offset, ATTRIB_COMPONENT_TYPE type, BYTE numcomponents, ATTRIB_USAGE_DECL usage, BYTE usageindex, BYTE method = 0)
 
483
    {
 
484
        Stream = stream;
 
485
        Offset = offset;
 
486
        Type = type;
 
487
        NumComponent = numcomponents;
 
488
        Usage = usage;
 
489
        UsageIndex = usageindex;
 
490
        Method = method;
 
491
    }
 
492
 
 
493
    WORD Stream;
 
494
    WORD Offset;
 
495
    
 
496
    // Type can be GL_UNSIGNED_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE ...
 
497
    ATTRIB_COMPONENT_TYPE Type;
 
498
    //DWORD Stride;
 
499
    
 
500
    // This can be 1, 2, 3 or 4; For a position (xyzw), it will be 4. For a texture coordinate (uv) it will be 2.
 
501
    BYTE NumComponent;
 
502
 
 
503
    ATTRIB_USAGE_DECL Usage;
 
504
 
 
505
    // Use this index in association with TEXCOORD or COLOR to identify the texture 
 
506
    // coordinate set or the color set.
 
507
    BYTE UsageIndex;
 
508
 
 
509
    BYTE Method; // Should be always 0 for D3DDECLMETHOD_DEFAULT = 0
 
510
 
 
511
    // The vertex attribute Cg parameter that will be bound to the vertex element;
 
512
//    CGparameter CgParameter;
 
513
//    VERTEXELEMENT()
 
514
//    {
 
515
//        CgParameter = 0;
 
516
//    }
 
517
//    void setCgParameter(CGparameter parameter)
 
518
//    {
 
519
//        cgParameter = parameter;
 
520
//    }
 
521
};
 
522
 
 
523
#define DECL_END VERTEXELEMENT(0xFF/*Stream*/,0/*Offset*/,ATTRIB_CT_UNKNOWN/*Type*/,0/*NumComponent*/,ATTRIB_USAGE_DECL_POSITION/*Usage*/,0/*UsageIndex*/, 0 /*CgParameter*/)
 
524
 
 
525
unsigned int GetVertexElementSize(VERTEXELEMENT vtxelement);
 
526
 
 
527
#define MAXDECLLENGTH    64
 
528
#define MAX_NUM_STREAM  8
 
529
 
 
530
void DecomposeTypeDeclaraction(ATTRIB_DECL_TYPE Type, BYTE &NumComponent, ATTRIB_COMPONENT_TYPE &ComponentType);
 
531
 
 
532
void AddVertexElement(std::vector<VERTEXELEMENT>& Elements,
 
533
                         WORD Stream,
 
534
                         WORD Offset,
 
535
                         //ubiS16 Stride,
 
536
                         ATTRIB_DECL_TYPE Type,
 
537
                         ATTRIB_USAGE_DECL Usage,
 
538
                         BYTE UsageIndex);
 
539
 
 
540
GLenum GetGLPrimitiveType(PRIMITIVE_TYPE InPrimitiveType);
 
541
unsigned int   GetGLElementCount(PRIMITIVE_TYPE InPrimitiveType,
 
542
                                    unsigned int        InPrimitiveCount);
 
543
 
 
544
template<typename T> class TRefGL
 
545
{
 
546
public:
 
547
    T*  Handle;
 
548
 
 
549
private:
 
550
    void CheckReferenceObject()
 
551
    {
 
552
        if(Handle)
 
553
        {
 
554
            if(Handle->GetRefCount() == 0)
 
555
            {
 
556
                delete Handle;
 
557
                //GetThreadGLDeviceFactory()->DestroyDeviceResource<T>(Handle);
 
558
            }
 
559
        }
 
560
        Handle = 0;
 
561
    }
 
562
 
 
563
    //     // Do not allow access to the managed pointer. This also avoid compiler confusion between 
 
564
    //     //  int BindTexture(IOpenGLBaseTexture* texture);
 
565
    //     // and
 
566
    //     //  int BindTexture(TRefGL<IOpenGLBaseTexture> texture);
 
567
    // 
 
568
    //     // Access operators.
 
569
    //     typedef      T*      PtrT;
 
570
    //     operator T*() 
 
571
    //     {
 
572
    //         return Handle;
 
573
    //     }
 
574
 
 
575
public:
 
576
    T* operator -> ()
 
577
    {
 
578
        nuxAssert(Handle);
 
579
        return Handle;
 
580
    }
 
581
 
 
582
    const T* operator -> () const
 
583
    {
 
584
        nuxAssert(Handle);
 
585
        return Handle;
 
586
    }
 
587
 
 
588
    T& operator*()
 
589
    {
 
590
        nuxAssert(Handle);
 
591
        return *Handle;
 
592
    }
 
593
 
 
594
    const T& operator *() const
 
595
    {
 
596
        nuxAssert(Handle);
 
597
        return *Handle;
 
598
    }
 
599
 
 
600
    // Constructor/destructor.
 
601
    TRefGL(T* InHandle = 0)
 
602
        :   Handle(InHandle)
 
603
    {
 
604
        if(Handle)
 
605
            Handle->Increment();
 
606
    }
 
607
 
 
608
    template <typename U>
 
609
    TRefGL(U* InHandle)
 
610
        :   Handle(0)
 
611
    {
 
612
        if(InHandle == 0)
 
613
            return;
 
614
 
 
615
        if(InHandle->Type().IsDerivedFromType(T::StaticObjectType))
 
616
        {
 
617
            Handle = (T*)InHandle;
 
618
        }
 
619
        if(Handle)
 
620
            Handle->Increment();
 
621
    }
 
622
 
 
623
    TRefGL(const TRefGL<T>& Copy)
 
624
        :   Handle(0)
 
625
    {
 
626
        Handle = Copy.Handle;
 
627
        if(Handle)
 
628
            Handle->Increment();
 
629
    }
 
630
 
 
631
    template <typename U>
 
632
    TRefGL(const TRefGL<U>& Copy)
 
633
        :   Handle(0)
 
634
    {
 
635
        // Check if type U is derived from type T
 
636
        // Type() is virtual. Even if we have a TRefGL<IOpenGLBaseTexture> but its internal pointer is a IOpenGLCubeTexture,
 
637
        // Type() returns the static object type inside IOpenGLCubeTexture.
 
638
        // This make this possible
 
639
        //
 
640
        //      TRefGL<IOpenGLBaseTexture> basetex;            // IOpenGLBaseTexture is an abstract base class for IOpenGLTexture2D
 
641
        //      basetex = gGLDeviceFactory->CreateTexture(.....);
 
642
        //      TRefGL<IOpenGLVertexBuffer> vtx(basetex);   // vtx Handle will be null
 
643
        //      TRefGL<IOpenGLTexture2D> tex(basetex);      // tex Handle will be the same as basetex
 
644
        //
 
645
 
 
646
        if(Copy.Handle->Type().IsDerivedFromType(T::StaticObjectType))
 
647
        {
 
648
            Handle = (T*)Copy.Handle;
 
649
        }
 
650
        if(Handle)
 
651
            Handle->Increment();
 
652
    }
 
653
 
 
654
    ~TRefGL()
 
655
    {
 
656
        if(Handle)
 
657
        {
 
658
            Handle->Decrement();
 
659
            CheckReferenceObject();
 
660
        }
 
661
    }
 
662
 
 
663
    // Assignment operator.
 
664
 
 
665
    TRefGL<T>& operator = (T* InHandle)
 
666
    {
 
667
        if(Handle != InHandle)
 
668
        {
 
669
            if(Handle)
 
670
            {
 
671
                Handle->Decrement();
 
672
                CheckReferenceObject();
 
673
            }
 
674
 
 
675
            Handle = InHandle;
 
676
 
 
677
            if(Handle)
 
678
                Handle->Increment();
 
679
        }
 
680
        return *this;
 
681
    }
 
682
 
 
683
    TRefGL<T>& operator = (const TRefGL<T>& Other)
 
684
    {
 
685
        // Avoid self assignment
 
686
        if(Handle == Other.Handle)
 
687
        {
 
688
            return *this;
 
689
        }
 
690
        if(Handle)
 
691
        {
 
692
            Handle->Decrement();
 
693
            CheckReferenceObject();
 
694
        }
 
695
        Handle = Other.Handle;
 
696
        if(Handle)
 
697
            Handle->Increment();
 
698
        return *this;
 
699
    }
 
700
 
 
701
    bool operator == (const TRefGL<T>& Other) const
 
702
    {
 
703
        if(Handle == Other.Handle)
 
704
        {
 
705
            return true;
 
706
        }
 
707
        return false;
 
708
    }
 
709
 
 
710
    bool operator == (const T* Ptr) const
 
711
    {
 
712
        if(Handle == Ptr)
 
713
        {
 
714
            return true;
 
715
        }
 
716
        return false;
 
717
    }
 
718
 
 
719
    template <typename U>
 
720
    bool operator == (const U* Ptr) const
 
721
    {
 
722
        if(Handle == Ptr)
 
723
        {
 
724
            return true;
 
725
        }
 
726
        return false;
 
727
    }
 
728
 
 
729
    template <typename U>
 
730
    bool operator == (TRefGL<U>& Other) const
 
731
    {
 
732
        if(Handle == Other.Handle)
 
733
        {
 
734
            return true;
 
735
        }
 
736
        return false;
 
737
    }
 
738
 
 
739
    bool operator != (const TRefGL<T>& Other) const
 
740
    {
 
741
        if(Handle != Other.Handle)
 
742
        {
 
743
            return true;
 
744
        }
 
745
        return false;
 
746
    }
 
747
 
 
748
    bool operator != (const T* Ptr) const
 
749
    {
 
750
        if(Handle != Ptr)
 
751
        {
 
752
            return true;
 
753
        }
 
754
        return false;
 
755
    }
 
756
 
 
757
    template <typename U>
 
758
    bool operator != (const U* Ptr) const
 
759
    {
 
760
        if(Handle != Ptr)
 
761
        {
 
762
            return true;
 
763
        }
 
764
        return false;
 
765
    }
 
766
 
 
767
    template <typename U>
 
768
    bool operator != (TRefGL<U>& Other) const
 
769
    {
 
770
        if(Handle != Other.Handle)
 
771
        {
 
772
            return true;
 
773
        }
 
774
        return false;
 
775
    }
 
776
 
 
777
    //    // This isn't safe. An assignment like the following is wrong, but it will no flag an error at compile time. 
 
778
    //    // TRefGL<IOpenGLVertexBuffer> vtx;
 
779
    //    // TRefGL<IOpenGLTexture2D> tex;
 
780
    //    // vtx = tex;         // WRONG
 
781
    //
 
782
    //    template<typename U>
 
783
    //        TRefGL<T>& operator=(const TRefGL<U>& Other)
 
784
    //    {
 
785
    //        Handle = (T*)(Other.Handle);
 
786
    //        return *this;
 
787
    //    }
 
788
 
 
789
    // Doing vtx = tex.Castref<IOpenGLVertexBuffer> will return a TRefGL<IOpenGLVertexBuffer> with a null Handle.
 
790
    template<typename U>
 
791
    TRefGL<U> CastRef()
 
792
    {
 
793
        TRefGL<U> t;
 
794
        // Check if type U is derived from type T
 
795
        if(U::StaticObjectType.IsDerivedFromType(T::StaticObjectType))
 
796
        {
 
797
            t = (U*)Handle;
 
798
        }
 
799
        return t;
 
800
    }
 
801
 
 
802
    void Release()
 
803
    {
 
804
        if(Handle)
 
805
        {
 
806
            Handle->Decrement();
 
807
            CheckReferenceObject();
 
808
        }
 
809
        Handle = 0;
 
810
    }
 
811
private:
 
812
    T& GetHandle()
 
813
    {
 
814
        return *Handle;
 
815
    }
 
816
 
 
817
public:
 
818
    bool IsValid()
 
819
    {
 
820
        if(Handle)
 
821
        {
 
822
            return true;
 
823
        }
 
824
        return false;
 
825
    }
 
826
 
 
827
    bool IsNull()
 
828
    {
 
829
        if(Handle)
 
830
        {
 
831
            return false;
 
832
        }
 
833
        return true;
 
834
    }
 
835
};
 
836
 
 
837
NAMESPACE_END_OGL
 
838
 
 
839
#endif // GLRESOURCE_H
 
840