Back to index

nux  3.0.0
GpuDevice.cpp
Go to the documentation of this file.
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 #include "GLResource.h"
00024 #include "NuxGraphics.h"
00025 #include "GpuDevice.h"
00026 #include "GLDeviceObjects.h"
00027 #include "GLResourceManager.h"
00028 
00029 #include "GLTextureResourceManager.h"
00030 #include "GLVertexResourceManager.h"
00031 #include "GLDeviceFrameBufferObject.h"
00032 #include "GLTemplatePrimitiveBuffer.h"
00033 #include "GraphicsEngine.h"
00034 
00035 namespace nux
00036 {
00037 #if (NUX_ENABLE_CG_SHADERS)
00038   extern void cgErrorCallback(void);
00039 #endif
00040 
00041   typedef struct
00042   {
00043     int major;
00044     int minor;
00045   } OpenGLVersion;
00046 
00047   static OpenGLVersion OpenGLVersionTable [] =
00048   {
00049     {1, 0},
00050     {1, 1},
00051     {1, 2},
00052     {1, 3},
00053     {1, 4},
00054     {2, 0},
00055     {2, 1},
00056     {3, 0},
00057     {3, 1},
00058     {3, 2},
00059     {3, 3},
00060     {4, 0},
00061     {4, 1},
00062     {0, 0}
00063   };
00064 
00065   extern PixelFormatInfo GPixelFormats[];
00066 
00067   static void InitTextureFormats()
00068   {
00069 #ifndef NUX_OPENGLES_20
00070     GPixelFormats[ BITFMT_UNKNOWN         ].PlatformFormat     = GL_NONE;                                              // Not supported for rendering.
00071 
00072     // Data in PC system memory: R(LSB) G B A(MSB) ---> GL Format:GL_RGBA - GL Type:GL_UNSIGNED_INT_8_8_8_8_REV
00073     GPixelFormats[BITFMT_R8G8B8A8].PlatformFormat           = GL_RGBA8;
00074     GPixelFormats[BITFMT_R8G8B8A8].Format             = GL_RGBA;
00075     GPixelFormats[BITFMT_R8G8B8A8].type                 = GL_UNSIGNED_INT_8_8_8_8_REV;
00076 
00077     // Data in PC system memory: A(LSB) B G R(MSB) ---> GL Format:GL_RGBA - GL Type:GL_UNSIGNED_INT_8_8_8_8
00078     GPixelFormats[BITFMT_A8B8G8R8].PlatformFormat           = GL_RGBA8;
00079     GPixelFormats[BITFMT_A8B8G8R8].Format             = GL_RGBA;
00080     GPixelFormats[BITFMT_A8B8G8R8].type                 = GL_UNSIGNED_INT_8_8_8_8;
00081 
00082     // Data in PC system memory: B(LSB) G R A(MSB) ---> GL Format:GL_BGRA - GL Type:GL_UNSIGNED_INT_8_8_8_8_REV
00083     GPixelFormats[BITFMT_B8G8R8A8].PlatformFormat           = GL_RGBA8;
00084     GPixelFormats[BITFMT_B8G8R8A8].Format             = GL_BGRA;
00085     GPixelFormats[BITFMT_B8G8R8A8].type                 = GL_UNSIGNED_INT_8_8_8_8_REV;
00086 
00087     // Data in PC system memory: A(LSB) R G B(MSB) ---> GL Format:GL_BGRA - GL Type:GL_UNSIGNED_INT_8_8_8_8
00088     GPixelFormats[BITFMT_A8R8G8B8].PlatformFormat           = GL_RGBA8;
00089     GPixelFormats[BITFMT_A8R8G8B8].Format             = GL_BGRA;
00090     GPixelFormats[BITFMT_A8R8G8B8].type                 = GL_UNSIGNED_INT_8_8_8_8;
00091 
00092     // Data in PC system memory: R(LSB) G B(MSB) ---> GL Format:GL_RGB - GL Type:GL_UNSIGNED
00093     GPixelFormats[BITFMT_R8G8B8].PlatformFormat        = GL_RGB8;
00094     GPixelFormats[BITFMT_R8G8B8].Format                 = GL_RGB;
00095     GPixelFormats[BITFMT_R8G8B8].type                     = GL_UNSIGNED_BYTE;
00096 
00097     GPixelFormats[BITFMT_B8G8R8].PlatformFormat        = GL_RGB8;
00098     GPixelFormats[BITFMT_B8G8R8].Format                 = GL_BGR;
00099     GPixelFormats[BITFMT_B8G8R8].type                     = GL_UNSIGNED_BYTE;
00100 
00101     GPixelFormats[BITFMT_R5G6B5].PlatformFormat        = GL_RGB5;
00102     GPixelFormats[BITFMT_R5G6B5].Format                 = GL_RGB;
00103     GPixelFormats[BITFMT_R5G6B5].type                     = GL_UNSIGNED_SHORT_5_6_5;
00104 
00105     GPixelFormats[BITFMT_RGBA16F].PlatformFormat     = GL_RGBA16F_ARB;
00106     GPixelFormats[BITFMT_RGBA16F].Format              = GL_RGBA;
00107     GPixelFormats[BITFMT_RGBA16F].type                  = GL_HALF_FLOAT_ARB;
00108 
00109     GPixelFormats[BITFMT_RGB32F].PlatformFormat        = GL_RGB;
00110     GPixelFormats[BITFMT_RGB32F].Format                 = GL_RGB;
00111     GPixelFormats[BITFMT_RGB32F].type                     = GL_FLOAT;
00112 
00113     GPixelFormats[BITFMT_RGBA32F].PlatformFormat     = GL_RGBA32F_ARB;
00114     GPixelFormats[BITFMT_RGBA32F].Format              = GL_RGBA;
00115     GPixelFormats[BITFMT_RGBA32F].type                  = GL_FLOAT;
00116 
00117     // Note: Using GL_DEPTH_COMPONENT24 or GL_DEPTH_COMPONENT for PlatformFormat generate error GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT.
00118     GPixelFormats[BITFMT_D24S8].PlatformFormat         = GL_DEPTH24_STENCIL8_EXT;
00119     GPixelFormats[BITFMT_D24S8].Format                  = GL_DEPTH_STENCIL_EXT;     // or GL_DEPTH_STENCIL_NV;
00120     GPixelFormats[BITFMT_D24S8].type                      = GL_UNSIGNED_INT_24_8_EXT; // or GL_UNSIGNED_INT_24_8_NV;
00121 
00122     GPixelFormats[BITFMT_DXT1].PlatformFormat            = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
00123     GPixelFormats[BITFMT_DXT2].PlatformFormat            = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
00124     GPixelFormats[BITFMT_DXT3].PlatformFormat            = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
00125     GPixelFormats[BITFMT_DXT4].PlatformFormat            = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
00126     GPixelFormats[BITFMT_DXT5].PlatformFormat            = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
00127 
00128     GPixelFormats[BITFMT_R10G10B10A2].PlatformFormat    = GL_RGB10_A2;
00129     GPixelFormats[BITFMT_R10G10B10A2].Format             = GL_RGBA;
00130     GPixelFormats[BITFMT_R10G10B10A2].type                 = GL_UNSIGNED_INT_10_10_10_2;
00131 
00132     GPixelFormats[BITFMT_A2B10G10R10].PlatformFormat    = GL_RGB10_A2;
00133     GPixelFormats[BITFMT_A2B10G10R10].Format             = GL_RGBA;
00134     GPixelFormats[BITFMT_A2B10G10R10].type                 = GL_UNSIGNED_INT_2_10_10_10_REV;
00135 
00136     GPixelFormats[BITFMT_B10G10R10A2].PlatformFormat    = GL_RGB10_A2;
00137     GPixelFormats[BITFMT_B10G10R10A2].Format             = GL_BGRA;
00138     GPixelFormats[BITFMT_B10G10R10A2].type                 = GL_UNSIGNED_INT_10_10_10_2;
00139 
00140     GPixelFormats[BITFMT_A2R10G10B10].PlatformFormat    = GL_RGB10_A2;
00141     GPixelFormats[BITFMT_A2R10G10B10].Format             = GL_BGRA;
00142     GPixelFormats[BITFMT_A2R10G10B10].type                 = GL_UNSIGNED_INT_2_10_10_10_REV;
00143 
00144     GPixelFormats[BITFMT_A8].PlatformFormat                = GL_RGBA8;
00145     GPixelFormats[BITFMT_A8].Format                         = GL_LUMINANCE;
00146     GPixelFormats[BITFMT_A8].type                      = GL_UNSIGNED_BYTE;
00147 #else
00148     GPixelFormats[ BITFMT_UNKNOWN         ].PlatformFormat     = GL_NONE;                                              // Not supported for rendering.
00149 
00150     // Data in PC system memory: R(LSB) G B A(MSB) ---> GL Format:GL_RGBA - GL Type:GL_UNSIGNED_INT_8_8_8_8_REV
00151     GPixelFormats[BITFMT_R8G8B8A8].PlatformFormat           = GL_RGBA;
00152     GPixelFormats[BITFMT_R8G8B8A8].Format             = GL_RGBA;
00153     GPixelFormats[BITFMT_R8G8B8A8].type                 = GL_UNSIGNED_BYTE;
00154 
00155     // Data in PC system memory: B(LSB) G R A(MSB) ---> GL Format:GL_BGRA - GL Type:GL_UNSIGNED_INT_8_8_8_8_REV
00156     GPixelFormats[BITFMT_B8G8R8A8].PlatformFormat           = GL_BGRA_EXT;
00157     GPixelFormats[BITFMT_B8G8R8A8].Format             = GL_BGRA_EXT;
00158     GPixelFormats[BITFMT_B8G8R8A8].type                 = GL_UNSIGNED_BYTE;
00159 
00160     // Data in PC system memory: R(LSB) G B(MSB) ---> GL Format:GL_RGB - GL Type:GL_UNSIGNED
00161     GPixelFormats[BITFMT_R8G8B8].PlatformFormat        = GL_RGB;
00162     GPixelFormats[BITFMT_R8G8B8].Format                 = GL_RGB;
00163     GPixelFormats[BITFMT_R8G8B8].type                     = GL_UNSIGNED_BYTE;
00164 
00165     GPixelFormats[BITFMT_R5G6B5].PlatformFormat        = GL_RGB;
00166     GPixelFormats[BITFMT_R5G6B5].Format                 = GL_RGB;
00167     GPixelFormats[BITFMT_R5G6B5].type                     = GL_UNSIGNED_SHORT_5_6_5;
00168 
00169     // Note: Using GL_DEPTH_COMPONENT24 or GL_DEPTH_COMPONENT for PlatformFormat generate error GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT.
00170     GPixelFormats[BITFMT_D24S8].PlatformFormat         = GL_DEPTH_STENCIL_OES;
00171     GPixelFormats[BITFMT_D24S8].Format                  = GL_DEPTH_STENCIL_OES;
00172     GPixelFormats[BITFMT_D24S8].type                      = GL_UNSIGNED_INT_24_8_OES;
00173 
00174     GPixelFormats[BITFMT_A8].PlatformFormat                = GL_ALPHA;
00175     GPixelFormats[BITFMT_A8].Format                         = GL_ALPHA;
00176     GPixelFormats[BITFMT_A8].type                      = GL_UNSIGNED_BYTE;
00177 #endif
00178   }
00179 
00180   STREAMSOURCE GpuDevice::_StreamSource[MAX_NUM_STREAM];
00181 
00182   GpuInfo::GpuInfo()
00183   {
00184     _support_opengl_version_11 = false;
00185     _support_opengl_version_12 = false;
00186     _support_opengl_version_13 = false;
00187     _support_opengl_version_14 = false;
00188     _support_opengl_version_15 = false;
00189     _support_opengl_version_20 = false;
00190     _support_opengl_version_21 = false;
00191     _support_opengl_version_30 = false;
00192     _support_opengl_version_31 = false;
00193     _support_opengl_version_32 = false;
00194     _support_opengl_version_33 = false;
00195     _support_opengl_version_40 = false;
00196     _support_opengl_version_41 = false;
00197   }
00198 
00199   void GpuInfo::Setup()
00200   {
00201 #ifndef NUX_OPENGLES_20
00202     _support_opengl_version_11 = GLEW_VERSION_1_1 ? true : false;
00203     _support_opengl_version_12 = GLEW_VERSION_1_2 ? true : false;
00204     _support_opengl_version_13 = GLEW_VERSION_1_3 ? true : false;
00205     _support_opengl_version_14 = GLEW_VERSION_1_4 ? true : false;
00206     _support_opengl_version_15 = GLEW_VERSION_1_5 ? true : false;
00207     _support_opengl_version_20 = GLEW_VERSION_2_0 ? true : false;
00208     _support_opengl_version_21 = GLEW_VERSION_2_1 ? true : false;
00209     _support_opengl_version_30 = GLEW_VERSION_3_0 ? true : false;
00210     _support_opengl_version_31 = GLEW_VERSION_3_1 ? true : false;
00211     _support_opengl_version_32 = GLEW_VERSION_3_2 ? true : false;
00212 //     _support_opengl_version_33 = GLEW_VERSION_3_3 ? true : false;
00213 //     _support_opengl_version_40 = GLEW_VERSION_4_0 ? true : false;
00214 //     _support_opengl_version_41 = GLEW_VERSION_4_1 ? true : false;
00215 
00216     // See: http://developer.nvidia.com/object/General_FAQ.html
00217     // The value of GL_MAX_TEXTURE_UNITS is 4 for GeForce FX and GeForce 6 Series GPUs. Why is that, since those GPUs have 16 texture units?
00218     CHECKGL(glGetIntegerv(GL_MAX_TEXTURE_UNITS, &_opengl_max_texture_units));
00219     CHECKGL(glGetIntegerv(GL_MAX_TEXTURE_COORDS, &_opengl_max_texture_coords));
00220     CHECKGL(glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &_opengl_max_texture_image_units));
00221     CHECKGL(glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &_opengl_max_vertex_attributes));
00222     CHECKGL(glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &_opengl_max_fb_attachment));
00223 #else
00224     _opengl_max_fb_attachment = 1;
00225 #endif
00226 
00227 #if defined(NUX_OS_WINDOWS)
00228     _support_ext_swap_control                 = WGLEW_EXT_swap_control ? true : false;
00229 #elif defined(NUX_OS_LINUX) && !defined(NUX_OPENGLES_20)
00230     _support_ext_swap_control                 = GLXEW_SGI_swap_control ? true : false;
00231 #endif
00232 
00233 #ifndef NUX_OPENGLES_20
00234     _support_arb_vertex_program               = GLEW_ARB_vertex_program ? true : false;
00235     _support_arb_fragment_program             = GLEW_ARB_fragment_program ? true : false;
00236     _support_ext_framebuffer_object           = GLEW_EXT_framebuffer_object ? true : false;
00237     _support_arb_shader_objects               = GLEW_ARB_shader_objects ? true : false;
00238     _support_arb_vertex_shader                = GLEW_ARB_vertex_shader ? true : false;
00239     _support_arb_fragment_shader              = GLEW_ARB_fragment_shader ? true : false;
00240     _support_arb_vertex_buffer_object         = GLEW_ARB_vertex_buffer_object ? true : false;
00241     _support_arb_texture_non_power_of_two     = GLEW_ARB_texture_non_power_of_two ? true : false;
00242     _support_ext_draw_range_elements          = GLEW_EXT_draw_range_elements ? true : false;
00243     _support_ext_stencil_two_side             = GLEW_EXT_stencil_two_side ? true : false;
00244     _support_ext_texture_rectangle            = GLEW_EXT_texture_rectangle ? true : false;
00245     _support_arb_texture_rectangle            = GLEW_ARB_texture_rectangle ? true : false;
00246     _support_nv_texture_rectangle             = GLEW_NV_texture_rectangle ? true : false;
00247     _support_arb_pixel_buffer_object          = GLEW_ARB_pixel_buffer_object ? true : false;
00248     _support_ext_blend_equation_separate      = GLEW_EXT_blend_equation_separate ? true : false;
00249     _support_ext_texture_srgb                 = GLEW_EXT_texture_sRGB ? true : false;
00250     _support_ext_texture_srgb_decode          = false; //GLEW_EXT_texture_sRGB_decode ? true : false;
00251     _support_ext_framebuffer_srgb             = GLEW_EXT_framebuffer_sRGB ? true : false;
00252     _support_arb_framebuffer_srgb             = GLEW_ARB_framebuffer_sRGB ? true : false;
00253 #else
00254     _support_arb_vertex_program               = false;
00255     _support_arb_fragment_program             = false;
00256     _support_arb_shader_objects               = true;
00257     _support_arb_vertex_shader                = true;
00258     _support_arb_fragment_shader              = true;
00259     _support_arb_vertex_buffer_object         = true;
00260     _support_arb_texture_non_power_of_two     = true;
00261     _support_ext_framebuffer_object           = true;
00262     _support_ext_draw_range_elements          = false;
00263     _support_ext_stencil_two_side             = false;
00264     _support_ext_texture_rectangle            = false;
00265     _support_arb_texture_rectangle            = false;
00266     _support_nv_texture_rectangle             = false;
00267     _support_arb_pixel_buffer_object          = false;
00268     _support_ext_blend_equation_separate      = true;
00269 #endif
00270   }
00271 
00272 #if defined(NUX_OS_WINDOWS)
00273   GpuDevice::GpuDevice(unsigned int DeviceWidth, unsigned int DeviceHeight, BitmapFormat DeviceFormat,
00274     HDC device_context,
00275     HGLRC &opengl_rendering_context,
00276     int req_opengl_major,
00277     int req_opengl_minor,
00278     bool opengl_es_20)
00279 #elif defined(NUX_OS_LINUX)
00280 #ifdef NUX_OPENGLES_20
00281   GpuDevice::GpuDevice(unsigned int DeviceWidth, unsigned int DeviceHeight, BitmapFormat DeviceFormat,
00282     Display *display,
00283     Window window,
00284     bool has_glx_13_support,
00285     EGLConfig fb_config,
00286     EGLContext &opengl_rendering_context,
00287     int req_opengl_major,
00288     int req_opengl_minor,
00289     bool opengl_es_20)
00290 #else
00291   GpuDevice::GpuDevice(unsigned int DeviceWidth, unsigned int DeviceHeight, BitmapFormat DeviceFormat,
00292     Display *display,
00293     Window window,
00294     bool has_glx_13_support,
00295     GLXFBConfig fb_config,
00296     GLXContext &opengl_rendering_context,
00297     int req_opengl_major,
00298     int req_opengl_minor,
00299     bool opengl_es_20)
00300 #endif
00301 #endif
00302   {
00303     _PixelStoreAlignment  = 4;
00304     _UsePixelBufferObject = false;
00305     _gpu_info             = NULL;
00306     _gpu_brand            = GPU_VENDOR_UNKNOWN;
00307 
00308 #ifndef NUX_OPENGLES_20    
00309     // OpenGL extension initialization
00310     GLenum Glew_Ok = 0;
00311 #ifdef GLEW_MX
00312     Glew_Ok = glewContextInit(glewGetContext());
00313     nuxAssertMsg(Glew_Ok == GLEW_OK, "[GpuDevice::GpuDevice] GL Extensions failed to initialize.");
00314 
00315 #if defined(NUX_OS_WINDOWS)
00316     Glew_Ok = wglewContextInit(wglewGetContext());
00317 #elif defined(NUX_OS_LINUX)
00318     Glew_Ok = glxewContextInit(glxewGetContext());
00319 #elif defined(NUX_OS_MACOSX)
00320     Glew_Ok = glxewContextInit(glxewGetContext());
00321 #endif
00322 
00323     nuxAssertMsg(Glew_Ok == GLEW_OK, "[GpuDevice::GpuDevice] OpenGL Extensions failed to initialize.");
00324 #else
00325     Glew_Ok = glewInit();
00326 #endif
00327 #endif
00328 
00329 #ifndef NUX_OPENGLES_20
00330     _glsl_version_string = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_VERSION)));
00331     CHECKGL_MSG(glGetString(GL_VERSION));
00332 
00333     NString opengl_major;
00334     NString opengl_minor;
00335     char split = '.';
00336     _glsl_version_string.SplitAtFirstOccurenceOf(split, opengl_major, opengl_minor);
00337 
00338     _opengl_major = (char)opengl_major.GetTCharPtr()[0] - '0';
00339     _opengl_minor = (char)opengl_minor.GetTCharPtr()[0] - '0';
00340 
00341     if (_opengl_major >= 3)
00342     {
00343       CHECKGL(glGetIntegerv(GL_MAJOR_VERSION, &_opengl_major));
00344       CHECKGL(glGetIntegerv(GL_MINOR_VERSION, &_opengl_minor));
00345     }
00346 #else
00347     _opengl_major = 2;
00348     _opengl_minor = 0;
00349 #endif
00350 
00351 #if defined(NUX_OS_WINDOWS)
00352     bool opengl_es_context_created = false;
00353     if (((_opengl_major >= 3) && (req_opengl_major >= 3)) || (_opengl_major >= 3) || opengl_es_20)
00354 #elif defined(NUX_OS_LINUX)
00355     //bool opengl_es_context_created = false;
00356     if (has_glx_13_support &&
00357     (((_opengl_major >= 3) && (req_opengl_major >= 3)) ||
00358     ((_opengl_major >= 3) && opengl_es_20)))
00359 #endif
00360     {
00361       // Create a new Opengl Rendering Context
00362       bool requested_profile_is_supported = false;
00363       int index = 0;
00364       for (index = 0; OpenGLVersionTable [index].major != 0; index++)
00365       {
00366         if ((OpenGLVersionTable[index].major == req_opengl_major) &&
00367           (OpenGLVersionTable[index].minor == req_opengl_minor))
00368         {
00369           if (_opengl_major == 1)
00370           {
00371             if ((req_opengl_major == 1) && (req_opengl_minor >= 0) && (req_opengl_minor <= 5))
00372               requested_profile_is_supported = true;
00373           }
00374           else if (_opengl_major == 2)
00375           {
00376             if ((req_opengl_major == 2) && (req_opengl_minor >= 0) && (req_opengl_minor <= 1))
00377               requested_profile_is_supported = true;
00378           }
00379           else if (_opengl_major == 3)
00380           {
00381             if ((req_opengl_major == 3) && (req_opengl_minor >= 0) && (req_opengl_minor <= 3))
00382               requested_profile_is_supported = true;
00383           }
00384           else if (_opengl_major == 4)
00385           {
00386             if ((req_opengl_major == 4) && (req_opengl_minor >= 0) && (req_opengl_minor <= 1))
00387               requested_profile_is_supported = true;
00388           }
00389           break;
00390         }
00391       }
00392 
00393       if (opengl_es_20)
00394       {
00395 #if defined(NUX_OS_WINDOWS)
00396         int attribs[] =
00397         {
00398           WGL_CONTEXT_MAJOR_VERSION_ARB,  2,
00399           WGL_CONTEXT_MINOR_VERSION_ARB,  0,
00400           WGL_CONTEXT_PROFILE_MASK_ARB,   //WGL_CONTEXT_ES2_PROFILE_BIT_EXT,
00401           0
00402         };
00403 
00404         HGLRC new_opengl_rendering_context = wglCreateContextAttribsARB(device_context,0, attribs);
00405 
00406         if (new_opengl_rendering_context == 0)
00407         {
00408           nuxDebugMsg("[GpuDevice::GpuDevice] OpenGL ES 2.0 context creation has failed.");
00409         }
00410         else
00411         {
00412           wglMakeCurrent(NULL, NULL);
00413           wglDeleteContext(opengl_rendering_context);
00414           opengl_rendering_context = new_opengl_rendering_context;
00415           wglMakeCurrent(device_context, opengl_rendering_context);
00416           opengl_es_context_created = true;
00417         }
00418 #elif defined(NUX_OS_LINUX)
00419 /*        int attribs[] =
00420         {
00421           GLX_CONTEXT_MAJOR_VERSION_ARB,  2,
00422           GLX_CONTEXT_MINOR_VERSION_ARB,  0,
00423           //GLX_CONTEXT_PROFILE_MASK_ARB,   GLX_CONTEXT_ES2_PROFILE_BIT_EXT,
00424           0
00425         };
00426 
00427         GLXContext new_opengl_rendering_context = glXCreateContextAttribsARB(display, fb_config, 0, true, attribs);
00428 
00429         if (new_opengl_rendering_context == 0)
00430         {
00431           nuxDebugMsg("[GpuDevice::GpuDevice] OpenGL ES 2.0 context creation has failed.");
00432         }
00433         else
00434         {
00435           opengl_rendering_context = new_opengl_rendering_context;
00436           glXMakeCurrent(display, window, opengl_rendering_context);
00437           opengl_es_context_created = true;
00438         }*/
00439 #endif
00440       }
00441       else if (requested_profile_is_supported)
00442       {
00443         int profile_mask = 0;
00444         int profile_value = 0;
00445         int flag_mask = 0;
00446         int flag_value = 0;
00447 
00448 #if defined(NUX_OS_WINDOWS)
00449         if (((req_opengl_major == 3) && (req_opengl_minor >= 3)) || (req_opengl_major >= 4))
00450         {
00451           profile_mask = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
00452           profile_value = WGL_CONTEXT_PROFILE_MASK_ARB;
00453           flag_mask = WGL_CONTEXT_FLAGS_ARB;
00454           flag_value = 0;
00455         }
00456 
00457         int attribs[] =
00458         {
00459           WGL_CONTEXT_MAJOR_VERSION_ARB,  req_opengl_major,
00460           WGL_CONTEXT_MINOR_VERSION_ARB,  req_opengl_minor,
00461           profile_mask,                   profile_value,
00462           flag_mask,                      flag_value,
00463           0
00464         };
00465 
00466         HGLRC new_opengl_rendering_context = wglCreateContextAttribsARB(device_context,0, attribs);
00467 
00468         if (new_opengl_rendering_context == 0)
00469         {
00470           nuxDebugMsg("[GpuDevice::GpuDevice] OpenGL version %d.%d context creation has failed.", req_opengl_major, req_opengl_minor);
00471         }
00472         else
00473         {
00474           wglMakeCurrent(NULL, NULL);
00475           wglDeleteContext(opengl_rendering_context);
00476           opengl_rendering_context = new_opengl_rendering_context;
00477           wglMakeCurrent(device_context, opengl_rendering_context);
00478         }
00479 #elif defined(NUX_OS_LINUX) && !defined(NUX_OPENGLES_20)
00480         if (((req_opengl_major == 3) && (req_opengl_minor >= 3)) || (req_opengl_major >= 4))
00481         {
00482           profile_mask  = GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
00483           profile_value = GLX_CONTEXT_PROFILE_MASK_ARB;
00484           flag_mask     = GLX_CONTEXT_FLAGS_ARB;
00485           flag_value    = 0;
00486         }
00487 
00488         int attribs[] =
00489         {
00490           GLX_CONTEXT_MAJOR_VERSION_ARB,  req_opengl_major,
00491           GLX_CONTEXT_MINOR_VERSION_ARB,  req_opengl_minor,
00492           profile_mask,                   profile_value,
00493           flag_mask,                      flag_value,
00494           0
00495         };
00496 
00497         GLXContext new_opengl_rendering_context = glXCreateContextAttribsARB(display, fb_config, 0, true, attribs);
00498 
00499         if (new_opengl_rendering_context == 0)
00500         {
00501           nuxDebugMsg("[GpuDevice::GpuDevice] OpenGL version %d.%d context creation has failed.", req_opengl_major, req_opengl_minor);
00502           attribs[0] = 1; // major version
00503           attribs[1] = 0; // minor version
00504           attribs[2] = 0;
00505           new_opengl_rendering_context = glXCreateContextAttribsARB(display, fb_config, 0, true, attribs);
00506 
00507           opengl_rendering_context = new_opengl_rendering_context;
00508           glXMakeCurrent(display, window, opengl_rendering_context);
00509         }
00510         else
00511         {
00512           opengl_rendering_context = new_opengl_rendering_context;
00513           glXMakeCurrent(display, window, opengl_rendering_context);
00514         }
00515 #endif
00516       }
00517       else
00518       {
00519         nuxDebugMsg("[GpuDevice::GpuDevice] Using highest default OpenGL version.");
00520       }
00521     }
00522 
00523     _board_vendor_string = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_VENDOR)));
00524     CHECKGL_MSG(glGetString(GL_VENDOR));
00525     _board_renderer_string = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_RENDERER)));
00526     CHECKGL_MSG(glGetString(GL_RENDERER));
00527     _openGL_version_string = ANSI_TO_TCHAR(NUX_REINTERPRET_CAST(const char *, glGetString(GL_VERSION)));
00528     CHECKGL_MSG(glGetString(GL_VERSION));
00529 
00530     nuxDebugMsg("Gpu Vendor: %s", _board_vendor_string.GetTCharPtr());
00531     nuxDebugMsg("Gpu Renderer: %s", _board_renderer_string.GetTCharPtr());
00532     nuxDebugMsg("Gpu OpenGL Version: %s", _openGL_version_string.GetTCharPtr());
00533     nuxDebugMsg("Gpu OpenGL Major Version: %d", _opengl_major);
00534     nuxDebugMsg("Gpu OpenGL Minor Version: %d", _opengl_minor);
00535     nuxDebugMsg("Gpu GLSL Version: %s", _glsl_version_string.GetTCharPtr());
00536 
00537     NString TempStr = (const char *) TCharToUpperCase(_board_vendor_string.GetTCharPtr());
00538 
00539     if (TempStr.FindFirstOccurence("NVIDIA") != tstring::npos)
00540     {
00541       _gpu_brand = GPU_BRAND_NVIDIA;
00542     }
00543     else if (TempStr.FindFirstOccurence("ATI") != tstring::npos)
00544     {
00545       _gpu_brand = GPU_BRAND_AMD;
00546     }
00547     else if (TempStr.FindFirstOccurence("TUNGSTEN") != tstring::npos)
00548     {
00549       _gpu_brand = GPU_BRAND_INTEL;
00550     }
00551 
00552     if (0)
00553     {
00554       if (GetGPUBrand() == GPU_BRAND_AMD)
00555         _UsePixelBufferObject = false;
00556       else
00557         _UsePixelBufferObject = true;
00558     }
00559     else
00560     {
00561       _UsePixelBufferObject = false;
00562     }
00563 
00564     _gpu_info = new GpuInfo();
00565     _gpu_info->Setup();
00566     _gpu_render_states = new GpuRenderStates(_gpu_brand, _gpu_info);
00567 
00568 #if defined(NUX_OS_WINDOWS)
00569     OGL_EXT_SWAP_CONTROL                = WGLEW_EXT_swap_control ? true : false;
00570 #elif defined(NUX_OS_LINUX) && !defined(NUX_OPENGLES_20)
00571     OGL_EXT_SWAP_CONTROL                = GLXEW_SGI_swap_control ? true : false;
00572 #endif
00573 
00574     InitTextureFormats();
00575 
00576     // See Avoiding 16 Common OpenGL Pitfalls
00577     // 7. Watch Your Pixel Store Alignment
00578     // http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/
00579     // We use a pack /unpack alignment to 1 so we don't have any padding at the end of row.
00580 
00581     CHECKGL(glPixelStorei(GL_UNPACK_ALIGNMENT, _PixelStoreAlignment));
00582     CHECKGL(glPixelStorei(GL_PACK_ALIGNMENT, _PixelStoreAlignment));
00583 
00584 //     _DeviceWidth = DeviceWidth;
00585 //     _DeviceHeight = DeviceHeight;
00586 // 
00587 //     _ViewportX = 0;
00588 //     _ViewportY = 0;
00589 //     _ViewportWidth = DeviceWidth;
00590 //     _ViewportHeight = DeviceHeight;
00591 
00592     for (int i = 0; i < MAX_NUM_STREAM; i++)
00593     {
00594       _StreamSource[i].ResetStreamSource();
00595     }
00596 
00597     // Configure NVidia CG
00598 #if (NUX_ENABLE_CG_SHADERS)
00599     {
00600       m_Cgcontext = 0;
00601 
00602       // Create Cg context and set profile.
00603       CHECKGL(cgSetErrorCallback( cgErrorCallback ));
00604       m_Cgcontext = cgCreateContext();
00605       nuxAssert(m_Cgcontext);
00606       //CHECKGL(cgGLEnableProfile( CG_PROFILE_VP40 ));
00607       //CHECKGL(cgGLEnableProfile( CG_PROFILE_FP40 ));
00608       CHECKGL(cgGLSetManageTextureParameters( m_Cgcontext, CG_FALSE ));
00609     }
00610 #endif
00611 
00612     if (GetGpuInfo().Support_EXT_Framebuffer_Object())
00613     {
00614       _FrameBufferObject = CreateFrameBufferObject();
00615       _FrameBufferObject->Deactivate();
00616     }
00617   }
00618 
00619   GpuDevice::~GpuDevice()
00620   {
00621     NUX_SAFE_DELETE(_gpu_info);
00622     NUX_SAFE_DELETE(_gpu_render_states);
00623 
00624     _FrameBufferObject.Release();
00625     _CurrentFrameBufferObject.Release();
00626 
00627     _PixelBufferArray.clear();
00628 
00629     for (int i = 0; i < MAX_NUM_STREAM; i++)
00630     {
00631       _StreamSource[i].ResetStreamSource();
00632     }
00633     // NVidia CG
00634 #if (NUX_ENABLE_CG_SHADERS)
00635     cgDestroyContext(m_Cgcontext);
00636 #endif
00637 
00638   }
00639 
00640   ObjectPtr<IOpenGLFrameBufferObject> GpuDevice::CreateFrameBufferObject()
00641   {
00642     IOpenGLFrameBufferObject *ptr;
00643     CreateFrameBufferObject((IOpenGLFrameBufferObject **) &ptr);
00644     ObjectPtr<IOpenGLFrameBufferObject> h = ObjectPtr<IOpenGLFrameBufferObject> (ptr);
00645     ptr->UnReference();
00646     return h;
00647   }
00648 
00649   int GpuDevice::CreateFrameBufferObject(IOpenGLFrameBufferObject **ppFrameBufferObject)
00650   {
00651     *ppFrameBufferObject = new IOpenGLFrameBufferObject(NUX_TRACKER_LOCATION);
00652 
00653     return OGL_OK;
00654   }
00655 
00656   int GpuDevice::GetOpenGLMajorVersion() const
00657   {
00658     return _opengl_major;
00659   }
00660 
00661   int GpuDevice::GetOpenGLMinorVersion() const
00662   {
00663     return _opengl_minor;
00664   }
00665 
00666   GpuBrand GpuDevice::GetGPUBrand() const
00667   {
00668     return _gpu_brand;
00669   }
00670 
00671   GpuRenderStates &GpuDevice::GetRenderStates()
00672   {
00673     return *_gpu_render_states;
00674   }
00675 
00676   GpuInfo &GpuDevice::GetGpuInfo()
00677   {
00678     return *_gpu_info;
00679   }
00680 
00681   void GpuDevice::ResetRenderStates()
00682   {
00683     _gpu_render_states->ResetStateChangeToDefault();
00684   }
00685 
00686   void GpuDevice::VerifyRenderStates()
00687   {
00688     _gpu_render_states->CheckStateChange();
00689   }
00690 
00691   void GpuDevice::InvalidateTextureUnit(int TextureUnitIndex)
00692   {
00693     CHECKGL(glActiveTextureARB(TextureUnitIndex));
00694 
00695     CHECKGL(glBindTexture(GL_TEXTURE_2D, 0));
00696 #ifndef NUX_OPENGLES_20
00697     CHECKGL(glBindTexture(GL_TEXTURE_1D, 0));
00698     CHECKGL(glBindTexture(GL_TEXTURE_CUBE_MAP, 0));
00699     CHECKGL(glBindTexture(GL_TEXTURE_3D, 0));
00700     CHECKGL(glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0));
00701 #endif
00702 
00703     // From lowest priority to highest priority:
00704     //      GL_TEXTURE_1D,
00705     //      GL_TEXTURE_2D,
00706     //      GL_TEXTURE_RECTANGLE_ARB,
00707     //      GL_TEXTURE_3D,
00708     //      GL_TEXTURE_CUBE_MAP.
00709 
00710 #ifndef NUX_OPENGLES_20
00711     CHECKGL(glDisable(GL_TEXTURE_2D));
00712     CHECKGL(glDisable(GL_TEXTURE_1D));
00713     CHECKGL(glDisable(GL_TEXTURE_RECTANGLE_ARB));
00714     CHECKGL(glDisable(GL_TEXTURE_3D));
00715     CHECKGL(glDisable(GL_TEXTURE_CUBE_MAP));
00716 #endif
00717   }
00718 
00719   int GpuDevice::AllocateUnpackPixelBufferIndex(int *index)
00720   {
00721     unsigned int num = (unsigned int) _PixelBufferArray.size();
00722 
00723     for (unsigned int i = 0; i < num; i++)
00724     {
00725       if (_PixelBufferArray[i].IsReserved == FALSE)
00726       {
00727         _PixelBufferArray[i].IsReserved = TRUE;
00728         *index = i;
00729         return OGL_OK;
00730       }
00731     }
00732 
00733     // Not enough free pbo
00734     PixelBufferObject pbo;
00735     pbo.PBO = CreatePixelBufferObject(4, (VBO_USAGE) GL_STATIC_DRAW);
00736     pbo.IsReserved = TRUE;
00737     _PixelBufferArray.push_back(pbo);
00738     *index = (int) _PixelBufferArray.size() - 1;
00739     return OGL_OK;
00740   }
00741 
00742   int GpuDevice::FreeUnpackPixelBufferIndex(const int index)
00743   {
00744     int num = (int) _PixelBufferArray.size();
00745     nuxAssertMsg((index >= 0) && (index < num), "[GpuDevice::FreeUnpackPixelBufferIndex] Trying to Free a pixel buffer index that does not exist.");
00746 
00747     if ((index < 0) || (index >= num))
00748     {
00749       return OGL_ERROR;
00750     }
00751 
00752     _PixelBufferArray[index].IsReserved = false;
00753 
00754 // //     if (0)
00755 // //     {
00756 // //         // Can we realloc the memory used by the buffer with much less memory(4x4bytes)???
00757 // //         CHECKGL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, OpenGLID));
00758 // //         CHECKGL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, 4*4, NULL, GL_STREAM_DRAW_ARB));
00759 // //     }
00760     return OGL_OK;
00761   }
00762 
00763   void *GpuDevice::LockUnpackPixelBufferIndex(const int index, int Size)
00764   {
00765 #ifndef NUX_OPENGLES_20
00766     BindUnpackPixelBufferIndex(index);
00767     CHECKGL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, Size, NULL, GL_STREAM_DRAW));
00768     void *pBits = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
00769     CHECKGL_MSG(glMapBufferARB );
00770     CHECKGL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
00771     return pBits;
00772 #else
00773        return NULL;
00774 #endif
00775   }
00776 
00777   void* GpuDevice::LockPackPixelBufferIndex(const int index, int Size)
00778   {
00779 #ifndef NUX_OPENGLES_20
00780     BindPackPixelBufferIndex(index);
00781     CHECKGL(glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, Size, NULL, GL_STREAM_DRAW));
00782     void *pBits = glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
00783     CHECKGL_MSG(glMapBufferARB );
00784     CHECKGL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
00785     return pBits;
00786 #else
00787        return NULL;
00788 #endif
00789   }
00790 
00791   void GpuDevice::UnlockUnpackPixelBufferIndex(const int index)
00792   {
00793 #ifndef NUX_OPENGLES_20
00794     BindUnpackPixelBufferIndex(index);
00795     CHECKGL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
00796     CHECKGL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
00797 #endif
00798   }
00799 
00800   void GpuDevice::UnlockPackPixelBufferIndex(const int index)
00801   {
00802 #ifndef NUX_OPENGLES_20
00803     BindPackPixelBufferIndex(index);
00804     CHECKGL(glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB));
00805     CHECKGL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
00806 #endif
00807   }
00808 
00809   int GpuDevice::BindUnpackPixelBufferIndex(const int index)
00810   {
00811     int num = (int) _PixelBufferArray.size();
00812     nuxAssertMsg((index >= 0) && (index < num), "[GpuDevice::BindUnpackPixelBufferIndex] Trying to bind an invalid pixel buffer index.");
00813 
00814     if ((index < 0) || (index >= num))
00815     {
00816       return OGL_ERROR;
00817     }
00818 
00819     nuxAssertMsg(_PixelBufferArray[index].IsReserved == true, "[GpuDevice::BindUnpackPixelBufferIndex] Trying to reserved pixel buffer index.");
00820 
00821     if (_PixelBufferArray[index].IsReserved == false)
00822     {
00823       return OGL_ERROR;
00824     }
00825 
00826     _PixelBufferArray[index].PBO->BindUnpackPixelBufferObject();
00827     return OGL_OK;
00828   }
00829 
00830   int GpuDevice::BindPackPixelBufferIndex(const int index)
00831   {
00832     int num = (int) _PixelBufferArray.size();
00833     nuxAssertMsg((index >= 0) && (index < num), "[GpuDevice::BindPackPixelBufferIndex] Trying to bind an invalid pixel buffer index.");
00834 
00835     if ((index < 0) || (index >= num))
00836     {
00837       return OGL_ERROR;
00838     }
00839 
00840     nuxAssertMsg(_PixelBufferArray[index].IsReserved == true, "[GpuDevice::BindPackPixelBufferIndex] Trying to reserved pixel buffer index.");
00841 
00842     if (_PixelBufferArray[index].IsReserved == false)
00843     {
00844       return OGL_ERROR;
00845     }
00846 
00847     _PixelBufferArray[index].PBO->BindPackPixelBufferObject();
00848     return OGL_OK;
00849   }
00850 
00851   int GpuDevice::FormatFrameBufferObject(unsigned int Width, unsigned int Height, BitmapFormat PixelFormat)
00852   {
00853     if (!GetGpuInfo().Support_EXT_Framebuffer_Object())
00854     {
00855       nuxDebugMsg("[GpuDevice::FormatFrameBufferObject] No support for OpenGL framebuffer extension.");
00856       return 0;
00857     }
00858 
00859     return _FrameBufferObject->FormatFrameBufferObject(Width, Height, PixelFormat);
00860   }
00861 
00862   int GpuDevice::SetColorRenderTargetSurface(unsigned int ColorAttachmentIndex, ObjectPtr<IOpenGLSurface> pRenderTargetSurface)
00863   {
00864     if (!GetGpuInfo().Support_EXT_Framebuffer_Object())
00865     {
00866       nuxDebugMsg("[GpuDevice::SetColorRenderTargetSurface] No support for OpenGL framebuffer extension.");
00867       return 0;
00868     }
00869 
00870     return _FrameBufferObject->SetRenderTarget(ColorAttachmentIndex, pRenderTargetSurface);
00871   }
00872 
00873   int GpuDevice::SetDepthRenderTargetSurface(ObjectPtr<IOpenGLSurface> pDepthSurface)
00874   {
00875     if (!GetGpuInfo().Support_EXT_Framebuffer_Object())
00876     {
00877       nuxDebugMsg("[GpuDevice::SetDepthRenderTargetSurface] No support for OpenGL framebuffer extension.");
00878       return 0;
00879     }
00880 
00881     return _FrameBufferObject->SetDepthSurface(pDepthSurface);
00882   }
00883 
00884   ObjectPtr<IOpenGLSurface> GpuDevice::GetColorRenderTargetSurface(unsigned int ColorAttachmentIndex)
00885   {
00886     if (!GetGpuInfo().Support_EXT_Framebuffer_Object())
00887     {
00888       nuxDebugMsg("[GpuDevice::GetColorRenderTargetSurface] No support for OpenGL framebuffer extension.");
00889       return ObjectPtr<IOpenGLSurface> (0);
00890     }
00891 
00892     return _FrameBufferObject->GetRenderTarget(ColorAttachmentIndex);
00893   }
00894 
00895   ObjectPtr<IOpenGLSurface> GpuDevice::GetDepthRenderTargetSurface()
00896   {
00897     if (!GetGpuInfo().Support_EXT_Framebuffer_Object())
00898     {
00899       nuxDebugMsg("[GpuDevice::GetDepthRenderTargetSurface] No support for OpenGL framebuffer extension.");
00900       return ObjectPtr<IOpenGLSurface> (0);
00901     }
00902 
00903     return _FrameBufferObject->GetDepthRenderTarget();
00904   }
00905 
00906   void GpuDevice::ActivateFrameBuffer()
00907   {
00908     if (!GetGpuInfo().Support_EXT_Framebuffer_Object())
00909     {
00910       nuxDebugMsg("[GpuDevice::ActivateFrameBuffer] No support for OpenGL framebuffer extension.");
00911       return;
00912     }
00913 
00914     _FrameBufferObject->Activate();
00915   }
00916 
00917   void GpuDevice::SetCurrentFrameBufferObject(ObjectPtr<IOpenGLFrameBufferObject> fbo)
00918   {
00919     _CurrentFrameBufferObject = fbo;
00920   }
00921 
00922   ObjectPtr<IOpenGLFrameBufferObject> GpuDevice::GetCurrentFrameBufferObject()
00923   {
00924     return _CurrentFrameBufferObject;
00925   }
00926 
00927   void GpuDevice::DeactivateFrameBuffer()
00928   {
00929     if (!GetGpuInfo().Support_EXT_Framebuffer_Object())
00930     {
00931       nuxDebugMsg("[GpuDevice::DeactivateFrameBuffer] No support for OpenGL framebuffer extension.");
00932       return;
00933     }
00934 
00935     _CurrentFrameBufferObject.Release();
00936     CHECKGL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
00937     CHECKGL(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0));
00938   }
00939 
00940   ObjectPtr<IOpenGLBaseTexture> GpuDevice::CreateSystemCapableDeviceTexture(
00941     int Width
00942     , int Height
00943     , int Levels
00944     , BitmapFormat PixelFormat
00945     , NUX_FILE_LINE_DECL)
00946   {
00947     if (GetGpuInfo().Support_ARB_Texture_Non_Power_Of_Two())
00948     {
00949       return CreateTexture(Width, Height, Levels, PixelFormat, NUX_FILE_LINE_PARAM);
00950     }
00951 
00952     if (GetGpuInfo().Support_EXT_Texture_Rectangle() || GetGpuInfo().Support_ARB_Texture_Rectangle())
00953     {
00954       return CreateRectangleTexture(Width, Height, Levels, PixelFormat, NUX_FILE_LINE_PARAM);
00955     }
00956 
00957     nuxAssertMsg(0, "[NuxGraphicsResources::CreateSystemCapableDeviceTexture] No support for non power of two textures or rectangle textures");
00958 
00959     return ObjectPtr<IOpenGLBaseTexture>();
00960   }
00961 
00962   BaseTexture* GpuDevice::CreateSystemCapableTexture(NUX_FILE_LINE_DECL)
00963   {
00964     if (GetGpuInfo().Support_ARB_Texture_Non_Power_Of_Two())
00965     {
00966       return new Texture2D(NUX_FILE_LINE_PARAM);
00967     }
00968 
00969     if (GetGpuInfo().Support_EXT_Texture_Rectangle() || GetGpuInfo().Support_ARB_Texture_Rectangle())
00970     {
00971       return new TextureRectangle(NUX_FILE_LINE_PARAM);
00972     }
00973 
00974     nuxAssertMsg(0, "[NuxGraphicsResources::CreateSystemCapableTexture] No support for non power of two textures or rectangle textures");
00975 
00976     return 0;
00977   }
00978 }