diff --git a/panda/src/gles2gsg/gles2gsg.h b/panda/src/gles2gsg/gles2gsg.h index d06c160e02..71ac91e594 100644 --- a/panda/src/gles2gsg/gles2gsg.h +++ b/panda/src/gles2gsg/gles2gsg.h @@ -113,6 +113,13 @@ typedef char GLchar; #define GL_R32F GL_R32F_EXT #define GL_RG32F GL_RG32F_EXT #define GL_RGB8 GL_RGB8_OES +#define GL_TEXTURE_COMPARE_FUNC_ARB GL_TEXTURE_COMPARE_FUNC_EXT +#define GL_TEXTURE_COMPARE_MODE_ARB GL_TEXTURE_COMPARE_MODE_EXT +#define GL_COMPARE_R_TO_TEXTURE_ARB GL_COMPARE_REF_TO_TEXTURE_EXT +#define GL_SAMPLER_2D_SHADOW GL_SAMPLER_2D_SHADOW_EXT +#define GL_MAX_DRAW_BUFFERS GL_MAX_DRAW_BUFFERS_NV +#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE +#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE #undef SUPPORT_IMMEDIATE_MODE #define APIENTRY diff --git a/panda/src/glesgsg/glesgsg.h b/panda/src/glesgsg/glesgsg.h index 9a3825c5dd..3282cd4536 100644 --- a/panda/src/glesgsg/glesgsg.h +++ b/panda/src/glesgsg/glesgsg.h @@ -118,6 +118,7 @@ #define GL_ALPHA8 GL_ALPHA8_EXT #define GL_LUMINANCE8 GL_LUMINANCE8_EXT #define GL_LUMINANCE8_ALPHA8 GL_LUMINANCE8_ALPHA8_EXT +#define GL_MAX_VERTEX_UNITS_ARB GL_MAX_VERTEX_UNITS_OES #undef SUPPORT_IMMEDIATE_MODE #define APIENTRY diff --git a/panda/src/glesgsg/panda_esglext.h b/panda/src/glesgsg/panda_esglext.h index 1a9e57e2a5..bb347948cc 100644 --- a/panda/src/glesgsg/panda_esglext.h +++ b/panda/src/glesgsg/panda_esglext.h @@ -1,7 +1,7 @@ #ifndef __panda_esglext_h_ #define __panda_esglext_h_ -/* $Revision$ on $Date$ */ +/* $Revision: 20798 $ on $Date:: 2013-03-07 01:19:34 -0800 #$ */ #ifdef __cplusplus extern "C" { @@ -1055,10 +1055,10 @@ typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC) (GLenum #ifndef GL_EXT_multi_draw_arrays #define GL_EXT_multi_draw_arrays 1 #ifdef GL_GLEXT_PROTOTYPES -GL_API void GL_APIENTRY glMultiDrawArraysEXT (GLenum, GLint *, GLsizei *, GLsizei); +GL_API void GL_APIENTRY glMultiDrawArraysEXT (GLenum, const GLint *, const GLsizei *, GLsizei); GL_API void GL_APIENTRY glMultiDrawElementsEXT (GLenum, const GLsizei *, GLenum, const GLvoid* *, GLsizei); #endif /* GL_GLEXT_PROTOTYPES */ -typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, GLint *first, GLsizei *count, GLsizei primcount); +typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSEXTPROC) (GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount); typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSEXTPROC) (GLenum mode, const GLsizei *count, GLenum type, const GLvoid* *indices, GLsizei primcount); #endif @@ -1275,3 +1275,4 @@ typedef void (GL_APIENTRYP PFNGLENDTILINGQCOMPROC) (GLbitfield preserveMask); #endif #endif /* __glext_h_ */ + diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.I b/panda/src/glstuff/glGraphicsStateGuardian_src.I index 694abd1280..d973269700 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.I +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.I @@ -532,6 +532,7 @@ enable_depth_test(bool val) { } } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::enable_fog // Access: @@ -539,7 +540,6 @@ enable_depth_test(bool val) { //////////////////////////////////////////////////////////////////// INLINE void CLP(GraphicsStateGuardian):: enable_fog(bool val) { -#ifndef OPENGLES_2 if (_fog_enabled != val) { _fog_enabled = val; if (val) { @@ -556,9 +556,10 @@ enable_fog(bool val) { glDisable(GL_FOG); } } -#endif } +#endif +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::enable_alpha_test // Access: @@ -566,7 +567,6 @@ enable_fog(bool val) { //////////////////////////////////////////////////////////////////// INLINE void CLP(GraphicsStateGuardian):: enable_alpha_test(bool val) { -#ifndef OPENGLES_2 if (_alpha_test_enabled != val) { _alpha_test_enabled = val; if (val) { @@ -583,9 +583,8 @@ enable_alpha_test(bool val) { glDisable(GL_ALPHA_TEST); } } -#endif // OPENGLES_2 } - +#endif //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::enable_polygon_offset @@ -645,6 +644,7 @@ clear_color_write_mask() { } } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::call_glFogfv // Access: Public @@ -653,16 +653,16 @@ clear_color_write_mask() { //////////////////////////////////////////////////////////////////// INLINE void CLP(GraphicsStateGuardian):: call_glFogfv(GLenum pname, const LColor &color) { -#ifndef OPENGLES_2 #ifndef STDFLOAT_DOUBLE glFogfv(pname, color.get_data()); #else // STDFLOAT_DOUBLE LColorf fcolor = LCAST(float, color); glFogfv(pname, fcolor.get_data()); #endif // STDFLOAT_DOUBLE -#endif } +#endif +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::call_glMaterialfv // Access: Public @@ -671,16 +671,16 @@ call_glFogfv(GLenum pname, const LColor &color) { //////////////////////////////////////////////////////////////////// INLINE void CLP(GraphicsStateGuardian):: call_glMaterialfv(GLenum face, GLenum pname, const LColor &color) { -#ifndef OPENGLES_2 #ifndef STDFLOAT_DOUBLE glMaterialfv(face, pname, color.get_data()); #else // STDFLOAT_DOUBLE LColorf fcolor = LCAST(float, color); glMaterialfv(face, pname, fcolor.get_data()); #endif // STDFLOAT_DOUBLE -#endif } +#endif +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::call_glLightfv // Access: Public @@ -689,16 +689,16 @@ call_glMaterialfv(GLenum face, GLenum pname, const LColor &color) { //////////////////////////////////////////////////////////////////// INLINE void CLP(GraphicsStateGuardian):: call_glLightfv(GLenum light, GLenum pname, const LVecBase4 &value) { -#ifndef OPENGLES_2 #ifndef STDFLOAT_DOUBLE glLightfv(light, pname, value.get_data()); #else // STDFLOAT_DOUBLE LVecBase4f fvalue = LCAST(float, value); glLightfv(light, pname, fvalue.get_data()); #endif // STDFLOAT_DOUBLE -#endif } +#endif +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::call_glLightfv // Access: Public @@ -707,16 +707,16 @@ call_glLightfv(GLenum light, GLenum pname, const LVecBase4 &value) { //////////////////////////////////////////////////////////////////// INLINE void CLP(GraphicsStateGuardian):: call_glLightfv(GLenum light, GLenum pname, const LVecBase3 &value) { -#ifndef OPENGLES_2 #ifndef STDFLOAT_DOUBLE glLightfv(light, pname, value.get_data()); #else // STDFLOAT_DOUBLE LVecBase3f fvalue = LCAST(float, value); glLightfv(light, pname, fvalue.get_data()); #endif // STDFLOAT_DOUBLE -#endif } +#endif +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::call_glLightModelfv // Access: Public @@ -725,16 +725,16 @@ call_glLightfv(GLenum light, GLenum pname, const LVecBase3 &value) { //////////////////////////////////////////////////////////////////// INLINE void CLP(GraphicsStateGuardian):: call_glLightModelfv(GLenum pname, const LVecBase4 &value) { -#ifndef OPENGLES_2 #ifndef STDFLOAT_DOUBLE glLightModelfv(pname, value.get_data()); #else // STDFLOAT_DOUBLE LVecBase4f fvalue = LCAST(float, value); glLightModelfv(pname, fvalue.get_data()); #endif // STDFLOAT_DOUBLE -#endif // OPENGLES_2 } +#endif +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::call_glTexEnvfv // Access: Public @@ -743,15 +743,14 @@ call_glLightModelfv(GLenum pname, const LVecBase4 &value) { //////////////////////////////////////////////////////////////////// INLINE void CLP(GraphicsStateGuardian):: call_glTexEnvfv(GLenum target, GLenum pname, const LVecBase4 &value) { -#ifndef OPENGLES_2 #ifndef STDFLOAT_DOUBLE glTexEnvfv(target, pname, value.get_data()); #else // STDFLOAT_DOUBLE LVecBase4f fvalue = LCAST(float, value); glTexEnvfv(target, pname, fvalue.get_data()); #endif // STDFLOAT_DOUBLE -#endif } +#endif //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::call_glTexParameterfv @@ -769,6 +768,7 @@ call_glTexParameterfv(GLenum target, GLenum pname, const LVecBase4 &value) { #endif // STDFLOAT_DOUBLE } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::get_light_id // Access: Public @@ -776,13 +776,11 @@ call_glTexParameterfv(GLenum target, GLenum pname, const LVecBase4 &value) { //////////////////////////////////////////////////////////////////// INLINE GLenum CLP(GraphicsStateGuardian):: get_light_id(int index) const { -#ifndef OPENGLES_2 return GL_LIGHT0 + index; -#else - return 0; -#endif } +#endif +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::get_clip_plane_id // Access: Public @@ -790,12 +788,9 @@ get_light_id(int index) const { //////////////////////////////////////////////////////////////////// INLINE GLenum CLP(GraphicsStateGuardian):: get_clip_plane_id(int index) const { -#ifndef OPENGLES_2 return GL_CLIP_PLANE0 + index; -#else - return 0; -#endif } +#endif //////////////////////////////////////////////////////////////////// // Function: CLP(GraphicsStateGuardian)::get_supports_framebuffer_multisample @@ -805,7 +800,7 @@ get_clip_plane_id(int index) const { //////////////////////////////////////////////////////////////////// INLINE bool CLP(GraphicsStateGuardian):: get_supports_framebuffer_multisample() { - return _supports_framebuffer_multisample; + return _supports_framebuffer_multisample; } //////////////////////////////////////////////////////////////////// @@ -816,7 +811,7 @@ get_supports_framebuffer_multisample() { //////////////////////////////////////////////////////////////////// INLINE bool CLP(GraphicsStateGuardian):: get_supports_framebuffer_multisample_coverage_nv() { - return _supports_framebuffer_multisample_coverage_nv; + return _supports_framebuffer_multisample_coverage_nv; } @@ -828,7 +823,7 @@ get_supports_framebuffer_multisample_coverage_nv() { //////////////////////////////////////////////////////////////////// INLINE bool CLP(GraphicsStateGuardian):: get_supports_framebuffer_blit() { - return _supports_framebuffer_blit; + return _supports_framebuffer_blit; } #ifndef NDEBUG diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 7813d9cc2a..5471dfeb87 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -96,6 +96,12 @@ static void APIENTRY null_glPointParameterfv(GLenum, const GLfloat *) { } +#ifdef OPENGLES +// OpenGL ES doesn't support this, period. Might as well macro it. +#define _glDrawRangeElements(mode, start, end, count, type, indices) \ + glDrawElements(mode, count, type, indices) + +#else static void APIENTRY null_glDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices) { @@ -103,6 +109,7 @@ null_glDrawRangeElements(GLenum mode, GLuint start, GLuint end, // glDrawElements() instead. glDrawElements(mode, count, type, indices); } +#endif static void APIENTRY null_glActiveTexture(GLenum gl_texture_stage) { @@ -471,12 +478,14 @@ reset() { _supports_debug = true; _use_object_labels = gl_debug_object_labels; +#ifndef OPENGLES } else if (has_extension("GL_ARB_debug_output")) { _glDebugMessageCallback = (PFNGLDEBUGMESSAGECALLBACKPROC) get_extension_func("glDebugMessageCallbackARB"); _glDebugMessageControl = (PFNGLDEBUGMESSAGECONTROLPROC) get_extension_func("glDebugMessageControlARB"); _supports_debug = true; +#endif } if (_supports_debug) { @@ -520,6 +529,7 @@ reset() { _supports_point_parameters = false; +#ifndef OPENGLES_2 if (is_at_least_gl_version(1, 4)) { _supports_point_parameters = true; _glPointParameterfv = (PFNGLPOINTPARAMETERFVPROC) @@ -542,8 +552,17 @@ reset() { } else { _glPointParameterfv = null_glPointParameterfv; } +#endif // !OPENGLES_2 + +#if defined(OPENGLES_2) + // OpenGL ES 2 doesn't have point sprites. + _supports_point_sprite = false; +#elif defined(OPENGLES_1) + _supports_point_sprite = has_extension("GL_OES_point_sprite"); +#else + _supports_point_sprite = has_extension("GL_ARB_point_sprite"); +#endif - _supports_point_sprite = has_extension("GL_ARB_point_sprite") || has_extension("GL_OES_point_sprite"); if (_supports_point_sprite) { // It appears that the point_sprite extension doesn't support // texture transforms on the generated texture coordinates. How @@ -576,11 +595,12 @@ reset() { get_extension_func("glPrimitiveRestartIndex"); } - // We used to have a case here for GL_NV_primitive_restart, but it - // seems to cause garbled geometry bugs on some drivers. } #endif +#ifdef OPENGLES_2 + _supports_vertex_blend = false; +#else _supports_vertex_blend = has_extension("GL_ARB_vertex_blend"); if (_supports_vertex_blend) { @@ -600,10 +620,13 @@ reset() { _supports_vertex_blend = false; } } +#endif -#ifndef OPENGLES +#ifndef OPENGLES_2 if (_supports_vertex_blend) { +#ifndef OPENGLES glEnable(GL_WEIGHT_SUM_UNITY_ARB); +#endif GLint max_vertex_units = 0; glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &max_vertex_units); @@ -634,7 +657,7 @@ reset() { _supports_matrix_palette = false; } } -#else +#elif defined(OPENGLES_1) if (has_extension("GL_OES_matrix_palette")) { _supports_matrix_palette = true; _glCurrentPaletteMatrix = (PFNGLCURRENTPALETTEMATRIXOESPROC) @@ -684,46 +707,27 @@ reset() { } } - _supports_draw_range_elements = false; +#ifndef OPENGLES + _glDrawRangeElements = null_glDrawRangeElements; if (is_at_least_gl_version(1, 2)) { - _supports_draw_range_elements = true; _glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC) get_extension_func("glDrawRangeElements"); } else if (has_extension("GL_EXT_draw_range_elements")) { - _supports_draw_range_elements = true; _glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC) get_extension_func("glDrawRangeElementsEXT"); } - if (_supports_draw_range_elements) { - if (_glDrawRangeElements == NULL) { - GLCAT.warning() - << "glDrawRangeElements advertised as supported by OpenGL runtime, but could not get pointers to extension functions.\n"; - _supports_draw_range_elements = false; - } - } - if (!_supports_draw_range_elements) { + if (_glDrawRangeElements == NULL) { + GLCAT.warning() + << "glDrawRangeElements advertised as supported by OpenGL runtime, but could not get pointers to extension functions.\n"; _glDrawRangeElements = null_glDrawRangeElements; } - -#ifdef OPENGLES - _supports_depth_texture = has_extension("GL_OES_depth_texture"); - _supports_depth24 = has_extension("GL_OES_depth24"); - _supports_depth32 = has_extension("GL_OES_depth32"); -#else - _supports_depth_texture = - has_extension("GL_ARB_depth_texture") || is_at_least_gl_version(1, 4); #endif - _supports_depth_stencil = false; - if (_supports_depth_texture) { - _supports_depth_stencil = - has_extension("GL_EXT_packed_depth_stencil") || has_extension("GL_OES_packed_depth_stencil"); - } - _supports_3d_texture = false; +#ifndef OPENGLES_1 if (is_at_least_gl_version(1, 2)) { _supports_3d_texture = true; @@ -771,9 +775,11 @@ reset() { _supports_3d_texture = false; } } +#endif // !OPENGLES_1 _supports_tex_storage = false; +#ifndef OPENGLES if (is_at_least_gl_version(4, 2) || has_extension("GL_ARB_texture_storage")) { _supports_tex_storage = true; @@ -784,7 +790,9 @@ reset() { _glTexStorage3D = (PFNGLTEXSTORAGE3DPROC) get_extension_func("glTexStorage3D"); - } else if (has_extension("GL_EXT_texture_storage")) { // GLES case + } else +#endif + if (has_extension("GL_EXT_texture_storage")) { // GLES case _supports_tex_storage = true; _glTexStorage1D = (PFNGLTEXSTORAGE1DPROC) @@ -991,8 +999,12 @@ reset() { (has_extension("GL_EXT_rescale_normal") || is_at_least_gl_version(1, 2)); #endif +#ifdef OPENGLES + _supports_packed_dabc = false; +#else _supports_packed_dabc = /*gl_support_packed_dabc &&*/ has_extension("GL_ARB_vertex_array_bgra") || has_extension("GL_EXT_vertex_array_bgra"); +#endif _supports_multisample = has_extension("GL_ARB_multisample") || is_at_least_gl_version(1, 3); @@ -1004,8 +1016,6 @@ reset() { has_extension("GL_SGIS_generate_mipmap") || is_at_least_gl_version(1, 4) || is_at_least_gles_version(1, 1); #endif - _supports_multitexture = false; - #ifdef OPENGLES _supports_tex_non_pow2 = has_extension("GL_OES_texture_npot"); @@ -1014,8 +1024,8 @@ reset() { has_extension("GL_ARB_texture_non_power_of_two"); #endif -#ifdef OPENGLES_2 // OpenGL ES 2.0 doesn't support multitexturing. - _supports_multitexture = false; +#ifdef OPENGLES_2 + _glActiveTexture = glActiveTexture; #else if (is_at_least_gl_version(1, 3) || is_at_least_gles_version(1, 1)) { _supports_multitexture = true; @@ -1064,6 +1074,8 @@ reset() { get_extension_func("glMultiTexCoord3dARB"); _glMultiTexCoord4d = (PFNGLMULTITEXCOORD4DPROC) get_extension_func("glMultiTexCoord4dARB"); + } else { + _supports_multitexture = false; } if (_supports_multitexture) { @@ -1078,23 +1090,45 @@ reset() { _supports_multitexture = false; } } -#endif if (!_supports_multitexture) { + // Replace with dummy no-op functions. _glActiveTexture = null_glActiveTexture; _glClientActiveTexture = null_glActiveTexture; } +#endif - if (has_extension("GL_ARB_depth_texture")) { +#ifdef OPENGLES + if (has_extension("GL_ANGLE_depth_texture")) { + // This extension provides both depth textures and depth-stencil support. _supports_depth_texture = true; - } + _supports_depth_stencil = true; + } else if (has_extension("GL_OES_depth_texture")) { + _supports_depth_texture = true; + _supports_depth_stencil = has_extension("GL_OES_packed_depth_stencil"); + } + _supports_depth24 = has_extension("GL_OES_depth24"); + _supports_depth32 = has_extension("GL_OES_depth32"); + +#else + _supports_depth_texture = (is_at_least_gl_version(1, 4) || + has_extension("GL_ARB_depth_texture")); +#endif + +#ifdef OPENGLES_2 + if (gl_support_shadow_filter && _supports_depth_texture && + has_extension("GL_EXT_shadow_samplers")) { + _supports_shadow_filter = true; + } +#else if (gl_support_shadow_filter && _supports_depth_texture && has_extension("GL_ARB_shadow") && has_extension("GL_ARB_fragment_program_shadow")) { _supports_shadow_filter = true; } +#endif // Actually, we can't keep forever disabling ARB_shadow on ATI cards, // since they do work correctly now. Maybe there is some feature // level we can check somewhere? @@ -1103,15 +1137,29 @@ reset() { _supports_shadow_filter = false; }*/ +#ifdef OPENGLES_2 + _supports_texture_combine = false; + _supports_texture_saved_result = false; + _supports_texture_dot3 = false; +#else _supports_texture_combine = has_extension("GL_ARB_texture_env_combine") || is_at_least_gl_version(1, 3) || is_at_least_gles_version(1, 1); _supports_texture_saved_result = has_extension("GL_ARB_texture_env_crossbar") || has_extension("GL_OES_texture_env_crossbar") || is_at_least_gl_version(1, 4); _supports_texture_dot3 = has_extension("GL_ARB_texture_env_dot3") || is_at_least_gl_version(1, 3) || is_at_least_gles_version(1, 1); +#endif +#ifdef OPENGLES_2 + _supports_buffers = true; + _glGenBuffers = glGenBuffers; + _glBindBuffer = glBindBuffer; + _glBufferData = glBufferData; + _glBufferSubData = glBufferSubData; + _glDeleteBuffers = glDeleteBuffers; + +#else _supports_buffers = false; - if (is_at_least_gl_version(1, 5) || is_at_least_gles_version(1, 1)) { _supports_buffers = true; @@ -1125,8 +1173,9 @@ reset() { get_extension_func("glBufferSubData"); _glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) get_extension_func("glDeleteBuffers"); - - } else if (has_extension("GL_ARB_vertex_buffer_object")) { + } +#ifndef OPENGLES_1 + else if (has_extension("GL_ARB_vertex_buffer_object")) { _supports_buffers = true; _glGenBuffers = (PFNGLGENBUFFERSPROC) @@ -1140,6 +1189,7 @@ reset() { _glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) get_extension_func("glDeleteBuffersARB"); } +#endif // OPENGLES_1 if (_supports_buffers) { if (_glGenBuffers == NULL || _glBindBuffer == NULL || @@ -1150,6 +1200,7 @@ reset() { _supports_buffers = false; } } +#endif #if defined(HAVE_CG) && !defined(OPENGLES) if (cgGLIsProfileSupported(CG_PROFILE_ARBFP1) && @@ -1385,19 +1436,129 @@ reset() { } #endif + // Check whether we support geometry instancing and instanced vertex attribs. +#if defined(OPENGLES_1) _supports_vertex_attrib_divisor = false; -#ifndef OPENGLES - if (is_at_least_gl_version(3, 3)) { + _supports_geometry_instancing = false; + +#elif defined(OPENGLES_2) + if (has_extension("GL_ANGLE_instanced_arrays")) { + // This extension has both things in one. +#ifdef __EMSCRIPTEN__ + // Work around bug - it doesn't allow ANGLE suffix in getProcAddress. _glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC) get_extension_func("glVertexAttribDivisor"); + _glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC) + get_extension_func("glDrawArraysInstanced"); + _glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC) + get_extension_func("glDrawElementsInstanced"); +#else + _glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC) + get_extension_func("glVertexAttribDivisorANGLE"); + _glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC) + get_extension_func("glDrawArraysInstancedANGLE"); + _glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC) + get_extension_func("glDrawElementsInstancedANGLE"); +#endif _supports_vertex_attrib_divisor = true; + _supports_geometry_instancing = true; + + } else { + // Check separately for geometry instancing and instanced attribs. + if (has_extension("GL_EXT_draw_instanced")) { + _glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC) + get_extension_func("glDrawArraysInstancedEXT"); + _glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC) + get_extension_func("glDrawElementsInstancedEXT"); + _supports_geometry_instancing = true; + + } else if (has_extension("GL_NV_draw_instanced")) { + _glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC) + get_extension_func("glDrawArraysInstancedNV"); + _glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC) + get_extension_func("glDrawElementsInstancedNV"); + _supports_geometry_instancing = true; + + } else { + _supports_geometry_instancing = false; + } + + if (has_extension("GL_EXT_instanced_arrays")) { + _glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC) + get_extension_func("glVertexAttribDivisorEXT"); + _supports_vertex_attrib_divisor = true; + + } else if (has_extension("GL_NV_instanced_arrays")) { + _glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC) + get_extension_func("glVertexAttribDivisorNV"); + _supports_vertex_attrib_divisor = true; + + } else { + _supports_vertex_attrib_divisor = false; + } + } + +#else + if (is_at_least_gl_version(3, 3)) { + // This feature is in OpenGL core as of 3.3. + _glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC) + get_extension_func("glVertexAttribDivisor"); + _supports_vertex_attrib_divisor = true; } else if (has_extension("GL_ARB_instanced_arrays")) { _glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORPROC) get_extension_func("glVertexAttribDivisorARB"); - _supports_vertex_attrib_divisor = true; + + } else { + _supports_vertex_attrib_divisor = false; + } + + // Some drivers expose one extension, some expose the other. + if (is_at_least_gl_version(3, 1)) { + _glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC) + get_extension_func("glDrawArraysInstanced"); + _glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC) + get_extension_func("glDrawElementsInstanced"); + _supports_geometry_instancing = true; + + } else if (has_extension("GL_ARB_draw_instanced")) { + _glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC) + get_extension_func("glDrawArraysInstancedARB"); + _glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC) + get_extension_func("glDrawElementsInstancedARB"); + _supports_geometry_instancing = true; + + } else if (has_extension("GL_EXT_draw_instanced")) { + _glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC) + get_extension_func("glDrawArraysInstancedEXT"); + _glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC) + get_extension_func("glDrawElementsInstancedEXT"); + _supports_geometry_instancing = true; + + } else { + _glDrawElementsInstanced = 0; + _glDrawArraysInstanced = 0; + _supports_geometry_instancing = false; + } +#endif + +#ifndef OPENGLES_1 + if (_supports_geometry_instancing) { + if (_glDrawArraysInstanced == NULL || _glDrawElementsInstanced == NULL) { + GLCAT.warning() + << "Geometry instancing advertised as supported by OpenGL runtime, but could not get pointers to extension functions.\n"; + _supports_geometry_instancing = false; + } + } + + if (_supports_vertex_attrib_divisor) { + if (_glVertexAttribDivisor == NULL) { + GLCAT.warning() + << "Instanced vertex arrays advertised as supported by OpenGL runtime, but could not get pointers to extension functions.\n"; + _supports_vertex_attrib_divisor = false; + } } #endif @@ -1506,43 +1667,67 @@ reset() { get_extension_func("glRenderbufferStorageMultisampleEXT"); } +#ifndef OPENGLES _supports_framebuffer_multisample_coverage_nv = false; if ( has_extension("GL_NV_framebuffer_multisample_coverage") ) { _supports_framebuffer_multisample_coverage_nv = true; _glRenderbufferStorageMultisampleCoverage = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLECOVERAGENVPROC) get_extension_func("glRenderbufferStorageMultisampleCoverageNV"); } +#endif +#ifndef OPENGLES_1 _supports_framebuffer_blit = false; if ( has_extension("GL_EXT_framebuffer_blit") ) { _supports_framebuffer_blit = true; _glBlitFramebuffer = (PFNGLBLITFRAMEBUFFEREXTPROC) get_extension_func("glBlitFramebufferEXT"); } +#endif +#if defined(OPENGLES_1) _glDrawBuffers = NULL; _glClearBufferfv = NULL; -#ifndef OPENGLES + _max_color_targets = 1; + +#elif defined(OPENGLES_2) + if (has_extension("GL_EXT_draw_buffers")) { + _glDrawBuffers = (PFNGLDRAWBUFFERSPROC) + get_extension_func("glDrawBuffersEXT"); + + } else if (has_extension("GL_NV_draw_buffers")) { + _glDrawBuffers = (PFNGLDRAWBUFFERSPROC) + get_extension_func("glDrawBuffersNV"); + } + +#else if (is_at_least_gl_version(2, 0)) { _glDrawBuffers = (PFNGLDRAWBUFFERSPROC) get_extension_func("glDrawBuffers"); + } else if (has_extension("GL_ARB_draw_buffers")) { _glDrawBuffers = (PFNGLDRAWBUFFERSPROC) get_extension_func("glDrawBuffersARB"); } +#endif +#ifndef OPENGLES_1 _max_color_targets = 1; if (_glDrawBuffers != 0) { GLint max_draw_buffers = 0; glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max_draw_buffers); _max_color_targets = max_draw_buffers; } +#endif // !OPENGLES_1 +#ifndef OPENGLES if (is_at_least_gl_version(3, 0)) { _glClearBufferfv = (PFNGLCLEARBUFFERFVPROC) get_extension_func("glClearBufferfv"); + } else { + _glClearBufferfv = NULL; } -#endif // OPENGLES +#endif // !OPENGLES #ifndef OPENGLES _supports_viewport_arrays = false; @@ -1562,18 +1747,17 @@ reset() { _supports_viewport_arrays = true; } } -#endif // OPENGLES +#endif // !OPENGLES _max_fb_samples = 0; -#ifndef OPENGLES if (_supports_framebuffer_multisample) { GLint max_samples; glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_samples); _max_fb_samples = max_samples; } -#endif _supports_occlusion_query = false; +#ifndef OPENGLES if (gl_support_occlusion_query) { if (is_at_least_gl_version(1, 5)) { _supports_occlusion_query = true; @@ -1608,7 +1792,6 @@ reset() { } } -#ifndef OPENGLES if (_supports_occlusion_query) { if (_glGenQueries == NULL || _glBeginQuery == NULL || _glEndQuery == NULL || _glDeleteQueries == NULL || @@ -1628,7 +1811,7 @@ reset() { } } } -#endif +#endif // !OPENGLES _supports_timer_query = false; #if defined(DO_PSTATS) && !defined(OPENGLES) @@ -1718,12 +1901,16 @@ reset() { } #endif +#ifdef OPENGLES_2 + _mirror_repeat = GL_MIRRORED_REPEAT; +#else _mirror_repeat = GL_REPEAT; if (has_extension("GL_ARB_texture_mirrored_repeat") || is_at_least_gl_version(1, 4) || has_extension("GL_OES_texture_mirrored_repeat")) { _mirror_repeat = GL_MIRRORED_REPEAT; } +#endif _mirror_clamp = _edge_clamp; _mirror_edge_clamp = _edge_clamp; @@ -1833,7 +2020,7 @@ reset() { } else { GLCAT.debug() << "Supported compressed texture formats:\n"; - GLint *formats = (GLint *)PANDA_MALLOC_ARRAY(num_compressed_formats * sizeof(GLint)); + GLint *formats = (GLint *)alloca(num_compressed_formats * sizeof(GLint)); glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats); for (int i = 0; i < num_compressed_formats; ++i) { switch (formats[i]) { @@ -1860,7 +2047,8 @@ reset() { case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: GLCAT.debug(false) << " GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG\n"; break; -#else +#endif +#ifndef OPENGLES_1 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: GLCAT.debug(false) << " GL_COMPRESSED_RGBA_S3TC_DXT3_EXT\n"; break; @@ -1868,7 +2056,8 @@ reset() { case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: GLCAT.debug(false) << " GL_COMPRESSED_RGBA_S3TC_DXT5_EXT\n"; break; - +#endif +#ifndef OPENGLES case GL_COMPRESSED_RGB_FXT1_3DFX: GLCAT.debug(false) << " GL_COMPRESSED_RGB_FXT1_3DFX\n"; break; @@ -1884,7 +2073,6 @@ reset() { << dec << "\n"; } } - PANDA_FREE_ARRAY(formats); } } } @@ -2040,26 +2228,6 @@ reset() { } #endif -#ifndef OPENGLES - // Some drivers expose one, some expose the other. ARB seems to be the newer one. - if (has_extension("GL_ARB_draw_instanced")) { - _glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC) - get_extension_func("glDrawArraysInstancedARB"); - _glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC) - get_extension_func("glDrawElementsInstancedARB"); - _supports_geometry_instancing = true; - } else if (has_extension("GL_EXT_draw_instanced")) { - _glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDPROC) - get_extension_func("glDrawArraysInstancedEXT"); - _glDrawElementsInstanced = (PFNGLDRAWELEMENTSINSTANCEDPROC) - get_extension_func("glDrawElementsInstancedEXT"); - _supports_geometry_instancing = true; - } else { - _glDrawElementsInstanced = 0; - _glDrawArraysInstanced = 0; - } -#endif - _auto_rescale_normal = false; // Ensure the initial state is what we say it should be (in some @@ -2139,13 +2307,12 @@ reset() { } #endif +#ifdef OPENGLES_2 + _max_texture_stages = 0; +#else if (_supports_multitexture) { GLint max_texture_stages = 0; -#ifdef OPENGLES_2 - glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_stages); -#else glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_stages); -#endif _max_texture_stages = max_texture_stages; if (GLCAT.is_debug()) { @@ -2153,6 +2320,8 @@ reset() { << "max texture stages = " << _max_texture_stages << "\n"; } } +#endif + _current_vbuffer_index = 0; _current_ibuffer_index = 0; _current_fbo = 0; @@ -2626,14 +2795,18 @@ prepare_display_region(DisplayRegionPipelineReader *dr) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: clear_before_callback() { +#ifndef OPENGLES_2 disable_standard_vertex_arrays(); +#endif unbind_buffers(); // Some callbacks may quite reasonably assume that the active // texture stage is still set to stage 0. CEGUI, in particular, // makes this assumption. _glActiveTexture(GL_TEXTURE0); +#ifndef OPENGLES_2 _glClientActiveTexture(GL_TEXTURE0); +#endif // Clear the bound sampler object, so that we do not inadvertently // override the callback's desired sampler settings. @@ -3231,10 +3404,13 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader, if (_vertex_array_shader_context != 0) { _vertex_array_shader_context->disable_shader_vertex_arrays(); } +#ifndef OPENGLES_2 if (!update_standard_vertex_arrays(force)) { return false; } +#endif } else { +#ifndef OPENGLES_2 // Shader. if (_vertex_array_shader_context == 0 || _vertex_array_shader_context->uses_standard_vertex_arrays()) { // Previous shader used standard arrays. @@ -3248,6 +3424,7 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader, disable_standard_vertex_arrays(); } } +#endif // !OPENGLES_2 if (_current_shader_context->uses_custom_vertex_arrays()) { // The current shader also uses custom vertex arrays. if (!_current_shader_context-> @@ -3268,6 +3445,7 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader, return true; } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::update_standard_vertex_arrays // Access: Protected @@ -3282,7 +3460,6 @@ begin_draw_primitives(const GeomPipelineReader *geom_reader, //////////////////////////////////////////////////////////////////// bool CLP(GraphicsStateGuardian):: update_standard_vertex_arrays(bool force) { -#ifndef OPENGLES_2 const GeomVertexAnimationSpec &animation = _data_reader->get_format()->get_animation(); bool hardware_animation = (animation.get_animation_type() == Geom::AT_hardware); @@ -3512,9 +3689,9 @@ update_standard_vertex_arrays(bool force) { glEnableClientState(GL_VERTEX_ARRAY); } } -#endif // OPENGLES_2 return true; } +#endif // !OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::unbind_buffers @@ -3542,9 +3719,12 @@ unbind_buffers() { _current_ibuffer_index = 0; } +#ifndef OPENGLES_2 disable_standard_vertex_arrays(); +#endif } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::disable_standard_vertex_arrays // Access: Protected @@ -3557,7 +3737,6 @@ unbind_buffers() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: disable_standard_vertex_arrays() { -#ifndef OPENGLES_2 #ifdef SUPPORT_IMMEDIATE_MODE if (_use_sender) return; #endif @@ -3583,8 +3762,8 @@ disable_standard_vertex_arrays() { glDisableClientState(GL_VERTEX_ARRAY); report_my_gl_errors(); -#endif } +#endif // !OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::draw_triangles @@ -3618,7 +3797,7 @@ draw_triangles(const GeomPrimitivePipelineReader *reader, bool force) { return false; } -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawElementsInstanced(GL_TRIANGLES, num_vertices, get_numeric_type(reader->get_index_type()), @@ -3634,7 +3813,7 @@ draw_triangles(const GeomPrimitivePipelineReader *reader, bool force) { client_pointer); } } else { -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawArraysInstanced(GL_TRIANGLES, reader->get_first_vertex(), @@ -3688,7 +3867,7 @@ draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force) { if (!setup_primitive(client_pointer, reader, force)) { return false; } -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawElementsInstanced(GL_TRIANGLE_STRIP, num_vertices, get_numeric_type(reader->get_index_type()), @@ -3704,7 +3883,7 @@ draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force) { client_pointer); } } else { -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawArraysInstanced(GL_TRIANGLE_STRIP, reader->get_first_vertex(), @@ -3738,7 +3917,7 @@ draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force) { unsigned int start = 0; for (size_t i = 0; i < ends.size(); i++) { _vertices_tristrip_pcollector.add_level(ends[i] - start); -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawElementsInstanced(GL_TRIANGLE_STRIP, ends[i] - start, get_numeric_type(reader->get_index_type()), @@ -3760,7 +3939,7 @@ draw_tristrips(const GeomPrimitivePipelineReader *reader, bool force) { int first_vertex = reader->get_first_vertex(); for (size_t i = 0; i < ends.size(); i++) { _vertices_tristrip_pcollector.add_level(ends[i] - start); -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawArraysInstanced(GL_TRIANGLE_STRIP, first_vertex + start, ends[i] - start, _instance_count); @@ -3819,7 +3998,7 @@ draw_trifans(const GeomPrimitivePipelineReader *reader, bool force) { unsigned int start = 0; for (size_t i = 0; i < ends.size(); i++) { _vertices_trifan_pcollector.add_level(ends[i] - start); -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawElementsInstanced(GL_TRIANGLE_FAN, ends[i] - start, get_numeric_type(reader->get_index_type()), @@ -3840,7 +4019,7 @@ draw_trifans(const GeomPrimitivePipelineReader *reader, bool force) { int first_vertex = reader->get_first_vertex(); for (size_t i = 0; i < ends.size(); i++) { _vertices_trifan_pcollector.add_level(ends[i] - start); -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawArraysInstanced(GL_TRIANGLE_FAN, first_vertex + start, ends[i] - start, _instance_count); @@ -3899,7 +4078,7 @@ draw_patches(const GeomPrimitivePipelineReader *reader, bool force) { return false; } -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawElementsInstanced(GL_PATCHES, num_vertices, get_numeric_type(reader->get_index_type()), @@ -3915,7 +4094,7 @@ draw_patches(const GeomPrimitivePipelineReader *reader, bool force) { client_pointer); } } else { -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawArraysInstanced(GL_PATCHES, reader->get_first_vertex(), @@ -3965,7 +4144,7 @@ draw_lines(const GeomPrimitivePipelineReader *reader, bool force) { if (!setup_primitive(client_pointer, reader, force)) { return false; } -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawElementsInstanced(GL_LINES, num_vertices, get_numeric_type(reader->get_index_type()), @@ -3981,7 +4160,7 @@ draw_lines(const GeomPrimitivePipelineReader *reader, bool force) { client_pointer); } } else { -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawArraysInstanced(GL_LINES, reader->get_first_vertex(), @@ -4042,7 +4221,7 @@ draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) { if (!setup_primitive(client_pointer, reader, force)) { return false; } -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawElementsInstanced(GL_LINE_STRIP, num_vertices, get_numeric_type(reader->get_index_type()), @@ -4083,7 +4262,7 @@ draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) { unsigned int start = 0; for (size_t i = 0; i < ends.size(); i++) { _vertices_other_pcollector.add_level(ends[i] - start); -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawElementsInstanced(GL_LINE_STRIP, ends[i] - start, get_numeric_type(reader->get_index_type()), @@ -4105,15 +4284,14 @@ draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) { int first_vertex = reader->get_first_vertex(); for (size_t i = 0; i < ends.size(); i++) { _vertices_other_pcollector.add_level(ends[i] - start); -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawArraysInstanced(GL_LINE_STRIP, first_vertex + start, ends[i] - start, _instance_count); } else #endif { - glDrawArrays(GL_LINE_STRIP, first_vertex + start, - ends[i] - start); + glDrawArrays(GL_LINE_STRIP, first_vertex + start, ends[i] - start); } start = ends[i] + 1; } @@ -4154,7 +4332,7 @@ draw_points(const GeomPrimitivePipelineReader *reader, bool force) { if (!setup_primitive(client_pointer, reader, force)) { return false; } -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawElementsInstanced(GL_POINTS, num_vertices, get_numeric_type(reader->get_index_type()), @@ -4170,7 +4348,7 @@ draw_points(const GeomPrimitivePipelineReader *reader, bool force) { client_pointer); } } else { -#ifndef OPENGLES +#ifndef OPENGLES_1 if (_supports_geometry_instancing && _instance_count > 0) { _glDrawArraysInstanced(GL_POINTS, reader->get_first_vertex(), @@ -4178,9 +4356,7 @@ draw_points(const GeomPrimitivePipelineReader *reader, bool force) { } else #endif { - glDrawArrays(GL_POINTS, - reader->get_first_vertex(), - num_vertices); + glDrawArrays(GL_POINTS, reader->get_first_vertex(), num_vertices); } } } @@ -4241,6 +4417,7 @@ end_draw_primitives() { report_my_gl_errors(); } +#ifndef OPENGLES //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::issue_memory_barrier // Access: Public @@ -4250,7 +4427,6 @@ end_draw_primitives() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: issue_memory_barrier(GLbitfield barriers) { -#ifndef OPENGLES if (!gl_enable_memory_barriers || _glMemoryBarrier == NULL) { return; } @@ -4288,8 +4464,8 @@ issue_memory_barrier(GLbitfield barriers) { GLCAT.spam(false) << "\n"; report_my_gl_errors(); -#endif // OPENGLES } +#endif // OPENGLES //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::prepare_texture @@ -4459,6 +4635,7 @@ extract_texture_data(Texture *tex) { return success; } +#ifndef OPENGLES //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::prepare_sampler // Access: Public, Virtual @@ -4475,7 +4652,6 @@ extract_texture_data(Texture *tex) { //////////////////////////////////////////////////////////////////// SamplerContext *CLP(GraphicsStateGuardian):: prepare_sampler(const SamplerState &sampler) { -#ifndef OPENGLES nassertr(_supports_sampler_objects, NULL); PStatGPUTimer timer(this, _prepare_sampler_pcollector); @@ -4543,12 +4719,10 @@ prepare_sampler(const SamplerState &sampler) { report_my_gl_errors(); return gsc; - -#else - return NULL; -#endif // OPENGLES } +#endif // !OPENGLES +#ifndef OPENGLES //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::release_sampler // Access: Public, Virtual @@ -4558,11 +4732,10 @@ prepare_sampler(const SamplerState &sampler) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: release_sampler(SamplerContext *sc) { -#ifndef OPENGLES CLP(SamplerContext) *gsc = DCAST(CLP(SamplerContext), sc); delete gsc; -#endif } +#endif // !OPENGLES //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::prepare_geom @@ -5064,6 +5237,7 @@ setup_primitive(const unsigned char *&client_pointer, return true; } +#ifndef OPENGLES //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::begin_occlusion_query // Access: Public, Virtual @@ -5082,10 +5256,6 @@ setup_primitive(const unsigned char *&client_pointer, //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: begin_occlusion_query() { -#ifdef OPENGLES // Occlusion queries not supported by OpenGL ES. - nassertv(false); - -#else nassertv(_supports_occlusion_query); nassertv(_current_occlusion_query == (OcclusionQueryContext *)NULL); PT(CLP(OcclusionQueryContext)) query = new CLP(OcclusionQueryContext)(this); @@ -5101,9 +5271,10 @@ begin_occlusion_query() { _current_occlusion_query = query; report_my_gl_errors(); -#endif // OPENGLES } +#endif // !OPENGLES +#ifndef OPENGLES //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::end_occlusion_query // Access: Public, Virtual @@ -5115,11 +5286,6 @@ begin_occlusion_query() { //////////////////////////////////////////////////////////////////// PT(OcclusionQueryContext) CLP(GraphicsStateGuardian):: end_occlusion_query() { -#ifdef OPENGLES // Occlusion queries not supported by OpenGL ES. - nassertr(false, NULL); - return NULL; - -#else nassertr(_current_occlusion_query != (OcclusionQueryContext *)NULL, NULL); PT(OcclusionQueryContext) result = _current_occlusion_query; @@ -5150,8 +5316,8 @@ end_occlusion_query() { report_my_gl_errors(); return result; -#endif // OPENGLES } +#endif // !OPENGLES //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::issue_timer_query @@ -5204,6 +5370,7 @@ issue_timer_query(int pstats_index) { #endif } +#ifndef OPENGLES //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::dispatch_compute // Access: Public, Virtual @@ -5212,7 +5379,6 @@ issue_timer_query(int pstats_index) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: dispatch_compute(int num_groups_x, int num_groups_y, int num_groups_z) { -#ifndef OPENGLES maybe_gl_finish(); PStatGPUTimer timer(this, _compute_dispatch_pcollector); @@ -5221,8 +5387,8 @@ dispatch_compute(int num_groups_x, int num_groups_y, int num_groups_z) { _glDispatchCompute(num_groups_x, num_groups_y, num_groups_z); maybe_gl_finish(); -#endif } +#endif // !OPENGLES //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::make_geom_munger @@ -5414,6 +5580,7 @@ framebuffer_copy_to_texture(Texture *tex, int view, int z, #endif if (z >= 0) { +#ifndef OPENGLES_1 if (new_image) { // These won't be used because we pass a NULL image, but we still // have to specify them. Might as well use the actual values. @@ -5423,6 +5590,7 @@ framebuffer_copy_to_texture(Texture *tex, int view, int z, } _glCopyTexSubImage3D(target, 0, 0, 0, z, xo, yo, w, h); +#endif } else { if (new_image) { // We have to create a new image. @@ -5645,6 +5813,7 @@ framebuffer_copy_to_ram(Texture *tex, int view, int z, return true; } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::apply_fog // Access: Public, Virtual @@ -5652,7 +5821,6 @@ framebuffer_copy_to_ram(Texture *tex, int view, int z, //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: apply_fog(Fog *fog) { -#ifndef OPENGLES_2 Fog::Mode fmode = fog->get_mode(); glFogf(GL_FOG_MODE, get_fog_mode_type(fmode)); @@ -5669,8 +5837,8 @@ apply_fog(Fog *fog) { call_glFogfv(GL_FOG_COLOR, fog->get_color()); report_my_gl_errors(); -#endif } +#endif // OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_transform @@ -5711,6 +5879,7 @@ do_issue_transform() { report_my_gl_errors(); } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_shade_model // Access: Protected @@ -5718,7 +5887,6 @@ do_issue_transform() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: do_issue_shade_model() { -#ifndef OPENGLES_2 const ShadeModelAttrib *target_shade_model; _target_rs->get_attrib_def(target_shade_model); @@ -5733,8 +5901,8 @@ do_issue_shade_model() { _flat_shade_model = true; break; } -#endif } +#endif // !OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_shader @@ -5783,9 +5951,6 @@ do_issue_shader(bool state_has_changed) { _current_shader_context = context; context->issue_parameters(Shader::SSD_shaderinputs); } else { -#ifdef OPENGLES_2 - context->bind(false); -#endif if (state_has_changed) { // Use the same shader as before, but with new input arguments. context->issue_parameters(Shader::SSD_shaderinputs); @@ -5908,11 +6073,12 @@ do_issue_antialias() { #endif // OPENGLES break; } -#endif +#endif // !OPENGLES_2 report_my_gl_errors(); } +#ifndef OPENGLES_2 // OpenGL ES 2.0 doesn't support rescaling normals. //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_rescale_normal // Access: Protected @@ -5920,7 +6086,6 @@ do_issue_antialias() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: do_issue_rescale_normal() { -#ifndef OPENGLES_2 // OpenGL ES 2.0 doesn't support rescaling normals. const RescaleNormalAttrib *target_rescale_normal; _target_rs->get_attrib_def(target_rescale_normal); @@ -5962,8 +6127,8 @@ do_issue_rescale_normal() { << "Unknown rescale_normal mode " << (int)mode << endl; } report_my_gl_errors(); -#endif } +#endif // !OPENGLES_2 // PandaCompareFunc - 1 + 0x200 === GL_NEVER, etc. order is sequential #define PANDA_TO_GL_COMPAREFUNC(PANDACMPFUNC) (PANDACMPFUNC-1 +0x200) @@ -5988,6 +6153,7 @@ do_issue_depth_test() { report_my_gl_errors(); } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_alpha_test // Access: Protected @@ -6006,13 +6172,12 @@ do_issue_alpha_test() { enable_alpha_test(false); } else { nassertv(GL_NEVER == (AlphaTestAttrib::M_never-1+0x200)); -#ifndef OPENGLES_2 glAlphaFunc(PANDA_TO_GL_COMPAREFUNC(mode), target_alpha_test->get_reference_alpha()); -#endif enable_alpha_test(true); } } } +#endif // !OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_depth_write @@ -6073,6 +6238,7 @@ do_issue_cull_face() { report_my_gl_errors(); } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_fog // Access: Protected @@ -6093,6 +6259,7 @@ do_issue_fog() { } report_my_gl_errors(); } +#endif // !OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_depth_offset @@ -6133,6 +6300,7 @@ do_issue_depth_offset() { report_my_gl_errors(); } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_material // Access: Protected @@ -6140,7 +6308,6 @@ do_issue_depth_offset() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: do_issue_material() { -#ifndef OPENGLES_2 // OpenGL ES 2.0 doesn't support materials. static Material empty; const Material *material; @@ -6238,8 +6405,8 @@ do_issue_material() { #endif report_my_gl_errors(); -#endif // OPENGLES_2 } +#endif // !OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_blending @@ -6370,6 +6537,7 @@ do_issue_blending() { enable_blend(false); } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::bind_light // Access: Public, Virtual @@ -6380,7 +6548,6 @@ do_issue_blending() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: bind_light(PointLight *light_obj, const NodePath &light, int light_id) { -#ifndef OPENGLES_2 // static PStatCollector _draw_set_state_light_bind_point_pcollector("Draw:Set State:Light:Bind:Point"); // PStatGPUTimer timer(this, _draw_set_state_light_bind_point_pcollector); @@ -6412,9 +6579,10 @@ bind_light(PointLight *light_obj, const NodePath &light, int light_id) { glLightf(id, GL_QUADRATIC_ATTENUATION, att[2]); report_my_gl_errors(); -#endif } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::bind_light // Access: Public, Virtual @@ -6425,7 +6593,6 @@ bind_light(PointLight *light_obj, const NodePath &light, int light_id) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: bind_light(DirectionalLight *light_obj, const NodePath &light, int light_id) { -#ifndef OPENGLES_2 // static PStatCollector _draw_set_state_light_bind_directional_pcollector("Draw:Set State:Light:Bind:Directional"); // PStatGPUTimer timer(this, _draw_set_state_light_bind_directional_pcollector); @@ -6464,9 +6631,10 @@ bind_light(DirectionalLight *light_obj, const NodePath &light, int light_id) { glLightf(id, GL_QUADRATIC_ATTENUATION, 0.0f); report_my_gl_errors(); -#endif } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::bind_light // Access: Public, Virtual @@ -6477,7 +6645,6 @@ bind_light(DirectionalLight *light_obj, const NodePath &light, int light_id) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: bind_light(Spotlight *light_obj, const NodePath &light, int light_id) { -#ifndef OPENGLES_2 // static PStatCollector _draw_set_state_light_bind_spotlight_pcollector("Draw:Set State:Light:Bind:Spotlight"); // PStatGPUTimer timer(this, _draw_set_state_light_bind_spotlight_pcollector); @@ -6510,8 +6677,8 @@ bind_light(Spotlight *light_obj, const NodePath &light, int light_id) { glLightf(id, GL_QUADRATIC_ATTENUATION, att[2]); report_my_gl_errors(); -#endif } +#endif // !OPENGLES_2 #ifdef SUPPORT_IMMEDIATE_MODE //////////////////////////////////////////////////////////////////// @@ -6720,10 +6887,12 @@ query_gl_version() { _gl_version_major = 0; _gl_version_minor = 0; + _gl_shadlang_ver_major = 0; + _gl_shadlang_ver_minor = 0; const GLubyte *text = glGetString(GL_VERSION); if (text == (const GLubyte *)NULL) { - GLCAT.debug() + GLCAT.warning() << "Unable to query GL_VERSION\n"; } else { string version((const char *)text); @@ -6759,30 +6928,40 @@ query_gl_version() { string_to_int(components[1], _gl_version_minor); } - if (GLCAT.is_debug()) { - GLCAT.debug() + if (GLCAT.is_info()) { + GLCAT.info() << "GL_VERSION = " << version << ", decoded to " << _gl_version_major << "." << _gl_version_minor << "\n"; } + #ifndef OPENGLES - if (_gl_version_major==1) { - const char *extstr = (const char *) glGetString(GL_EXTENSIONS); - if (extstr != NULL) { - if (strstr( extstr, "GL_ARB_shading_language_100") != NULL) - { - _gl_shadlang_ver_major = 1; - _gl_shadlang_ver_minor = 0; - } + if (_gl_version_major == 1) { + // We can't call has_extension at this point yet. + const char *extstr = (const char *) glGetString(GL_EXTENSIONS); + if (extstr != NULL) { + if (strstr(extstr, "GL_ARB_shading_language_100") != NULL) { + _gl_shadlang_ver_major = 1; + _gl_shadlang_ver_minor = 0; } + } + } else if (_gl_version_major >= 2) { + _gl_shadlang_ver_major = 1; + _gl_shadlang_ver_minor = 1; + const char *verstr = (const char *) glGetString(GL_SHADING_LANGUAGE_VERSION); + if (verstr == NULL || sscanf(verstr, "%d.%d", &_gl_shadlang_ver_major, &_gl_shadlang_ver_minor) != 2) { + GLCAT.warning() << "Invalid GL_SHADING_LANGUAGE_VERSION format.\n"; + } + cerr << verstr << " -> " << _gl_shadlang_ver_major << " . " << _gl_shadlang_ver_minor << "\n"; } - else if (_gl_version_major >= 2) { - const char *verstr = (const char *) glGetString(GL_SHADING_LANGUAGE_VERSION); - if ((verstr == NULL) || (sscanf(verstr, "%d.%d", &_gl_shadlang_ver_major, &_gl_shadlang_ver_minor) != 2)) - { - GLCAT.warning() << "Invalid GL_SHADING_LANGUAGE_VERSION format.\n"; - } +#elif defined(OPENGLES_2) + _gl_shadlang_ver_major = 1; + _gl_shadlang_ver_minor = 0; + const char *verstr = (const char *) glGetString(GL_SHADING_LANGUAGE_VERSION); + if (verstr == NULL || sscanf(verstr, "OpenGL ES GLSL %d.%d", &_gl_shadlang_ver_major, &_gl_shadlang_ver_minor) != 2) { + GLCAT.warning() << "Invalid GL_SHADING_LANGUAGE_VERSION format.\n"; } + cerr << verstr << " -> " << _gl_shadlang_ver_major << " . " << _gl_shadlang_ver_minor << "\n"; #endif } } @@ -7134,9 +7313,11 @@ get_numeric_type(Geom::NumericType numeric_type) { case Geom::NT_uint16: return GL_UNSIGNED_SHORT; -#ifndef OPENGLES_1 case Geom::NT_uint32: +#ifndef OPENGLES_1 return GL_UNSIGNED_INT; +#else + break; #endif case Geom::NT_uint8: @@ -7147,9 +7328,11 @@ get_numeric_type(Geom::NumericType numeric_type) { case Geom::NT_float32: return GL_FLOAT; -#ifndef OPENGLES case Geom::NT_float64: +#ifndef OPENGLES return GL_DOUBLE; +#else + break; #endif case Geom::NT_stdfloat: @@ -7171,8 +7354,9 @@ get_numeric_type(Geom::NumericType numeric_type) { GLenum CLP(GraphicsStateGuardian):: get_texture_target(Texture::TextureType texture_type) const { switch (texture_type) { -#ifndef OPENGLES case Texture::TT_1d_texture: + // There are no 1D textures in OpenGL ES. Fall back to 2D textures. +#ifndef OPENGLES return GL_TEXTURE_1D; #endif @@ -7487,37 +7671,40 @@ get_external_image_format(Texture *tex) const { return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; } -#ifndef OPENGLES case Texture::CM_dxt3: +#ifndef OPENGLES if (format == Texture::F_srgb || format == Texture::F_srgb_alpha) { return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; - } else { - return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; } +#endif +#ifndef OPENGLES_1 + return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; +#endif + break; case Texture::CM_dxt5: +#ifndef OPENGLES if (format == Texture::F_srgb || format == Texture::F_srgb_alpha) { return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; - } else { - return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; } +#endif +#ifndef OPENGLES_1 + return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; +#endif + break; case Texture::CM_fxt1: +#ifndef OPENGLES if (Texture::has_alpha(format)) { return GL_COMPRESSED_RGBA_FXT1_3DFX; } else { return GL_COMPRESSED_RGB_FXT1_3DFX; } +#endif + break; -#else +#ifdef OPENGLES case Texture::CM_pvr1_2bpp: -#ifndef OPENGLES - if (format == Texture::F_srgb_alpha) { - return GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT; - } else if (format == Texture::F_srgb) { - return GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT; - } else -#endif // OPENGLES if (Texture::has_alpha(format)) { return GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; } else { @@ -7525,19 +7712,16 @@ get_external_image_format(Texture *tex) const { } case Texture::CM_pvr1_4bpp: -#ifndef OPENGLES - if (format == Texture::F_srgb_alpha) { - return GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT; - } else if (format == Texture::F_srgb) { - return GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT; - } else -#endif // OPENGLES if (Texture::has_alpha(format)) { return GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; } else { return GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; } -#endif +#else + case Texture::CM_pvr1_2bpp: + case Texture::CM_pvr1_4bpp: + break; +#endif // OPENGLES case Texture::CM_default: case Texture::CM_off: @@ -7623,12 +7807,14 @@ get_external_image_format(Texture *tex) const { return GL_RGB_INTEGER; case Texture::F_rgba8i: return GL_RGBA_INTEGER; - #endif + + default: + break; } GLCAT.error() << "Invalid Texture::Format value in get_external_image_format(): " - << (int)tex->get_format() << "\n"; + << tex->get_format() << "\n"; return GL_RGB; } @@ -7654,8 +7840,6 @@ get_internal_image_format(Texture *tex, bool force_sized) const { if (get_supports_compressed_texture_format(compression)) { switch (compression) { - // For now, we don't support generic compression with OpenGL ES. -#ifndef OPENGLES case Texture::CM_on: // The user asked for just generic compression. OpenGL supports // requesting just generic compression, but we'd like to go ahead @@ -7681,30 +7865,46 @@ get_internal_image_format(Texture *tex, bool force_sized) const { case Texture::F_rgbm: if (get_supports_compressed_texture_format(Texture::CM_dxt1) && !is_3d) { return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; - } else if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { + } +#ifndef OPENGLES + if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { return GL_COMPRESSED_RGBA_FXT1_3DFX; } return GL_COMPRESSED_RGBA; +#endif + break; case Texture::F_rgba4: +#ifndef OPENGLES_1 if (get_supports_compressed_texture_format(Texture::CM_dxt3) && !is_3d) { return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - } else if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { + } +#endif +#ifndef OPENGLES + if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { return GL_COMPRESSED_RGBA_FXT1_3DFX; } return GL_COMPRESSED_RGBA; +#endif + break; case Texture::F_rgba: case Texture::F_rgba8: case Texture::F_rgba12: case Texture::F_rgba16: case Texture::F_rgba32: +#ifndef OPENGLES_1 if (get_supports_compressed_texture_format(Texture::CM_dxt5) && !is_3d) { return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - } else if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { + } +#endif +#ifndef OPENGLES + if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { return GL_COMPRESSED_RGBA_FXT1_3DFX; } return GL_COMPRESSED_RGBA; +#endif + break; case Texture::F_rgb: case Texture::F_rgb5: @@ -7716,18 +7916,28 @@ get_internal_image_format(Texture *tex, bool force_sized) const { case Texture::F_rgb32: if (get_supports_compressed_texture_format(Texture::CM_dxt1) && !is_3d) { return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; - } else if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { + } +#ifndef OPENGLES + if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { return GL_COMPRESSED_RGB_FXT1_3DFX; } return GL_COMPRESSED_RGB; +#endif + break; case Texture::F_alpha: +#ifndef OPENGLES_1 if (get_supports_compressed_texture_format(Texture::CM_dxt5) && !is_3d) { return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - } else if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { + } +#endif +#ifndef OPENGLES + if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { return GL_COMPRESSED_RGBA_FXT1_3DFX; } return GL_COMPRESSED_ALPHA; +#endif + break; case Texture::F_red: case Texture::F_green: @@ -7736,37 +7946,56 @@ get_internal_image_format(Texture *tex, bool force_sized) const { case Texture::F_r32: if (get_supports_compressed_texture_format(Texture::CM_dxt1) && !is_3d) { return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; - } else if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { + } +#ifndef OPENGLES + if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { return GL_COMPRESSED_RGB_FXT1_3DFX; } return GL_COMPRESSED_RED; +#endif + break; case Texture::F_rg16: case Texture::F_rg32: if (get_supports_compressed_texture_format(Texture::CM_dxt1) && !is_3d) { return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; - } else if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { + } +#ifndef OPENGLES + if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { return GL_COMPRESSED_RGB_FXT1_3DFX; } return GL_COMPRESSED_RG; +#endif + break; case Texture::F_luminance: if (get_supports_compressed_texture_format(Texture::CM_dxt1) && !is_3d) { return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; - } else if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { + } +#ifndef OPENGLES + if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { return GL_COMPRESSED_RGB_FXT1_3DFX; } return GL_COMPRESSED_LUMINANCE; +#endif + break; case Texture::F_luminance_alpha: case Texture::F_luminance_alphamask: +#ifndef OPENGLES_1 if (get_supports_compressed_texture_format(Texture::CM_dxt5) && !is_3d) { return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - } else if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { + } +#endif +#ifndef OPENGLES + if (get_supports_compressed_texture_format(Texture::CM_fxt1) && !is_3d) { return GL_COMPRESSED_RGBA_FXT1_3DFX; } return GL_COMPRESSED_LUMINANCE_ALPHA; +#endif + break; +#ifndef OPENGLES case Texture::F_srgb: if (get_supports_compressed_texture_format(Texture::CM_dxt1) && !is_3d) { return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT; @@ -7784,9 +8013,16 @@ get_internal_image_format(Texture *tex, bool force_sized) const { case Texture::F_sluminance_alpha: return GL_COMPRESSED_SLUMINANCE_ALPHA; +#else + // For now, we don't support compressed sRGB textures in OpenGL ES. + case Texture::F_srgb: + case Texture::F_srgb_alpha: + case Texture::F_sluminance: + case Texture::F_sluminance_alpha: + break; +#endif } break; -#endif case Texture::CM_dxt1: #ifndef OPENGLES @@ -7802,28 +8038,38 @@ get_internal_image_format(Texture *tex, bool force_sized) const { return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; } -#ifndef OPENGLES case Texture::CM_dxt3: +#ifndef OPENGLES if (format == Texture::F_srgb || format == Texture::F_srgb_alpha) { return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; - } else { - return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; } +#endif +#ifndef OPENGLES_1 + return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; +#endif + break; case Texture::CM_dxt5: +#ifndef OPENGLES if (format == Texture::F_srgb || format == Texture::F_srgb_alpha) { return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; - } else { - return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; } +#endif +#ifndef OPENGLES_1 + return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; +#endif case Texture::CM_fxt1: +#ifndef OPENGLES if (Texture::has_alpha(format)) { return GL_COMPRESSED_RGBA_FXT1_3DFX; } else { return GL_COMPRESSED_RGB_FXT1_3DFX; } -#else +#endif + break; + +#ifdef OPENGLES case Texture::CM_pvr1_2bpp: if (Texture::has_alpha(format)) { return GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; @@ -7837,6 +8083,10 @@ get_internal_image_format(Texture *tex, bool force_sized) const { } else { return GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; } +#else + case Texture::CM_pvr1_2bpp: + case Texture::CM_pvr1_4bpp: + break; #endif case Texture::CM_default: @@ -8337,7 +8587,13 @@ get_blend_equation_type(ColorBlendAttrib::Mode mode) { case ColorBlendAttrib::M_inv_subtract: return GL_FUNC_REVERSE_SUBTRACT; -#ifndef OPENGLES +#ifdef OPENGLES + case ColorBlendAttrib::M_min: + return GL_MIN_EXT; + + case ColorBlendAttrib::M_max: + return GL_MAX_EXT; +#else case ColorBlendAttrib::M_min: return GL_MIN; @@ -8390,7 +8646,18 @@ get_blend_func(ColorBlendAttrib::Operand operand) { case ColorBlendAttrib::O_one_minus_fbuffer_alpha: return GL_ONE_MINUS_DST_ALPHA; -#ifndef OPENGLES_1 +#ifdef OPENGLES_1 + // OpenGL ES 1 has no constant blend factor. + case ColorBlendAttrib::O_constant_color: + case ColorBlendAttrib::O_color_scale: + case ColorBlendAttrib::O_one_minus_constant_color: + case ColorBlendAttrib::O_one_minus_color_scale: + case ColorBlendAttrib::O_constant_alpha: + case ColorBlendAttrib::O_alpha_scale: + case ColorBlendAttrib::O_one_minus_constant_alpha: + case ColorBlendAttrib::O_one_minus_alpha_scale: + break; +#else case ColorBlendAttrib::O_constant_color: case ColorBlendAttrib::O_color_scale: return GL_CONSTANT_COLOR; @@ -8549,6 +8816,7 @@ reissue_transforms() { do_issue_transform(); } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::enable_lighting // Access: Protected, Virtual @@ -8559,7 +8827,6 @@ reissue_transforms() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: enable_lighting(bool enable) { -#ifndef OPENGLES_2 // static PStatCollector _draw_set_state_light_enable_lighting_pcollector("Draw:Set State:Light:Enable lighting"); // PStatGPUTimer timer(this, _draw_set_state_light_enable_lighting_pcollector); @@ -8568,9 +8835,10 @@ enable_lighting(bool enable) { } else { glDisable(GL_LIGHTING); } -#endif } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::set_ambient_light // Access: Protected, Virtual @@ -8581,7 +8849,6 @@ enable_lighting(bool enable) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: set_ambient_light(const LColor &color) { -#ifndef OPENGLES_2 // static PStatCollector _draw_set_state_light_ambient_pcollector("Draw:Set State:Light:Ambient"); // PStatGPUTimer timer(this, _draw_set_state_light_ambient_pcollector); @@ -8591,9 +8858,10 @@ set_ambient_light(const LColor &color) { c[2] * _light_color_scale[2], c[3] * _light_color_scale[3]); call_glLightModelfv(GL_LIGHT_MODEL_AMBIENT, c); -#endif } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::enable_light // Access: Protected, Virtual @@ -8612,7 +8880,9 @@ enable_light(int light_id, bool enable) { glDisable(get_light_id(light_id)); } } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::begin_bind_lights // Access: Protected, Virtual @@ -8627,7 +8897,6 @@ enable_light(int light_id, bool enable) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: begin_bind_lights() { -#ifndef OPENGLES_2 // static PStatCollector _draw_set_state_light_begin_bind_pcollector("Draw:Set State:Light:Begin bind"); // PStatGPUTimer timer(this, _draw_set_state_light_begin_bind_pcollector); @@ -8644,9 +8913,10 @@ begin_bind_lights() { glMatrixMode(GL_MODELVIEW); glPushMatrix(); GLPf(LoadMatrix)(render_transform->get_mat().get_data()); -#endif } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::end_bind_lights // Access: Protected, Virtual @@ -8658,15 +8928,15 @@ begin_bind_lights() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: end_bind_lights() { -#ifndef OPENGLES_2 // static PStatCollector _draw_set_state_light_end_bind_pcollector("Draw:Set State:Light:End bind"); // PStatGPUTimer timer(this, _draw_set_state_light_end_bind_pcollector); glMatrixMode(GL_MODELVIEW); glPopMatrix(); -#endif } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::enable_clip_plane // Access: Protected, Virtual @@ -8683,7 +8953,9 @@ enable_clip_plane(int plane_id, bool enable) { glDisable(get_clip_plane_id(plane_id)); } } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::begin_bind_clip_planes // Access: Protected, Virtual @@ -8698,7 +8970,6 @@ enable_clip_plane(int plane_id, bool enable) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: begin_bind_clip_planes() { -#ifndef OPENGLES_2 // We need to temporarily load a new matrix so we can define the // clip_plane in a known coordinate system. We pick the transform of the // root. (Alternatively, we could leave the current transform where @@ -8712,9 +8983,10 @@ begin_bind_clip_planes() { glMatrixMode(GL_MODELVIEW); glPushMatrix(); GLPf(LoadMatrix)(render_transform->get_mat().get_data()); -#endif } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::bind_clip_plane // Access: Protected, Virtual @@ -8732,7 +9004,6 @@ bind_clip_plane(const NodePath &plane, int plane_id) { DCAST_INTO_V(plane_node, plane.node()); LPlane xformed_plane = plane_node->get_plane() * transform->get_mat(); -#ifndef OPENGLES_2 // OpenGL ES 2.0 doesn't support clip planes at all. #ifdef OPENGLES // OpenGL ES uses a single-precision call. LPlanef single_plane(LCAST(float, xformed_plane)); @@ -8742,11 +9013,12 @@ bind_clip_plane(const NodePath &plane, int plane_id) { LPlaned double_plane(LCAST(double, xformed_plane)); glClipPlane(id, double_plane.get_data()); #endif // OPENGLES -#endif // OPENGLES_2 report_my_gl_errors(); } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::end_bind_clip_planes // Access: Protected, Virtual @@ -8758,11 +9030,10 @@ bind_clip_plane(const NodePath &plane, int plane_id) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: end_bind_clip_planes() { -#ifndef OPENGLES_2 glMatrixMode(GL_MODELVIEW); glPopMatrix(); -#endif } +#endif // !OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::set_state_and_transform @@ -8809,10 +9080,11 @@ set_state_and_transform(const RenderState *target, _target_shader = (const ShaderAttrib *) _target_rs->get_attrib_def(ShaderAttrib::get_class_slot()); -#ifndef OPENGLES +#ifndef OPENGLES_1 _instance_count = _target_shader->get_instance_count(); #endif +#ifndef OPENGLES_2 int alpha_test_slot = AlphaTestAttrib::get_class_slot(); if (_target_rs->get_attrib(alpha_test_slot) != _state_rs->get_attrib(alpha_test_slot) || !_state_mask.get_bit(alpha_test_slot) || @@ -8822,6 +9094,7 @@ set_state_and_transform(const RenderState *target, do_issue_alpha_test(); _state_mask.set_bit(alpha_test_slot); } +#endif int antialias_slot = AntialiasAttrib::get_class_slot(); if (_target_rs->get_attrib(antialias_slot) != _state_rs->get_attrib(antialias_slot) || @@ -8903,6 +9176,7 @@ set_state_and_transform(const RenderState *target, _state_mask.set_bit(render_mode_slot); } +#ifndef OPENGLES_2 int rescale_normal_slot = RescaleNormalAttrib::get_class_slot(); if (_target_rs->get_attrib(rescale_normal_slot) != _state_rs->get_attrib(rescale_normal_slot) || !_state_mask.get_bit(rescale_normal_slot)) { @@ -8910,7 +9184,9 @@ set_state_and_transform(const RenderState *target, do_issue_rescale_normal(); _state_mask.set_bit(rescale_normal_slot); } +#endif +#ifndef OPENGLES_2 int shade_model_slot = ShadeModelAttrib::get_class_slot(); if (_target_rs->get_attrib(shade_model_slot) != _state_rs->get_attrib(shade_model_slot) || !_state_mask.get_bit(shade_model_slot)) { @@ -8918,6 +9194,7 @@ set_state_and_transform(const RenderState *target, do_issue_shade_model(); _state_mask.set_bit(shade_model_slot); } +#endif int transparency_slot = TransparencyAttrib::get_class_slot(); int color_write_slot = ColorWriteAttrib::get_class_slot(); @@ -8972,6 +9249,7 @@ set_state_and_transform(const RenderState *target, // If one of the previously-loaded TexGen modes modified the texture // matrix, then if either state changed, we have to change both of // them now. +#ifndef OPENGLES_2 if (_tex_gen_modifies_mat) { int tex_gen_slot = TexGenAttrib::get_class_slot(); int tex_matrix_slot = TexMatrixAttrib::get_class_slot(); @@ -8991,7 +9269,9 @@ set_state_and_transform(const RenderState *target, do_issue_tex_matrix(); _state_mask.set_bit(tex_matrix_slot); } +#endif +#ifndef OPENGLES_2 int tex_gen_slot = TexGenAttrib::get_class_slot(); if (_target_tex_gen != _state_tex_gen || !_state_mask.get_bit(tex_gen_slot)) { @@ -9000,12 +9280,15 @@ set_state_and_transform(const RenderState *target, _state_tex_gen = _target_tex_gen; _state_mask.set_bit(tex_gen_slot); } +#endif int material_slot = MaterialAttrib::get_class_slot(); if (_target_rs->get_attrib(material_slot) != _state_rs->get_attrib(material_slot) || !_state_mask.get_bit(material_slot)) { //PStatGPUTimer timer(this, _draw_set_state_material_pcollector); +#ifndef OPENGLES_2 do_issue_material(); +#endif _state_mask.set_bit(material_slot); #ifndef OPENGLES_1 if (_current_shader_context) { @@ -9018,7 +9301,9 @@ set_state_and_transform(const RenderState *target, if (_target_rs->get_attrib(light_slot) != _state_rs->get_attrib(light_slot) || !_state_mask.get_bit(light_slot)) { //PStatGPUTimer timer(this, _draw_set_state_light_pcollector); +#ifndef OPENGLES_2 do_issue_light(); +#endif _state_mask.set_bit(light_slot); #ifndef OPENGLES_1 if (_current_shader_context) { @@ -9039,7 +9324,9 @@ set_state_and_transform(const RenderState *target, if (_target_rs->get_attrib(fog_slot) != _state_rs->get_attrib(fog_slot) || !_state_mask.get_bit(fog_slot)) { //PStatGPUTimer timer(this, _draw_set_state_fog_pcollector); +#ifndef OPENGLES_2 do_issue_fog(); +#endif _state_mask.set_bit(fog_slot); #ifndef OPENGLES_1 if (_current_shader_context) { @@ -9150,10 +9437,14 @@ do_issue_texture() { if (_texture_binding_shader_context != 0) { _texture_binding_shader_context->disable_shader_texture_bindings(); } +#ifndef OPENGLES_2 update_standard_texture_bindings(); +#endif } else { if (_texture_binding_shader_context == 0) { +#ifndef OPENGLES_2 disable_standard_texture_bindings(); +#endif _current_shader_context->update_shader_texture_bindings(NULL); } else { _current_shader_context-> @@ -9166,6 +9457,7 @@ do_issue_texture() { #endif } +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::update_standard_texture_bindings // Access: Private @@ -9175,7 +9467,6 @@ do_issue_texture() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: update_standard_texture_bindings() { -#ifndef OPENGLES_2 #ifndef NDEBUG if (_show_texture_usage) { update_show_usage_texture_bindings(-1); @@ -9409,8 +9700,9 @@ update_standard_texture_bindings() { _num_active_texture_stages = num_stages; report_my_gl_errors(); -#endif // OPENGLES_2 } +#endif // !OPENGLES_2 + #ifndef NDEBUG @@ -9591,6 +9883,7 @@ upload_usage_texture(int width, int height) { } #endif // NDEBUG +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::disable_standard_texture_bindings // Access: Private @@ -9598,7 +9891,6 @@ upload_usage_texture(int width, int height) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: disable_standard_texture_bindings() { -#ifndef OPENGLES_2 // Disable the texture stages that are no longer used. for (int i = 0; i < _num_active_texture_stages; i++) { _glActiveTexture(GL_TEXTURE0 + i); @@ -9619,9 +9911,10 @@ disable_standard_texture_bindings() { _num_active_texture_stages = 0; report_my_gl_errors(); -#endif // OPENGLES_2 } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_tex_matrix // Access: Protected @@ -9629,7 +9922,6 @@ disable_standard_texture_bindings() { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: do_issue_tex_matrix() { -#ifndef OPENGLES_2 // OpenGL ES 2 doesn't support texture matrices, I think. nassertv(_num_active_texture_stages <= _max_texture_stages); for (int i = 0; i < _num_active_texture_stages; i++) { @@ -9656,9 +9948,10 @@ do_issue_tex_matrix() { } } report_my_gl_errors(); -#endif } +#endif // !OPENGLES_2 +#ifndef OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::do_issue_tex_gen // Access: Protected @@ -9687,7 +9980,6 @@ do_issue_tex_gen() { for (int i = 0; i < _num_active_texture_stages; i++) { TextureStage *stage = _target_texture->get_on_ff_stage(i); _glActiveTexture(GL_TEXTURE0 + i); -#ifndef OPENGLES_2 if (_supports_point_sprite) { #ifdef OPENGLES glTexEnvi(GL_POINT_SPRITE_OES, GL_COORD_REPLACE_OES, GL_FALSE); @@ -9695,7 +9987,6 @@ do_issue_tex_gen() { glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_FALSE); #endif // OPENGLES } -#endif // OPENGLES_2 #ifndef OPENGLES // TexGen not supported by OpenGL ES. glDisable(GL_TEXTURE_GEN_S); @@ -9926,7 +10217,6 @@ do_issue_tex_gen() { if (got_point_sprites != _tex_gen_point_sprite) { _tex_gen_point_sprite = got_point_sprites; -#ifndef OPENGLES_2 #ifdef OPENGLES if (_tex_gen_point_sprite) { glEnable(GL_POINT_SPRITE_OES); @@ -9940,11 +10230,11 @@ do_issue_tex_gen() { glDisable(GL_POINT_SPRITE_ARB); } #endif // OPENGLES -#endif // OPENGLES_2 } report_my_gl_errors(); } +#endif // !OPENGLES_2 //////////////////////////////////////////////////////////////////// // Function: GLGraphicsStateGuardian::specify_texture @@ -10028,13 +10318,15 @@ specify_texture(CLP(TextureContext) *gtc, const SamplerState &sampler) { glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); } -#ifndef OPENGLES +#ifndef OPENGLES_1 if (tex->get_format() == Texture::F_depth_stencil || tex->get_format() == Texture::F_depth_component || tex->get_format() == Texture::F_depth_component16 || tex->get_format() == Texture::F_depth_component24 || tex->get_format() == Texture::F_depth_component32) { +#ifndef OPENGLES glTexParameteri(target, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY); +#endif if (_supports_shadow_filter) { if ((sampler.get_magfilter() == SamplerState::FT_shadow) || (sampler.get_minfilter() == SamplerState::FT_shadow)) { @@ -10046,7 +10338,9 @@ specify_texture(CLP(TextureContext) *gtc, const SamplerState &sampler) { } } } +#endif +#ifndef OPENGLES glTexParameterf(target, GL_TEXTURE_MIN_LOD, sampler.get_min_lod()); glTexParameterf(target, GL_TEXTURE_MAX_LOD, sampler.get_max_lod()); glTexParameterf(target, GL_TEXTURE_LOD_BIAS, sampler.get_lod_bias()); diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 03e8e2c8a5..3a7f5ddba7 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -184,6 +184,8 @@ typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, typedef void (APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); typedef void (APIENTRYP PFNGLVERTEXATTRIBLPOINTERPROC) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORPROC) (GLuint index, GLuint divisor); +typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); +typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); #endif // OPENGLES_1 #ifndef OPENGLES typedef void (APIENTRYP PFNGLGENSAMPLERSPROC) (GLsizei count, GLuint *samplers); @@ -194,8 +196,6 @@ typedef void (APIENTRYP PFNGLSAMPLERPARAMETERIVPROC) (GLuint sampler, GLenum pna typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFPROC) (GLuint sampler, GLenum pname, GLfloat param); typedef void (APIENTRYP PFNGLSAMPLERPARAMETERFVPROC) (GLuint sampler, GLenum pname, const GLfloat *param); typedef void (APIENTRYP PFNGLPROGRAMPARAMETERIEXTPROC) (GLuint program, GLenum pname, GLint value); -typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); -typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, GLsizei primcount); typedef void (APIENTRYP PFNGLCLEARTEXIMAGEPROC) (GLuint texture, GLint level, GLenum format, GLenum type, const void *data); typedef void (APIENTRYP PFNGLCLEARTEXSUBIMAGEPROC) (GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *data); typedef void (APIENTRYP PFNGLBINDTEXTURESPROC) (GLuint first, GLsizei count, const GLuint *textures); @@ -281,15 +281,19 @@ public: bool force); virtual void end_draw_primitives(); +#ifndef OPENGLES void issue_memory_barrier(GLbitfield barrier); +#endif virtual TextureContext *prepare_texture(Texture *tex, int view); virtual bool update_texture(TextureContext *tc, bool force); virtual void release_texture(TextureContext *tc); virtual bool extract_texture_data(Texture *tex); +#ifndef OPENGLES virtual SamplerContext *prepare_sampler(const SamplerState &sampler); virtual void release_sampler(SamplerContext *sc); +#endif virtual GeomContext *prepare_geom(Geom *geom); virtual void release_geom(GeomContext *gc); @@ -318,12 +322,16 @@ public: const GeomPrimitivePipelineReader *reader, bool force); +#ifndef OPENGLES virtual void begin_occlusion_query(); virtual PT(OcclusionQueryContext) end_occlusion_query(); +#endif virtual PT(TimerQueryContext) issue_timer_query(int pstats_index); +#ifndef OPENGLES virtual void dispatch_compute(int size_x, int size_y, int size_z); +#endif virtual PT(GeomMunger) make_geom_munger(const RenderState *state, Thread *current_thread); @@ -337,6 +345,7 @@ public: virtual bool framebuffer_copy_to_ram (Texture *tex, int view, int z, const DisplayRegion *dr, const RenderBuffer &rb); +#ifndef OPENGLES_2 void apply_fog(Fog *fog); virtual void bind_light(PointLight *light_obj, const NodePath &light, @@ -345,6 +354,7 @@ public: int light_id); virtual void bind_light(Spotlight *light_obj, const NodePath &light, int light_id); +#endif void print_gfx_visual(); @@ -380,18 +390,26 @@ protected: void do_issue_rescale_normal(); void do_issue_color_write(); void do_issue_depth_test(); +#ifndef OPENGLES_2 void do_issue_alpha_test(); +#endif void do_issue_depth_write(); void do_issue_cull_face(); +#ifndef OPENGLES_2 void do_issue_fog(); +#endif void do_issue_depth_offset(); void do_issue_shade_model(); void do_issue_shader(bool state_has_changed = false); +#ifndef OPENGLES_2 void do_issue_material(); +#endif void do_issue_texture(); void do_issue_blending(); +#ifndef OPENGLES_2 void do_issue_tex_gen(); void do_issue_tex_matrix(); +#endif void do_issue_stencil(); void do_issue_scissor(); @@ -414,6 +432,8 @@ protected: virtual void *do_get_extension_func(const char *name); virtual void reissue_transforms(); + +#ifndef OPENGLES_2 virtual void enable_lighting(bool enable); virtual void set_ambient_light(const LColor &color); virtual void enable_light(int light_id, bool enable); @@ -424,6 +444,7 @@ protected: virtual void begin_bind_clip_planes(); virtual void bind_clip_plane(const NodePath &plane, int plane_id); virtual void end_bind_clip_planes(); +#endif virtual void free_pointers(); @@ -447,16 +468,21 @@ protected: INLINE void set_color_write_mask(int mask); INLINE void clear_color_write_mask(); +#ifndef OPENGLES_2 INLINE void call_glFogfv(GLenum pname, const LColor &color); INLINE void call_glMaterialfv(GLenum face, GLenum pname, const LColor &color); INLINE void call_glLightfv(GLenum light, GLenum pname, const LVecBase4 &value); INLINE void call_glLightfv(GLenum light, GLenum pname, const LVecBase3 &value); INLINE void call_glLightModelfv(GLenum pname, const LVecBase4 &value); INLINE void call_glTexEnvfv(GLenum target, GLenum pname, const LVecBase4 &value); +#endif + INLINE void call_glTexParameterfv(GLenum target, GLenum pname, const LVecBase4 &value); +#ifndef OPENGLES_2 INLINE GLenum get_light_id(int index) const; INLINE GLenum get_clip_plane_id(int index) const; +#endif void set_draw_buffer(int rbtype); void set_read_buffer(int rbtype); @@ -485,10 +511,12 @@ protected: static GLenum get_usage(Geom::UsageHint usage_hint); void unbind_buffers(); +#ifndef OPENGLES_2 void disable_standard_vertex_arrays(); bool update_standard_vertex_arrays(bool force); void disable_standard_texture_bindings(); void update_standard_texture_bindings(); +#endif #ifndef NDEBUG void update_show_usage_texture_bindings(int show_stage_index); @@ -570,7 +598,7 @@ protected: ShaderContext *_texture_binding_shader_context; #endif #ifdef OPENGLES_2 - static PT(Shader) _default_shader; + static PT(Shader) _default_shader; #endif #ifdef HAVE_CG @@ -640,21 +668,25 @@ public: PFNGLWEIGHTDVARBPROC _glWeightdv; bool _supports_matrix_palette; -#ifdef OPENGLES +#ifdef OPENGLES_1 PFNGLCURRENTPALETTEMATRIXOESPROC _glCurrentPaletteMatrix; PFNGLMATRIXINDEXPOINTEROESPROC _glMatrixIndexPointer; -#else +#endif +#ifndef OPENGLES PFNGLCURRENTPALETTEMATRIXARBPROC _glCurrentPaletteMatrix; PFNGLMATRIXINDEXPOINTERARBPROC _glMatrixIndexPointer; PFNGLMATRIXINDEXUIVARBPROC _glMatrixIndexuiv; #endif - bool _supports_draw_range_elements; +#ifndef OPENGLES PFNGLDRAWRANGEELEMENTSPROC _glDrawRangeElements; +#endif +#ifndef OPENGLES_1 PFNGLTEXIMAGE3DPROC_P _glTexImage3D; PFNGLTEXSUBIMAGE3DPROC _glTexSubImage3D; PFNGLCOPYTEXSUBIMAGE3DPROC _glCopyTexSubImage3D; +#endif bool _supports_tex_storage; PFNGLTEXSTORAGE1DPROC _glTexStorage1D; @@ -678,8 +710,9 @@ public: bool _supports_rescale_normal; bool _supports_packed_dabc; - bool _supports_multitexture; PFNGLACTIVETEXTUREPROC _glActiveTexture; +#ifndef OPENGLES_2 + bool _supports_multitexture; PFNGLCLIENTACTIVETEXTUREPROC _glClientActiveTexture; PFNGLMULTITEXCOORD1FPROC _glMultiTexCoord1f; PFNGLMULTITEXCOORD2FPROC _glMultiTexCoord2f; @@ -689,6 +722,7 @@ public: PFNGLMULTITEXCOORD2DPROC _glMultiTexCoord2d; PFNGLMULTITEXCOORD3DPROC _glMultiTexCoord3d; PFNGLMULTITEXCOORD4DPROC _glMultiTexCoord4d; +#endif bool _supports_buffers; PFNGLGENBUFFERSPROC _glGenBuffers; @@ -798,7 +832,9 @@ public: PFNGLVERTEXATTRIBIPOINTERPROC _glVertexAttribIPointer; PFNGLVERTEXATTRIBLPOINTERPROC _glVertexAttribLPointer; PFNGLVERTEXATTRIBDIVISORPROC _glVertexAttribDivisor; -#endif // OPENGLES_1 + PFNGLDRAWARRAYSINSTANCEDPROC _glDrawArraysInstanced; + PFNGLDRAWELEMENTSINSTANCEDPROC _glDrawElementsInstanced; +#endif // !OPENGLES_1 #ifndef OPENGLES PFNGLGENSAMPLERSPROC _glGenSamplers; PFNGLDELETESAMPLERSPROC _glDeleteSamplers; @@ -809,8 +845,6 @@ public: PFNGLSAMPLERPARAMETERFVPROC _glSamplerParameterfv; PFNGLPROGRAMPARAMETERIPROC _glProgramParameteri; PFNGLPATCHPARAMETERIPROC _glPatchParameteri; - PFNGLDRAWARRAYSINSTANCEDPROC _glDrawArraysInstanced; - PFNGLDRAWELEMENTSINSTANCEDPROC _glDrawElementsInstanced; PFNGLBINDTEXTURESPROC _glBindTextures; PFNGLBINDSAMPLERSPROC _glBindSamplers; PFNGLBINDIMAGETEXTUREPROC _glBindImageTexture; @@ -828,7 +862,7 @@ public: PFNGLMAKETEXTUREHANDLENONRESIDENTPROC _glMakeTextureHandleNonResident; PFNGLUNIFORMHANDLEUI64PROC _glUniformHandleui64; PFNGLUNIFORMHANDLEUI64VPROC _glUniformHandleui64v; -#endif // OPENGLES +#endif // !OPENGLES GLenum _edge_clamp; GLenum _border_clamp; @@ -836,7 +870,7 @@ public: GLenum _mirror_clamp; GLenum _mirror_edge_clamp; GLenum _mirror_border_clamp; -#ifndef OPENGLES +#ifndef OPENGLES_1 GLsizei _instance_count; #endif diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 1b66f6172a..eb31a08127 100755 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -196,6 +196,7 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext _glgsg = glgsg; _glsl_program = 0; _uses_standard_vertex_arrays = false; + _has_divisor = false; nassertv(s->get_language() == Shader::SL_GLSL); @@ -537,8 +538,8 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext continue; } case GL_INT_SAMPLER_2D: case GL_UNSIGNED_INT_SAMPLER_2D: - case GL_SAMPLER_2D_SHADOW: #endif + case GL_SAMPLER_2D_SHADOW: case GL_SAMPLER_2D: { _glgsg->_glUniform1i(p, s->_tex_spec.size()); Shader::ShaderTexSpec bind; @@ -553,13 +554,18 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext case GL_UNSIGNED_INT_SAMPLER_3D: #endif case GL_SAMPLER_3D: { - _glgsg->_glUniform1i(p, s->_tex_spec.size()); - Shader::ShaderTexSpec bind; - bind._id = arg_id; - bind._name = InternalName::make(param_name); - bind._desired_type = Texture::TT_3d_texture; - bind._stage = texunitno++; - s->_tex_spec.push_back(bind); + if (_glgsg->_supports_3d_texture) { + _glgsg->_glUniform1i(p, s->_tex_spec.size()); + Shader::ShaderTexSpec bind; + bind._id = arg_id; + bind._name = InternalName::make(param_name); + bind._desired_type = Texture::TT_3d_texture; + bind._stage = texunitno++; + s->_tex_spec.push_back(bind); + } else { + GLCAT.error() + << "GLSL shader uses 3D texture, which is unsupported by the driver.\n"; + } continue; } #ifndef OPENGLES case GL_INT_SAMPLER_CUBE: @@ -567,26 +573,36 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext case GL_SAMPLER_CUBE_SHADOW: #endif case GL_SAMPLER_CUBE: { - _glgsg->_glUniform1i(p, s->_tex_spec.size()); - Shader::ShaderTexSpec bind; - bind._id = arg_id; - bind._name = InternalName::make(param_name); - bind._desired_type = Texture::TT_cube_map; - bind._stage = texunitno++; - s->_tex_spec.push_back(bind); + if (_glgsg->_supports_cube_map) { + _glgsg->_glUniform1i(p, s->_tex_spec.size()); + Shader::ShaderTexSpec bind; + bind._id = arg_id; + bind._name = InternalName::make(param_name); + bind._desired_type = Texture::TT_cube_map; + bind._stage = texunitno++; + s->_tex_spec.push_back(bind); + } else { + GLCAT.error() + << "GLSL shader uses cube map, which is unsupported by the driver.\n"; + } continue; } #ifndef OPENGLES case GL_INT_SAMPLER_2D_ARRAY: case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: case GL_SAMPLER_2D_ARRAY_SHADOW: case GL_SAMPLER_2D_ARRAY: { - _glgsg->_glUniform1i(p, s->_tex_spec.size()); - Shader::ShaderTexSpec bind; - bind._id = arg_id; - bind._name = InternalName::make(param_name); - bind._desired_type = Texture::TT_2d_texture_array; - bind._stage = texunitno++; - s->_tex_spec.push_back(bind); + if (_glgsg->_supports_2d_texture_array) { + _glgsg->_glUniform1i(p, s->_tex_spec.size()); + Shader::ShaderTexSpec bind; + bind._id = arg_id; + bind._name = InternalName::make(param_name); + bind._desired_type = Texture::TT_2d_texture_array; + bind._stage = texunitno++; + s->_tex_spec.push_back(bind); + } else { + GLCAT.error() + << "GLSL shader uses 2D texture array, which is unsupported by the driver.\n"; + } continue; } #endif case GL_FLOAT_MAT2: @@ -1202,7 +1218,7 @@ disable_shader_vertex_arrays() { for (int i=0; i<(int)_shader->_var_spec.size(); i++) { const Shader::ShaderVarSpec &bind = _shader->_var_spec[i]; const GLint p = _glsl_parameter_map[bind._id._seqno]; - if (_glgsg->_supports_vertex_attrib_divisor) { + if (_has_divisor) { _glgsg->_glVertexAttribDivisor(p, 0); } for (int i = 0; i < bind._elements; ++i) { @@ -1291,6 +1307,7 @@ update_shader_vertex_arrays(ShaderContext *prev, bool force) { if (_glgsg->_supports_vertex_attrib_divisor) { _glgsg->_glVertexAttribDivisor(p, divisor); + _has_divisor = true; } ++p; @@ -1342,22 +1359,32 @@ disable_shader_texture_bindings() { _glgsg->_glActiveTexture(GL_TEXTURE0 + i); + switch (_shader->_tex_spec[i]._desired_type) { + case Texture::TT_1d_texture: #ifndef OPENGLES - glBindTexture(GL_TEXTURE_1D, 0); -#endif // OPENGLES - glBindTexture(GL_TEXTURE_2D, 0); -#ifndef OPENGLES_1 - if (_glgsg->_supports_3d_texture) { - glBindTexture(GL_TEXTURE_3D, 0); - } -#endif // OPENGLES_1 -#ifndef OPENGLES - if (_glgsg->_supports_2d_texture_array) { - glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, 0); - } + glBindTexture(GL_TEXTURE_1D, 0); #endif - if (_glgsg->_supports_cube_map) { + break; + + case Texture::TT_2d_texture: + glBindTexture(GL_TEXTURE_2D, 0); + break; + + case Texture::TT_3d_texture: +#ifndef OPENGLES_1 + glBindTexture(GL_TEXTURE_3D, 0); +#endif + break; + + case Texture::TT_2d_texture_array: +#ifndef OPENGLES + glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, 0); +#endif + break; + + case Texture::TT_cube_map: glBindTexture(GL_TEXTURE_CUBE_MAP, 0); + break; } } diff --git a/panda/src/glstuff/glShaderContext_src.h b/panda/src/glstuff/glShaderContext_src.h index 19c7190bcd..ae8e6b3851 100755 --- a/panda/src/glstuff/glShaderContext_src.h +++ b/panda/src/glstuff/glShaderContext_src.h @@ -72,6 +72,7 @@ private: CLP(GraphicsStateGuardian) *_glgsg; bool _uses_standard_vertex_arrays; + bool _has_divisor; void glsl_report_shader_errors(GLuint shader, Shader::ShaderType type, bool fatal); void glsl_report_program_errors(GLuint program, bool fatal);