nux-0.9.46
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef GLRESOURCE_H 00024 #define GLRESOURCE_H 00025 00026 #include "NuxCore/NuxCore.h" 00027 #include "NuxCore/Namespace.h" 00028 #include "NuxCore/SystemTypes.h" 00029 #include "NuxCore/Error.h" 00030 #include "NuxCore/FilePath.h" 00031 #include "NuxCore/Color.h" 00032 #include "NuxCore/Rect.h" 00033 #include "NuxCore/Point.h" 00034 #include "NuxCore/Size.h" 00035 #include "NuxImage/BitmapFormats.h" 00036 #include "NuxCore/Parsing.h" 00037 #include "NuxCore/Object.h" 00038 #include "NuxCore/SmartPtr/GenericSmartPointer.h" 00039 #include "NuxCore/ObjectPtr.h" 00040 00041 #include "NuxCore/Math/MathUtility.h" 00042 #include "NuxCore/Math/Constants.h" 00043 #include "NuxCore/Math/Vector3.h" 00044 #include "NuxCore/Math/Vector4.h" 00045 #include "NuxCore/Math/Matrix3.h" 00046 #include "NuxCore/Math/Matrix4.h" 00047 #include "NuxCore/Math/Spline.h" 00048 #include "NuxCore/Math/MathFunctions.h" 00049 00050 #include "NuxImage/ImageSurface.h" 00051 00052 namespace nux 00053 { 00054 class IOpenGLResource; 00055 00056 class BaseTexture; 00057 class Texture2D; 00058 class TextureRectangle; 00059 class TextureCube; 00060 class TextureVolume; 00061 class TextureFrameAnimation; 00062 00063 class NVertexBuffer; 00064 class NIndexBuffer; 00065 00066 class CachedTexture2D; 00067 class CachedTextureRectangle; 00068 class CachedTextureCube; 00069 class CachedTextureVolume; 00070 class CachedTextureFrameAnimation; 00071 class FontTexture; 00072 00073 } 00074 00075 #define NUX_ENABLE_CG_SHADERS 0 00076 00077 //#define NUX_OPENGLES_20 00078 00079 #if defined(NUX_OS_WINDOWS) 00080 #include "GL/glew.h" 00081 #include "GL/wglew.h" 00082 00083 GLEWContext *glewGetContext(); 00084 WGLEWContext *wglewGetContext(); 00085 00086 #if (NUX_ENABLE_CG_SHADERS) 00087 #include "CG/cg.h" 00088 #include "CG/cgGL.h" 00089 #pragma comment( lib, "cg.lib" ) 00090 #pragma comment( lib, "cgGL.lib" ) 00091 #endif 00092 00093 #elif defined(NUX_OS_LINUX) 00094 00095 #ifdef NUX_OPENGLES_20 00096 #define GLEW_MX 00097 #include "EGL/egl.h" 00098 #include "GLES2/gl2.h" 00099 #else 00100 #define GLEW_MX 00101 #include "GL/glew.h" 00102 #include "GL/glxew.h" 00103 00104 GLEWContext *glewGetContext(); 00105 GLXEWContext *glxewGetContext(); 00106 00107 #if (NUX_ENABLE_CG_SHADERS) 00108 #include "Cg/cg.h" 00109 #include "Cg/cgGL.h" 00110 #endif 00111 #endif 00112 00113 #endif 00114 00115 #include "RunTimeStats.h" 00116 #include "NuxGraphicsResources.h" 00117 #include "FontTexture.h" 00118 #include "GlobalGraphicsInitializer.h" 00119 00120 #include "GLError.h" 00121 00122 #define CG_FRAGMENT_PROFILE CG_PROFILE_FP30 00123 #define CG_VERTEX_PROFILE CG_PROFILE_VP30 00124 00125 #define NUX_BUFFER_OFFSET(i) ((BYTE *)NULL + (i)) 00126 00127 00128 namespace nux 00129 { 00130 00131 enum 00132 { 00133 OGL_OK = 0, 00134 OGL_ERROR, 00135 OGL_ERROR_UNKNOWN, 00136 OGL_INVALID_SURFACE_LEVEL, 00137 OGL_INVALID_CALL, 00138 OGL_INVALID_LOCK, 00139 OGL_INVALID_UNLOCK, 00140 OGL_INVALID_TEXTURE, 00141 OGL_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00142 }; 00143 00144 extern const TCHAR *OGLDeviceErrorMessages[]; 00145 00146 #define OGL_OK 0 00147 #define OGL_CALL(call) \ 00148 { \ 00149 int Result = call; \ 00150 if(Result != OGL_OK) \ 00151 {nuxError(TEXT("OGL Object Error: Error # %d - (%s) "), Result, *OGLDeviceErrorMessages[Result] );} \ 00152 } 00153 00154 //if(Result!=OGL_OK) {nuxError(TEXT("OGL Object Error: Error # %d - %s"), Result, OGLDeviceErrorMessages[Result]);} 00155 00156 enum TEXTURE_FORMAT 00157 { 00158 TEXTURE_FMT_UNKNOWN = 0, 00159 TEXTURE_FMT_ALPHA = GL_ALPHA, 00160 TEXTURE_FMT_ALPHA8 = GL_ALPHA8, 00161 TEXTURE_FMT_ALPHA16 = GL_ALPHA16, 00162 00163 TEXTURE_FMT_LUMINANCE = GL_LUMINANCE, 00164 TEXTURE_FMT_LUMINANCE8 = GL_LUMINANCE8, 00165 TEXTURE_FMT_LUMINANCE16 = GL_LUMINANCE16, 00166 00167 TEXTURE_FMT_LUMINANCE_ALPHA = GL_LUMINANCE_ALPHA, 00168 TEXTURE_FMT_LUMINANCE8_ALPHA8 = GL_LUMINANCE8_ALPHA8, 00169 TEXTURE_FMT_LUMINANCE16_ALPHA16 = GL_LUMINANCE16_ALPHA16, 00170 00171 TEXTURE_FMT_INTENSITY = GL_INTENSITY, 00172 TEXTURE_FMT_INTENSITY8 = GL_INTENSITY8, 00173 TEXTURE_FMT_INTENSITY16 = GL_INTENSITY16, 00174 00175 TEXTURE_FMT_GL_DEPTH_COMPONENT = GL_DEPTH_COMPONENT, 00176 TEXTURE_FMT_GL_DEPTH_COMPONENT24 = GL_DEPTH_COMPONENT24, 00177 00178 TEXTURE_FMT_RGBA = GL_RGBA, 00179 TEXTURE_FMT_RGBA8 = GL_RGBA8, 00180 TEXTURE_FMT_RGBA16 = GL_RGBA16, 00181 00182 TEXTURE_FMT_RGBA16F_ARB = GL_RGBA16F_ARB, 00183 TEXTURE_FMT_RGBA32F_ARB = GL_RGBA32F_ARB, 00184 TEXTURE_FMT_RGB = GL_RGB, 00185 TEXTURE_FMT_RGB8 = GL_RGB8, 00186 TEXTURE_FMT_RGB16 = GL_RGB16, 00187 TEXTURE_FMT_RGB16F_ARB = GL_RGB16F_ARB, 00188 TEXTURE_FMT_RGB32F_ARB = GL_RGB32F_ARB, 00189 00190 TEXTURE_FMT_COMPRESSED_RGB_S3TC_DXT1_EXT = GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 00191 TEXTURE_FMT_COMPRESSED_RGBA_S3TC_DXT1_EXT = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 00192 TEXTURE_FMT_COMPRESSED_RGBA_S3TC_DXT3_EXT = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 00193 TEXTURE_FMT_COMPRESSED_RGBA_S3TC_DXT5_EXT = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 00194 TEXTURE_FMT_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00195 }; 00196 00197 struct PixelFormatReadInfo 00198 { 00199 const TCHAR *Name; 00200 GLenum Format; // format use for glReadPixels 00201 GLenum type; // type use for glReadPixels 00202 // Format specific internal flags, e.g. whether SRGB is supported with this format 00203 DWORD Flags; 00204 bool Supported; 00205 }; 00206 00207 enum eCUBEMAP_FACES 00208 { 00209 CUBEMAP_FACE_POSITIVE_X = GL_TEXTURE_CUBE_MAP_POSITIVE_X, 00210 CUBEMAP_FACE_NEGATIVE_X = GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 00211 CUBEMAP_FACE_POSITIVE_Y = GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 00212 CUBEMAP_FACE_NEGATIVE_Y = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 00213 CUBEMAP_FACE_POSITIVE_Z = GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 00214 CUBEMAP_FACE_NEGATIVE_Z = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 00215 00216 CUBEMAP_FACE_FORCE_DWORD = 0x7fffffff 00217 }; 00218 00219 enum VBO_USAGE 00220 { 00221 VBO_USAGE_UNKNOWN = 0, 00222 VBO_USAGE_STATIC = GL_STATIC_DRAW, 00223 VBO_USAGE_DYNAMIC = GL_DYNAMIC_DRAW, 00224 VBO_USAGE_STREAM = GL_STREAM_DRAW, 00225 VBO_USAGE_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00226 }; 00227 00228 enum INDEX_FORMAT 00229 { 00230 INDEX_FORMAT_UNKNOWN = 0, 00231 INDEX_FORMAT_USHORT = GL_UNSIGNED_SHORT, 00232 INDEX_FORMAT_UINT = GL_UNSIGNED_INT, 00233 INDEX_FORMAT_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00234 }; 00235 00236 // Primitives supported by draw-primitive API 00237 typedef enum 00238 { 00239 PRIMITIVE_TYPE_POINTLIST = GL_POINTS, 00240 PRIMITIVE_TYPE_LINELIST = GL_LINES, 00241 PRIMITIVE_TYPE_LINESTRIP = GL_LINE_STRIP, 00242 PRIMITIVE_TYPE_TRIANGLELIST = GL_TRIANGLES, 00243 PRIMITIVE_TYPE_TRIANGLESTRIP = GL_TRIANGLE_STRIP, 00244 PRIMITIVE_TYPE_TRIANGLEFAN = GL_TRIANGLE_FAN, 00245 PRIMITIVE_TYPE_QUADLIST = GL_QUADS, 00246 PRIMITIVE_TYPE_QUADSTRIP = GL_QUAD_STRIP, 00247 PRIMITIVE_TYPE_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00248 } PRIMITIVE_TYPE; 00249 00250 typedef enum 00251 { 00252 RTINDEXBUFFER, 00253 RTVERTEXBUFFER, 00254 RTSURFACE, 00255 RTVOLUME, 00256 RTBASETEXTURE, 00257 RTTEXTURE, 00258 RTTEXTURERECTANGLE, 00259 RTCUBETEXTURE, 00260 RTVOLUMETEXTURE, 00261 RTANIMATEDTEXTURE, 00262 RTVERTEXDECLARATION, 00263 RTQUERY, 00264 RTFRAMEBUFFEROBJECT, 00265 RT_GLSL_VERTEXSHADER, 00266 RT_GLSL_PIXELSHADER, 00267 RT_GLSL_SHADERPROGRAM, 00268 RT_CG_VERTEXSHADER, 00269 RT_CG_PIXELSHADER, 00270 RT_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00271 } OpenGLResourceType; 00272 00273 /* Multi-Sample buffer types */ 00274 typedef enum 00275 { 00276 MULTISAMPLE_TYPE_NONE = 0, 00277 MULTISAMPLE_TYPE_NONMASKABLE = 1, 00278 MULTISAMPLE_TYPE_2_SAMPLES = 2, 00279 MULTISAMPLE_TYPE_3_SAMPLES = 3, 00280 MULTISAMPLE_TYPE_4_SAMPLES = 4, 00281 MULTISAMPLE_TYPE_5_SAMPLES = 5, 00282 MULTISAMPLE_TYPE_6_SAMPLES = 6, 00283 MULTISAMPLE_TYPE_7_SAMPLES = 7, 00284 MULTISAMPLE_TYPE_8_SAMPLES = 8, 00285 MULTISAMPLE_TYPE_9_SAMPLES = 9, 00286 MULTISAMPLE_TYPE_10_SAMPLES = 10, 00287 MULTISAMPLE_TYPE_11_SAMPLES = 11, 00288 MULTISAMPLE_TYPE_12_SAMPLES = 12, 00289 MULTISAMPLE_TYPE_13_SAMPLES = 13, 00290 MULTISAMPLE_TYPE_14_SAMPLES = 14, 00291 MULTISAMPLE_TYPE_15_SAMPLES = 15, 00292 MULTISAMPLE_TYPE_16_SAMPLES = 16, 00293 MULTISAMPLE_TYPE_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00294 } MULTISAMPLE_TYPE; 00295 00296 typedef enum 00297 { 00298 MEM_POOL_DEFAULT = 0, 00299 MEM_POOL_MANAGED = 1, 00300 MEM_POOL_SYSTEMMEM = 2, 00301 MEM_POOL_SCRATCH = 3, 00302 MEM_POOL_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00303 } MEM_POOL; 00304 00305 00306 typedef struct 00307 { 00308 OpenGLResourceType ResourceType; 00309 unsigned int Width; 00310 unsigned int Height; 00311 unsigned int Depth; 00312 BitmapFormat PixelFormat; 00313 unsigned int RowPitch; 00314 unsigned int SlicePitch; 00315 unsigned int BitsPerPixel; 00316 unsigned int WidthInBlocks; 00317 unsigned int HeightInBlocks; 00318 unsigned int DepthInBlocks; 00319 unsigned int BytesPerBlock; 00320 int ExpBias; 00321 DWORD Flags; 00322 MULTISAMPLE_TYPE MultiSampleType; 00323 } TEXTURE_DESC; 00324 00325 typedef struct _SURFACE_DESC 00326 { 00327 BitmapFormat PixelFormat; 00328 OpenGLResourceType Type; 00329 DWORD Usage; 00330 MEM_POOL Pool; 00331 00332 MULTISAMPLE_TYPE MultiSampleType; 00333 DWORD MultiSampleQuality; 00334 unsigned int Width; 00335 unsigned int Height; 00336 } SURFACE_DESC; 00337 00338 typedef struct _VOLUME_DESC 00339 { 00340 BitmapFormat PixelFormat; 00341 OpenGLResourceType Type; 00342 DWORD Usage; 00343 MEM_POOL Pool; 00344 unsigned int Width; 00345 unsigned int Height; 00346 unsigned int Depth; 00347 } VOLUME_DESC; 00348 00349 typedef struct _ANIMATEDTEXTURE_DESC 00350 { 00351 BitmapFormat PixelFormat; 00352 OpenGLResourceType Type; 00353 DWORD Usage; 00354 MEM_POOL Pool; 00355 unsigned int Width; 00356 unsigned int Height; 00357 unsigned int Depth; 00358 } ANIMATEDTEXTURE_DESC; 00359 00360 typedef struct _VERTEXBUFFER_DESC 00361 { 00362 VBO_USAGE Usage; 00363 unsigned int Size; 00364 } VERTEXBUFFER_DESC; 00365 00366 typedef struct _INDEXBUFFER_DESC 00367 { 00368 INDEX_FORMAT Format; 00369 VBO_USAGE Usage; 00370 unsigned int Size; 00371 } INDEXBUFFER_DESC; 00372 00373 typedef struct _LOCKED_RECT 00374 { 00375 int Pitch; 00376 void *pBits; 00377 } SURFACE_LOCKED_RECT; 00378 00379 typedef struct _SURFACE_RECT 00380 { 00381 long left; //Specifies the x-coordinate of the lower-left corner of the rectangle. 00382 long top; //Specifies the y-coordinate of the lower-left corner of the rectangle. 00383 long right; //Specifies the x-coordinate of the upper-right corner of the rectangle. 00384 long bottom; //Specifies the y-coordinate of the upper-right corner of the rectangle. 00385 } SURFACE_RECT; 00386 00387 00388 /* Structures for LockBox */ 00389 typedef struct _VOLUME_BOX 00390 { 00391 int Left; 00392 int Top; 00393 int Right; 00394 int Bottom; 00395 int Front; 00396 int Back; 00397 } VOLUME_BOX; 00398 00399 typedef struct _VOLUME_LOCKED_BOX 00400 { 00401 int RowPitch; 00402 int SlicePitch; 00403 void *pBits; 00404 } VOLUME_LOCKED_BOX; 00405 00406 typedef enum _ATTRIB_DECL_TYPE 00407 { 00408 ATTRIB_DECLTYPE_UNKNOWN = 0, 00409 ATTRIB_DECLTYPE_FLOAT1, 00410 ATTRIB_DECLTYPE_FLOAT2, 00411 ATTRIB_DECLTYPE_FLOAT3, 00412 ATTRIB_DECLTYPE_FLOAT4, 00413 ATTRIB_DECLTYPE_COLOR, 00414 ATTRIB_DECLTYPE_UBYTE4, 00415 ATTRIB_DECLTYPE_SHORT2, 00416 ATTRIB_DECLTYPE_SHORT4, 00417 ATTRIB_DECLTYPE_UBYTE4N, 00418 ATTRIB_DECLTYPE_SHORT2N, 00419 ATTRIB_DECLTYPE_SHORT4N, 00420 ATTRIB_DECLTYPE_USHORT2N, 00421 ATTRIB_DECLTYPE_USHORT4N, 00422 ATTRIB_DECLTYPE_UDEC3, 00423 ATTRIB_DECLTYPE_DEC3N, 00424 ATTRIB_DECLTYPE_FLOAT16_2, 00425 ATTRIB_DECLTYPE_FLOAT16_4, 00426 ATTRIB_DECLTYPE_UNUSED, 00427 ATTRIB_DECLTYPE_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00428 } ATTRIB_DECL_TYPE; 00429 00430 typedef enum _ATTRIB_COMPONENT_TYPE 00431 { 00432 ATTRIB_CT_UNKNOWN = 0, 00433 ATTRIB_CT_BYTE = GL_BYTE, 00434 ATTRIB_CT_UNSIGNED_BYTE = GL_UNSIGNED_BYTE, 00435 ATTRIB_CT_SHORT = GL_SHORT, 00436 ATTRIB_CT_UNSIGNED_SHORT = GL_UNSIGNED_SHORT, 00437 ATTRIB_CT_INT = GL_INT, 00438 ATTRIB_CT_UNSIGNED_INT = GL_UNSIGNED_INT, 00439 ATTRIB_CT_FLOAT = GL_FLOAT, 00440 ATTRIB_CT_HALF_FLOAT = GL_HALF_FLOAT_ARB, 00441 // ATTRIB_CT_2_BYTES = GL_2_BYTES, 00442 // ATTRIB_CT_3_BYTES = GL_3_BYTES, 00443 // ATTRIB_CT_4_BYTES = GL_4_BYTES, 00444 ATTRIB_CT_DOUBLE = GL_DOUBLE, 00445 // Type can be GL_UNSIGNED_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE 00446 ATTRIB_CT_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00447 } ATTRIB_COMPONENT_TYPE; 00448 00449 // Binding Semantics 00450 typedef enum 00451 { 00452 ATTRIB_USAGE_DECL_POSITION = 0, 00453 ATTRIB_USAGE_DECL_BLENDWEIGHT = 1, 00454 ATTRIB_USAGE_DECL_NORMAL = 2, 00455 ATTRIB_USAGE_DECL_COLOR = 3, 00456 ATTRIB_USAGE_DECL_COLOR1 = 4, 00457 ATTRIB_USAGE_DECL_FOGCOORD = 5, 00458 ATTRIB_USAGE_DECL_PSIZE = 6, 00459 ATTRIB_USAGE_DECL_BLENDINDICES = 7, 00460 ATTRIB_USAGE_DECL_TEXCOORD = 8, 00461 ATTRIB_USAGE_DECL_TEXCOORD0 = 8, 00462 ATTRIB_USAGE_DECL_TEXCOORD1 = 9, 00463 ATTRIB_USAGE_DECL_TEXCOORD2 = 10, 00464 ATTRIB_USAGE_DECL_TEXCOORD3 = 11, 00465 ATTRIB_USAGE_DECL_TEXCOORD4 = 12, 00466 ATTRIB_USAGE_DECL_TEXCOORD5 = 13, 00467 ATTRIB_USAGE_DECL_TEXCOORD6 = 14, 00468 ATTRIB_USAGE_DECL_TEXCOORD7 = 15, 00469 ATTRIB_USAGE_DECL_TANGENT = 14, 00470 ATTRIB_USAGE_DECL_BINORMAL = 15, 00471 ATTRIB_USAGE_DECL_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00472 } ATTRIB_USAGE_DECL; 00473 00474 typedef enum 00475 { 00476 QUERY_TYPE_VCACHE = 4, 00477 QUERY_TYPE_RESOURCEMANAGER = 5, 00478 QUERY_TYPE_VERTEXSTATS = 6, 00479 QUERY_TYPE_EVENT = 8, 00480 QUERY_TYPE_OCCLUSION = 9, 00481 QUERY_TYPE_SCREENEXTENT = 10, 00482 QUERY_TYPE_FORCE_DWORD = 0x7fffffff /* force 32-bit size enum */ 00483 } QUERY_TYPE; 00484 00485 // Flags field for Issue 00486 #define ISSUE_END (1 << 0) // Tells the runtime to issue the end of a query, changing it's state to "non-signaled". 00487 #define ISSUE_BEGIN (1 << 1) // Tells the runtime to issue the begining of a query. 00488 00489 struct VERTEXELEMENT 00490 { 00491 VERTEXELEMENT() 00492 { 00493 Stream = 0; 00494 Offset = 0; 00495 Type = ATTRIB_CT_UNKNOWN; 00496 NumComponent = 0; 00497 Usage = ATTRIB_USAGE_DECL_POSITION; 00498 UsageIndex = 0; 00499 Method = 0; 00500 } 00501 00502 VERTEXELEMENT (WORD stream, WORD offset, ATTRIB_COMPONENT_TYPE type, BYTE numcomponents, ATTRIB_USAGE_DECL usage, BYTE usageindex, BYTE method = 0) 00503 { 00504 Stream = stream; 00505 Offset = offset; 00506 Type = type; 00507 NumComponent = numcomponents; 00508 Usage = usage; 00509 UsageIndex = usageindex; 00510 Method = method; 00511 } 00512 00513 WORD Stream; 00514 WORD Offset; 00515 00516 // Type can be GL_UNSIGNED_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE ... 00517 ATTRIB_COMPONENT_TYPE Type; 00518 //DWORD Stride; 00519 00520 // 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. 00521 BYTE NumComponent; 00522 00523 ATTRIB_USAGE_DECL Usage; 00524 00525 // Use this index in association with TEXCOORD or COLOR to identify the texture 00526 // coordinate set or the color set. 00527 BYTE UsageIndex; 00528 00529 BYTE Method; // Should be always 0 for D3DDECLMETHOD_DEFAULT = 0 00530 00531 // The vertex attribute Cg parameter that will be bound to the vertex element; 00532 // CGparameter CgParameter; 00533 // VERTEXELEMENT() 00534 // { 00535 // CgParameter = 0; 00536 // } 00537 // void setCgParameter(CGparameter parameter) 00538 // { 00539 // cgParameter = parameter; 00540 // } 00541 }; 00542 00543 #define DECL_END VERTEXELEMENT(0xFF/*Stream*/,0/*Offset*/,ATTRIB_CT_UNKNOWN/*Type*/,0/*NumComponent*/,ATTRIB_USAGE_DECL_POSITION/*Usage*/,0/*UsageIndex*/, 0 /*CgParameter*/) 00544 00545 unsigned int GetVertexElementSize (VERTEXELEMENT vtxelement); 00546 00547 #define MAXDECLLENGTH 64 00548 #define MAX_NUM_STREAM 8 00549 00550 void DecomposeTypeDeclaraction (ATTRIB_DECL_TYPE Type, BYTE &NumComponent, ATTRIB_COMPONENT_TYPE &ComponentType); 00551 00552 void AddVertexElement (std::vector<VERTEXELEMENT>& Elements, 00553 WORD Stream, 00554 WORD Offset, 00555 //ubiS16 Stride, 00556 ATTRIB_DECL_TYPE Type, 00557 ATTRIB_USAGE_DECL Usage, 00558 BYTE UsageIndex); 00559 00560 GLenum GetGLPrimitiveType (PRIMITIVE_TYPE InPrimitiveType); 00561 unsigned int GetGLElementCount (PRIMITIVE_TYPE InPrimitiveType, 00562 unsigned int InPrimitiveCount); 00563 00564 // template<typename T> class ObjectPtr 00565 // { 00566 // public: 00567 // T *Handle; 00568 // 00569 // private: 00570 // void CheckReferenceObject() 00571 // { 00572 // if (Handle) 00573 // { 00574 // if (Handle->GetValue() == 0) 00575 // { 00576 // delete Handle; 00577 // //GetGpuDevice()->DestroyDeviceResource<T>(Handle); 00578 // } 00579 // } 00580 // 00581 // Handle = 0; 00582 // } 00583 // 00584 // // // Do not allow access to the managed pointer. This also avoid compiler confusion between 00585 // // // int BindTexture(IOpenGLBaseTexture* texture); 00586 // // // and 00587 // // // int BindTexture(ObjectPtr<IOpenGLBaseTexture> texture); 00588 // // 00589 // // // Access operators. 00590 // // typedef T* PtrT; 00591 // // operator T*() 00592 // // { 00593 // // return Handle; 00594 // // } 00595 // 00596 // public: 00597 // T *operator -> () 00598 // { 00599 // nuxAssert (Handle); 00600 // return Handle; 00601 // } 00602 // 00603 // const T *operator -> () const 00604 // { 00605 // nuxAssert (Handle); 00606 // return Handle; 00607 // } 00608 // 00609 // T &operator*() 00610 // { 00611 // nuxAssert (Handle); 00612 // return *Handle; 00613 // } 00614 // 00615 // const T &operator *() const 00616 // { 00617 // nuxAssert (Handle); 00618 // return *Handle; 00619 // } 00620 // 00621 // // Constructor/destructor. 00622 // ObjectPtr (T *InHandle = 0) 00623 // : Handle (InHandle) 00624 // { 00625 // if (Handle) 00626 // Handle->Increment(); 00627 // } 00628 // 00629 // template <typename U> 00630 // ObjectPtr (U *InHandle) 00631 // : Handle (0) 00632 // { 00633 // if (InHandle == 0) 00634 // return; 00635 // 00636 // if (InHandle->Type().IsDerivedFromType (T::StaticObjectType) ) 00637 // { 00638 // Handle = (T *) InHandle; 00639 // } 00640 // 00641 // if (Handle) 00642 // Handle->Increment(); 00643 // } 00644 // 00645 // ObjectPtr (const ObjectPtr<T>& Copy) 00646 // : Handle (0) 00647 // { 00648 // Handle = Copy.Handle; 00649 // 00650 // if (Handle) 00651 // Handle->Increment(); 00652 // } 00653 // 00654 // template <typename U> 00655 // ObjectPtr (const ObjectPtr<U>& Copy) 00656 // : Handle (0) 00657 // { 00658 // // Check if type U is derived from type T 00659 // // Type() is virtual. Even if we have a ObjectPtr<IOpenGLBaseTexture> but its internal pointer is a IOpenGLCubeTexture, 00660 // // Type() returns the static object type inside IOpenGLCubeTexture. 00661 // // This make this possible 00662 // // 00663 // // ObjectPtr<IOpenGLBaseTexture> basetex; // IOpenGLBaseTexture is an abstract base class for IOpenGLTexture2D 00664 // // basetex = gGLDeviceFactory->CreateTexture(.....); 00665 // // ObjectPtr<IOpenGLVertexBuffer> vtx(basetex); // vtx Handle will be null 00666 // // ObjectPtr<IOpenGLTexture2D> tex(basetex); // tex Handle will be the same as basetex 00667 // // 00668 // 00669 // if (Copy.Handle->Type().IsDerivedFromType (T::StaticObjectType) ) 00670 // { 00671 // Handle = (T *) Copy.Handle; 00672 // } 00673 // 00674 // if (Handle) 00675 // Handle->Increment(); 00676 // } 00677 // 00678 // ~ObjectPtr() 00679 // { 00680 // if (Handle) 00681 // { 00682 // Handle->Decrement(); 00683 // CheckReferenceObject(); 00684 // } 00685 // } 00686 // 00687 // // Assignment operator. 00688 // 00689 // ObjectPtr<T>& operator = (T *InHandle) 00690 // { 00691 // if (Handle != InHandle) 00692 // { 00693 // if (Handle) 00694 // { 00695 // Handle->Decrement(); 00696 // CheckReferenceObject(); 00697 // } 00698 // 00699 // Handle = InHandle; 00700 // 00701 // if (Handle) 00702 // Handle->Increment(); 00703 // } 00704 // 00705 // return *this; 00706 // } 00707 // 00708 // ObjectPtr<T>& operator = (const ObjectPtr<T>& Other) 00709 // { 00710 // // Avoid self assignment 00711 // if (Handle == Other.Handle) 00712 // { 00713 // return *this; 00714 // } 00715 // 00716 // if (Handle) 00717 // { 00718 // Handle->Decrement(); 00719 // CheckReferenceObject(); 00720 // } 00721 // 00722 // Handle = Other.Handle; 00723 // 00724 // if (Handle) 00725 // Handle->Increment(); 00726 // 00727 // return *this; 00728 // } 00729 // 00730 // bool operator == (const ObjectPtr<T>& Other) const 00731 // { 00732 // if (Handle == Other.Handle) 00733 // { 00734 // return true; 00735 // } 00736 // 00737 // return false; 00738 // } 00739 // 00740 // bool operator == (const T *Ptr) const 00741 // { 00742 // if (Handle == Ptr) 00743 // { 00744 // return true; 00745 // } 00746 // 00747 // return false; 00748 // } 00749 // 00750 // template <typename U> 00751 // bool operator == (const U *Ptr) const 00752 // { 00753 // if (Handle == Ptr) 00754 // { 00755 // return true; 00756 // } 00757 // 00758 // return false; 00759 // } 00760 // 00761 // template <typename U> 00762 // bool operator == (ObjectPtr<U>& Other) const 00763 // { 00764 // if (Handle == Other.Handle) 00765 // { 00766 // return true; 00767 // } 00768 // 00769 // return false; 00770 // } 00771 // 00772 // bool operator != (const ObjectPtr<T>& Other) const 00773 // { 00774 // if (Handle != Other.Handle) 00775 // { 00776 // return true; 00777 // } 00778 // 00779 // return false; 00780 // } 00781 // 00782 // bool operator != (const T *Ptr) const 00783 // { 00784 // if (Handle != Ptr) 00785 // { 00786 // return true; 00787 // } 00788 // 00789 // return false; 00790 // } 00791 // 00792 // template <typename U> 00793 // bool operator != (const U *Ptr) const 00794 // { 00795 // if (Handle != Ptr) 00796 // { 00797 // return true; 00798 // } 00799 // 00800 // return false; 00801 // } 00802 // 00803 // template <typename U> 00804 // bool operator != (ObjectPtr<U>& Other) const 00805 // { 00806 // if (Handle != Other.Handle) 00807 // { 00808 // return true; 00809 // } 00810 // 00811 // return false; 00812 // } 00813 // 00814 // // // This isn't safe. An assignment like the following is wrong, but it will no flag an error at compile time. 00815 // // // ObjectPtr<IOpenGLVertexBuffer> vtx; 00816 // // // ObjectPtr<IOpenGLTexture2D> tex; 00817 // // // vtx = tex; // WRONG 00818 // // 00819 // // template<typename U> 00820 // // ObjectPtr<T>& operator=(const ObjectPtr<U>& Other) 00821 // // { 00822 // // Handle = (T*)(Other.Handle); 00823 // // return *this; 00824 // // } 00825 // 00826 // // Doing vtx = tex.Castref<IOpenGLVertexBuffer> will return a ObjectPtr<IOpenGLVertexBuffer> with a null Handle. 00827 // template<typename U> 00828 // ObjectPtr<U> CastRef() 00829 // { 00830 // ObjectPtr<U> t; 00831 // 00832 // // Check if type U is derived from type T 00833 // if (U::StaticObjectType.IsDerivedFromType (T::StaticObjectType) ) 00834 // { 00835 // t = (U *) Handle; 00836 // } 00837 // 00838 // return t; 00839 // } 00840 // 00841 // void Release() 00842 // { 00843 // if (Handle) 00844 // { 00845 // Handle->Decrement(); 00846 // CheckReferenceObject(); 00847 // } 00848 // 00849 // Handle = 0; 00850 // } 00851 // private: 00852 // T &GetHandle() 00853 // { 00854 // return *Handle; 00855 // } 00856 // 00857 // public: 00858 // bool IsValid() 00859 // { 00860 // if (Handle) 00861 // { 00862 // return true; 00863 // } 00864 // 00865 // return false; 00866 // } 00867 // 00868 // bool IsNull() 00869 // { 00870 // if (Handle) 00871 // { 00872 // return false; 00873 // } 00874 // 00875 // return true; 00876 // } 00877 // }; 00878 00879 } 00880 00881 #endif // GLRESOURCE_H 00882