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"
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"
47
#include "NuxImage/ImageSurface.h"
48
#include "NuxImage/Tga.h"
49
#include "NuxImage/Bmp.h"
50
#include "NuxImage/NPng.h"
52
#define NAMESPACE_BEGIN_OGL namespace nux {
53
#define NAMESPACE_END_OGL }
56
class IOpenGLResource;
60
class NRectangleTexture;
63
class NAnimatedTexture;
69
class NGLRectangleTexture;
71
class NGLTextureVolume;
72
class NGLAnimatedTexture;
76
#include "RunTimeStats.h"
77
#include "GlobalGraphicsInitializer.h"
79
#define NUX_ENABLE_CG_SHADERS 0
81
#if defined(INL_OS_WINDOWS)
82
#include "OpenGL/Glew/glew.h"
83
#include "OpenGL/Glew/wglew.h"
85
GLEWContext* glewGetContext();
86
WGLEWContext* wglewGetContext();
88
#if (NUX_ENABLE_CG_SHADERS)
91
#pragma comment( lib, "cg.lib" )
92
#pragma comment( lib, "cgGL.lib" )
95
#elif defined(INL_OS_LINUX)
100
GLEWContext* glewGetContext();
101
GLXEWContext* glxewGetContext();
103
#if (NUX_ENABLE_CG_SHADERS)
111
#define CG_FRAGMENT_PROFILE CG_PROFILE_FP30
112
#define CG_VERTEX_PROFILE CG_PROFILE_VP30
114
#define INL_BUFFER_OFFSET(i) ((BYTE *)NULL + (i))
124
OGL_INVALID_SURFACE_LEVEL,
129
OGL_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */
132
extern const TCHAR* OGLDeviceErrorMessages[];
135
#define OGL_CALL(call) \
138
if(Result != OGL_OK) \
139
{nuxError(TEXT("OGL Object Error: Error # %d - (%s) "), Result, *OGLDeviceErrorMessages[Result] );} \
142
//if(Result!=OGL_OK) {nuxError(TEXT("OGL Object Error: Error # %d - %s"), Result, OGLDeviceErrorMessages[Result]);}
146
TEXTURE_FMT_UNKNOWN = 0,
147
TEXTURE_FMT_ALPHA = GL_ALPHA,
148
TEXTURE_FMT_ALPHA8 = GL_ALPHA8,
149
TEXTURE_FMT_ALPHA16 = GL_ALPHA16,
151
TEXTURE_FMT_LUMINANCE = GL_LUMINANCE,
152
TEXTURE_FMT_LUMINANCE8 = GL_LUMINANCE8,
153
TEXTURE_FMT_LUMINANCE16 = GL_LUMINANCE16,
155
TEXTURE_FMT_LUMINANCE_ALPHA = GL_LUMINANCE_ALPHA,
156
TEXTURE_FMT_LUMINANCE8_ALPHA8 = GL_LUMINANCE8_ALPHA8,
157
TEXTURE_FMT_LUMINANCE16_ALPHA16 = GL_LUMINANCE16_ALPHA16,
159
TEXTURE_FMT_INTENSITY = GL_INTENSITY,
160
TEXTURE_FMT_INTENSITY8 = GL_INTENSITY8,
161
TEXTURE_FMT_INTENSITY16 = GL_INTENSITY16,
163
TEXTURE_FMT_GL_DEPTH_COMPONENT = GL_DEPTH_COMPONENT,
164
TEXTURE_FMT_GL_DEPTH_COMPONENT24 = GL_DEPTH_COMPONENT24,
166
TEXTURE_FMT_RGBA = GL_RGBA,
167
TEXTURE_FMT_RGBA8 = GL_RGBA8,
168
TEXTURE_FMT_RGBA16 = GL_RGBA16,
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,
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 */
185
struct PixelFormatReadInfo
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
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,
204
CUBEMAP_FACE_FORCE_DWORD = 0x7fffffff
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 */
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 */
224
// Primitives supported by draw-primitive API
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 */
237
enum OpenGLResourceType
252
RT_GLSL_VERTEXSHADER,
254
RT_GLSL_SHADERPROGRAM,
257
RT_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */
260
/* Multi-Sample buffer types */
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 */
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 */
294
OpenGLResourceType ResourceType;
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;
308
MULTISAMPLE_TYPE MultiSampleType;
311
typedef struct _SURFACE_DESC
313
BitmapFormat PixelFormat;
314
OpenGLResourceType Type;
318
MULTISAMPLE_TYPE MultiSampleType;
319
DWORD MultiSampleQuality;
324
typedef struct _VOLUME_DESC {
325
BitmapFormat PixelFormat;
326
OpenGLResourceType Type;
334
typedef struct _ANIMATEDTEXTURE_DESC {
335
BitmapFormat PixelFormat;
336
OpenGLResourceType Type;
342
} ANIMATEDTEXTURE_DESC;
344
typedef struct _VERTEXBUFFER_DESC {
349
typedef struct _INDEXBUFFER_DESC {
355
typedef struct _LOCKED_RECT
359
} SURFACE_LOCKED_RECT;
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.
369
/* Structures for LockBox */
370
typedef struct _VOLUME_BOX
380
typedef struct _VOLUME_LOCKED_BOX
387
typedef enum _ATTRIB_DECL_TYPE
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 */
411
typedef enum _ATTRIB_COMPONENT_TYPE
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;
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 */
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 */
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.
475
Type = ATTRIB_CT_UNKNOWN;
477
Usage = ATTRIB_USAGE_DECL_POSITION;
482
VERTEXELEMENT(WORD stream, WORD offset, ATTRIB_COMPONENT_TYPE type, BYTE numcomponents, ATTRIB_USAGE_DECL usage, BYTE usageindex, BYTE method = 0)
487
NumComponent = numcomponents;
489
UsageIndex = usageindex;
496
// Type can be GL_UNSIGNED_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE ...
497
ATTRIB_COMPONENT_TYPE Type;
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.
503
ATTRIB_USAGE_DECL Usage;
505
// Use this index in association with TEXCOORD or COLOR to identify the texture
506
// coordinate set or the color set.
509
BYTE Method; // Should be always 0 for D3DDECLMETHOD_DEFAULT = 0
511
// The vertex attribute Cg parameter that will be bound to the vertex element;
512
// CGparameter CgParameter;
517
// void setCgParameter(CGparameter parameter)
519
// cgParameter = parameter;
523
#define DECL_END VERTEXELEMENT(0xFF/*Stream*/,0/*Offset*/,ATTRIB_CT_UNKNOWN/*Type*/,0/*NumComponent*/,ATTRIB_USAGE_DECL_POSITION/*Usage*/,0/*UsageIndex*/, 0 /*CgParameter*/)
525
unsigned int GetVertexElementSize(VERTEXELEMENT vtxelement);
527
#define MAXDECLLENGTH 64
528
#define MAX_NUM_STREAM 8
530
void DecomposeTypeDeclaraction(ATTRIB_DECL_TYPE Type, BYTE &NumComponent, ATTRIB_COMPONENT_TYPE &ComponentType);
532
void AddVertexElement(std::vector<VERTEXELEMENT>& Elements,
536
ATTRIB_DECL_TYPE Type,
537
ATTRIB_USAGE_DECL Usage,
540
GLenum GetGLPrimitiveType(PRIMITIVE_TYPE InPrimitiveType);
541
unsigned int GetGLElementCount(PRIMITIVE_TYPE InPrimitiveType,
542
unsigned int InPrimitiveCount);
544
template<typename T> class TRefGL
550
void CheckReferenceObject()
554
if(Handle->GetRefCount() == 0)
557
//GetThreadGLDeviceFactory()->DestroyDeviceResource<T>(Handle);
563
// // Do not allow access to the managed pointer. This also avoid compiler confusion between
564
// // int BindTexture(IOpenGLBaseTexture* texture);
566
// // int BindTexture(TRefGL<IOpenGLBaseTexture> texture);
568
// // Access operators.
582
const T* operator -> () const
594
const T& operator *() const
600
// Constructor/destructor.
601
TRefGL(T* InHandle = 0)
608
template <typename U>
615
if(InHandle->Type().IsDerivedFromType(T::StaticObjectType))
617
Handle = (T*)InHandle;
623
TRefGL(const TRefGL<T>& Copy)
626
Handle = Copy.Handle;
631
template <typename U>
632
TRefGL(const TRefGL<U>& Copy)
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
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
646
if(Copy.Handle->Type().IsDerivedFromType(T::StaticObjectType))
648
Handle = (T*)Copy.Handle;
659
CheckReferenceObject();
663
// Assignment operator.
665
TRefGL<T>& operator = (T* InHandle)
667
if(Handle != InHandle)
672
CheckReferenceObject();
683
TRefGL<T>& operator = (const TRefGL<T>& Other)
685
// Avoid self assignment
686
if(Handle == Other.Handle)
693
CheckReferenceObject();
695
Handle = Other.Handle;
701
bool operator == (const TRefGL<T>& Other) const
703
if(Handle == Other.Handle)
710
bool operator == (const T* Ptr) const
719
template <typename U>
720
bool operator == (const U* Ptr) const
729
template <typename U>
730
bool operator == (TRefGL<U>& Other) const
732
if(Handle == Other.Handle)
739
bool operator != (const TRefGL<T>& Other) const
741
if(Handle != Other.Handle)
748
bool operator != (const T* Ptr) const
757
template <typename U>
758
bool operator != (const U* Ptr) const
767
template <typename U>
768
bool operator != (TRefGL<U>& Other) const
770
if(Handle != Other.Handle)
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
782
// template<typename U>
783
// TRefGL<T>& operator=(const TRefGL<U>& Other)
785
// Handle = (T*)(Other.Handle);
789
// Doing vtx = tex.Castref<IOpenGLVertexBuffer> will return a TRefGL<IOpenGLVertexBuffer> with a null Handle.
794
// Check if type U is derived from type T
795
if(U::StaticObjectType.IsDerivedFromType(T::StaticObjectType))
807
CheckReferenceObject();
839
#endif // GLRESOURCE_H
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"
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"
47
#include "NuxImage/ImageSurface.h"
48
#include "NuxImage/Tga.h"
49
#include "NuxImage/Bmp.h"
50
#include "NuxImage/NPng.h"
52
#define NAMESPACE_BEGIN_OGL namespace nux {
53
#define NAMESPACE_END_OGL }
56
class IOpenGLResource;
60
class NRectangleTexture;
63
class NAnimatedTexture;
69
class NGLRectangleTexture;
71
class NGLTextureVolume;
72
class NGLAnimatedTexture;
76
#include "RunTimeStats.h"
77
#include "GlobalGraphicsInitializer.h"
79
#define NUX_ENABLE_CG_SHADERS 0
81
#if defined(INL_OS_WINDOWS)
82
#include "OpenGL/Glew/glew.h"
83
#include "OpenGL/Glew/wglew.h"
85
GLEWContext* glewGetContext();
86
WGLEWContext* wglewGetContext();
88
#if (NUX_ENABLE_CG_SHADERS)
91
#pragma comment( lib, "cg.lib" )
92
#pragma comment( lib, "cgGL.lib" )
95
#elif defined(INL_OS_LINUX)
100
GLEWContext* glewGetContext();
101
GLXEWContext* glxewGetContext();
103
#if (NUX_ENABLE_CG_SHADERS)
111
#define CG_FRAGMENT_PROFILE CG_PROFILE_FP30
112
#define CG_VERTEX_PROFILE CG_PROFILE_VP30
114
#define INL_BUFFER_OFFSET(i) ((BYTE *)NULL + (i))
124
OGL_INVALID_SURFACE_LEVEL,
129
OGL_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */
132
extern const TCHAR* OGLDeviceErrorMessages[];
135
#define OGL_CALL(call) \
138
if(Result != OGL_OK) \
139
{nuxError(TEXT("OGL Object Error: Error # %d - (%s) "), Result, *OGLDeviceErrorMessages[Result] );} \
142
//if(Result!=OGL_OK) {nuxError(TEXT("OGL Object Error: Error # %d - %s"), Result, OGLDeviceErrorMessages[Result]);}
146
TEXTURE_FMT_UNKNOWN = 0,
147
TEXTURE_FMT_ALPHA = GL_ALPHA,
148
TEXTURE_FMT_ALPHA8 = GL_ALPHA8,
149
TEXTURE_FMT_ALPHA16 = GL_ALPHA16,
151
TEXTURE_FMT_LUMINANCE = GL_LUMINANCE,
152
TEXTURE_FMT_LUMINANCE8 = GL_LUMINANCE8,
153
TEXTURE_FMT_LUMINANCE16 = GL_LUMINANCE16,
155
TEXTURE_FMT_LUMINANCE_ALPHA = GL_LUMINANCE_ALPHA,
156
TEXTURE_FMT_LUMINANCE8_ALPHA8 = GL_LUMINANCE8_ALPHA8,
157
TEXTURE_FMT_LUMINANCE16_ALPHA16 = GL_LUMINANCE16_ALPHA16,
159
TEXTURE_FMT_INTENSITY = GL_INTENSITY,
160
TEXTURE_FMT_INTENSITY8 = GL_INTENSITY8,
161
TEXTURE_FMT_INTENSITY16 = GL_INTENSITY16,
163
TEXTURE_FMT_GL_DEPTH_COMPONENT = GL_DEPTH_COMPONENT,
164
TEXTURE_FMT_GL_DEPTH_COMPONENT24 = GL_DEPTH_COMPONENT24,
166
TEXTURE_FMT_RGBA = GL_RGBA,
167
TEXTURE_FMT_RGBA8 = GL_RGBA8,
168
TEXTURE_FMT_RGBA16 = GL_RGBA16,
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,
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 */
185
struct PixelFormatReadInfo
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
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,
204
CUBEMAP_FACE_FORCE_DWORD = 0x7fffffff
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 */
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 */
224
// Primitives supported by draw-primitive API
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 */
237
enum OpenGLResourceType
252
RT_GLSL_VERTEXSHADER,
254
RT_GLSL_SHADERPROGRAM,
257
RT_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */
260
/* Multi-Sample buffer types */
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 */
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 */
294
OpenGLResourceType ResourceType;
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;
308
MULTISAMPLE_TYPE MultiSampleType;
311
typedef struct _SURFACE_DESC
313
BitmapFormat PixelFormat;
314
OpenGLResourceType Type;
318
MULTISAMPLE_TYPE MultiSampleType;
319
DWORD MultiSampleQuality;
324
typedef struct _VOLUME_DESC {
325
BitmapFormat PixelFormat;
326
OpenGLResourceType Type;
334
typedef struct _ANIMATEDTEXTURE_DESC {
335
BitmapFormat PixelFormat;
336
OpenGLResourceType Type;
342
} ANIMATEDTEXTURE_DESC;
344
typedef struct _VERTEXBUFFER_DESC {
349
typedef struct _INDEXBUFFER_DESC {
355
typedef struct _LOCKED_RECT
359
} SURFACE_LOCKED_RECT;
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.
369
/* Structures for LockBox */
370
typedef struct _VOLUME_BOX
380
typedef struct _VOLUME_LOCKED_BOX
387
typedef enum _ATTRIB_DECL_TYPE
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 */
411
typedef enum _ATTRIB_COMPONENT_TYPE
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;
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 */
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 */
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.
475
Type = ATTRIB_CT_UNKNOWN;
477
Usage = ATTRIB_USAGE_DECL_POSITION;
482
VERTEXELEMENT(WORD stream, WORD offset, ATTRIB_COMPONENT_TYPE type, BYTE numcomponents, ATTRIB_USAGE_DECL usage, BYTE usageindex, BYTE method = 0)
487
NumComponent = numcomponents;
489
UsageIndex = usageindex;
496
// Type can be GL_UNSIGNED_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE ...
497
ATTRIB_COMPONENT_TYPE Type;
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.
503
ATTRIB_USAGE_DECL Usage;
505
// Use this index in association with TEXCOORD or COLOR to identify the texture
506
// coordinate set or the color set.
509
BYTE Method; // Should be always 0 for D3DDECLMETHOD_DEFAULT = 0
511
// The vertex attribute Cg parameter that will be bound to the vertex element;
512
// CGparameter CgParameter;
517
// void setCgParameter(CGparameter parameter)
519
// cgParameter = parameter;
523
#define DECL_END VERTEXELEMENT(0xFF/*Stream*/,0/*Offset*/,ATTRIB_CT_UNKNOWN/*Type*/,0/*NumComponent*/,ATTRIB_USAGE_DECL_POSITION/*Usage*/,0/*UsageIndex*/, 0 /*CgParameter*/)
525
unsigned int GetVertexElementSize(VERTEXELEMENT vtxelement);
527
#define MAXDECLLENGTH 64
528
#define MAX_NUM_STREAM 8
530
void DecomposeTypeDeclaraction(ATTRIB_DECL_TYPE Type, BYTE &NumComponent, ATTRIB_COMPONENT_TYPE &ComponentType);
532
void AddVertexElement(std::vector<VERTEXELEMENT>& Elements,
536
ATTRIB_DECL_TYPE Type,
537
ATTRIB_USAGE_DECL Usage,
540
GLenum GetGLPrimitiveType(PRIMITIVE_TYPE InPrimitiveType);
541
unsigned int GetGLElementCount(PRIMITIVE_TYPE InPrimitiveType,
542
unsigned int InPrimitiveCount);
544
template<typename T> class TRefGL
550
void CheckReferenceObject()
554
if(Handle->GetRefCount() == 0)
557
//GetThreadGLDeviceFactory()->DestroyDeviceResource<T>(Handle);
563
// // Do not allow access to the managed pointer. This also avoid compiler confusion between
564
// // int BindTexture(IOpenGLBaseTexture* texture);
566
// // int BindTexture(TRefGL<IOpenGLBaseTexture> texture);
568
// // Access operators.
582
const T* operator -> () const
594
const T& operator *() const
600
// Constructor/destructor.
601
TRefGL(T* InHandle = 0)
608
template <typename U>
615
if(InHandle->Type().IsDerivedFromType(T::StaticObjectType))
617
Handle = (T*)InHandle;
623
TRefGL(const TRefGL<T>& Copy)
626
Handle = Copy.Handle;
631
template <typename U>
632
TRefGL(const TRefGL<U>& Copy)
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
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
646
if(Copy.Handle->Type().IsDerivedFromType(T::StaticObjectType))
648
Handle = (T*)Copy.Handle;
659
CheckReferenceObject();
663
// Assignment operator.
665
TRefGL<T>& operator = (T* InHandle)
667
if(Handle != InHandle)
672
CheckReferenceObject();
683
TRefGL<T>& operator = (const TRefGL<T>& Other)
685
// Avoid self assignment
686
if(Handle == Other.Handle)
693
CheckReferenceObject();
695
Handle = Other.Handle;
701
bool operator == (const TRefGL<T>& Other) const
703
if(Handle == Other.Handle)
710
bool operator == (const T* Ptr) const
719
template <typename U>
720
bool operator == (const U* Ptr) const
729
template <typename U>
730
bool operator == (TRefGL<U>& Other) const
732
if(Handle == Other.Handle)
739
bool operator != (const TRefGL<T>& Other) const
741
if(Handle != Other.Handle)
748
bool operator != (const T* Ptr) const
757
template <typename U>
758
bool operator != (const U* Ptr) const
767
template <typename U>
768
bool operator != (TRefGL<U>& Other) const
770
if(Handle != Other.Handle)
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
782
// template<typename U>
783
// TRefGL<T>& operator=(const TRefGL<U>& Other)
785
// Handle = (T*)(Other.Handle);
789
// Doing vtx = tex.Castref<IOpenGLVertexBuffer> will return a TRefGL<IOpenGLVertexBuffer> with a null Handle.
794
// Check if type U is derived from type T
795
if(U::StaticObjectType.IsDerivedFromType(T::StaticObjectType))
807
CheckReferenceObject();
839
#endif // GLRESOURCE_H