From d3052b02575db4a9413bb2868b204e8da88acd22 Mon Sep 17 00:00:00 2001
Message-Id: <d3052b02575db4a9413bb2868b204e8da88acd22.1423165018.git.fireclawthefox@gmail.com>
From: fireclaw <fireclawthefox@gmail.com>
Date: Sun, 1 Feb 2015 14:31:15 +0100
Subject: [PATCH] Fix GLES

add and change #ifndef/#ifdef blocks for OPENGLES where necessary
---
 panda/src/gles2gsg/gles2gsg.h                     |   4 +-
 panda/src/gles2gsg/panda_esgl2ext.h               |  73 ++++++++-------
 panda/src/glstuff/glGraphicsBuffer_src.cxx        |   2 +-
 panda/src/glstuff/glGraphicsStateGuardian_src.cxx | 103 +++++++++++++++-------
 panda/src/glstuff/glSamplerContext_src.cxx        |   6 ++
 panda/src/glstuff/glShaderContext_src.cxx         |   8 +-
 6 files changed, 129 insertions(+), 67 deletions(-)

diff --git a/panda/src/gles2gsg/gles2gsg.h b/panda/src/gles2gsg/gles2gsg.h
index cd5444c..1c33932 100644
--- a/panda/src/gles2gsg/gles2gsg.h
+++ b/panda/src/gles2gsg/gles2gsg.h
@@ -57,7 +57,7 @@
 //  #include <GLES2/gl2ext.h>
 #endif
 
-#include "panda_esgl2ext.h" 
+#include "panda_esgl2ext.h"
 
 // This helps to keep the source clean of hundreds of #ifdefs.
 typedef char GLchar;
@@ -100,12 +100,14 @@ typedef char GLchar;
 #define GL_RGBA16F GL_RGBA16F_EXT
 #define GL_RGB32F GL_RGB32F_EXT
 #define GL_RGBA32F GL_RGBA32F_EXT
+/* These are already defined in panda_esgl2ext.h
 #define GL_DEBUG_SEVERITY_HIGH GL_DEBUG_SEVERITY_HIGH_KHR
 #define GL_DEBUG_SEVERITY_MEDIUM GL_DEBUG_SEVERITY_MEDIUM_KHR
 #define GL_DEBUG_SEVERITY_LOW GL_DEBUG_SEVERITY_LOW_KHR
 #define GL_DEBUG_SEVERITY_NOTIFICATION GL_DEBUG_SEVERITY_NOTIFICATION_KHR
 #define GL_DEBUG_OUTPUT_SYNCHRONOUS GL_DEBUG_OUTPUT_SYNCHRONOUS_KHR
 #define GL_FRAMEBUFFER_SRGB GL_FRAMEBUFFER_SRGB_EXT
+*/
 #define GL_SRGB GL_SRGB_EXT
 #define GL_SRGB_ALPHA GL_SRGB_ALPHA_EXT
 #define GL_SRGB8 GL_SRGB8_EXT
diff --git a/panda/src/gles2gsg/panda_esgl2ext.h b/panda/src/gles2gsg/panda_esgl2ext.h
index 7e6ff9c..7e4fb53 100644
--- a/panda/src/gles2gsg/panda_esgl2ext.h
+++ b/panda/src/gles2gsg/panda_esgl2ext.h
@@ -94,23 +94,23 @@ typedef void* GLeglImageOES;
 #endif
 
 /* GL_OES_required_internalformat */
-#ifndef GL_OES_required_internalformat 
+#ifndef GL_OES_required_internalformat
 #define GL_ALPHA8_OES                                           0x803C
 #define GL_DEPTH_COMPONENT16_OES                                0x81A5
-/* reuse GL_DEPTH_COMPONENT24_OES */                            
-/* reuse GL_DEPTH24_STENCIL8_OES */                             
-/* reuse GL_DEPTH_COMPONENT32_OES */                            
+/* reuse GL_DEPTH_COMPONENT24_OES */
+/* reuse GL_DEPTH24_STENCIL8_OES */
+/* reuse GL_DEPTH_COMPONENT32_OES */
 #define GL_LUMINANCE4_ALPHA4_OES                                0x8043
 #define GL_LUMINANCE8_ALPHA8_OES                                0x8045
 #define GL_LUMINANCE8_OES                                       0x8040
 #define GL_RGBA4_OES                                            0x8056
 #define GL_RGB5_A1_OES                                          0x8057
 #define GL_RGB565_OES                                           0x8D62
-/* reuse GL_RGB8_OES */                              
-/* reuse GL_RGBA8_OES */  
+/* reuse GL_RGB8_OES */
+/* reuse GL_RGBA8_OES */
 /* reuse GL_RGB10_EXT */
 /* reuse GL_RGB10_A2_EXT */
-#endif 
+#endif
 
 /* GL_OES_rgb8_rgba8 */
 #ifndef GL_OES_rgb8_rgba8
@@ -210,9 +210,9 @@ typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLen
 #define GL_SHADER                                               0x82E1
 #define GL_PROGRAM                                              0x82E2
 #define GL_QUERY                                                0x82E3
-/* PROGRAM_PIPELINE only in GL */                               
+/* PROGRAM_PIPELINE only in GL */
 #define GL_SAMPLER                                              0x82E6
-/* DISPLAY_LIST only in GL */                                   
+/* DISPLAY_LIST only in GL */
 #define GL_MAX_LABEL_LENGTH                                     0x82E8
 #define GL_MAX_DEBUG_MESSAGE_LENGTH                             0x9143
 #define GL_MAX_DEBUG_LOGGED_MESSAGES                            0x9144
@@ -310,33 +310,33 @@ typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLen
 #endif
 
 /* GL_ANGLE_instanced_arrays */
-#ifndef GL_ANGLE_instanced_arrays 
+#ifndef GL_ANGLE_instanced_arrays
 #define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE                    0x88FE
 #endif
 
 /* GL_ANGLE_pack_reverse_row_order */
-#ifndef GL_ANGLE_pack_reverse_row_order 
+#ifndef GL_ANGLE_pack_reverse_row_order
 #define GL_PACK_REVERSE_ROW_ORDER_ANGLE                         0x93A4
 #endif
 
 /* GL_ANGLE_texture_compression_dxt3 */
-#ifndef GL_ANGLE_texture_compression_dxt3 
+#ifndef GL_ANGLE_texture_compression_dxt3
 #define GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE                      0x83F2
 #endif
 
 /* GL_ANGLE_texture_compression_dxt5 */
-#ifndef GL_ANGLE_texture_compression_dxt5 
+#ifndef GL_ANGLE_texture_compression_dxt5
 #define GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE                      0x83F3
 #endif
 
 /* GL_ANGLE_texture_usage */
-#ifndef GL_ANGLE_texture_usage 
+#ifndef GL_ANGLE_texture_usage
 #define GL_TEXTURE_USAGE_ANGLE                                  0x93A2
 #define GL_FRAMEBUFFER_ATTACHMENT_ANGLE                         0x93A3
 #endif
 
 /* GL_ANGLE_translated_shader_source */
-#ifndef GL_ANGLE_translated_shader_source 
+#ifndef GL_ANGLE_translated_shader_source
 #define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE                0x93A0
 #endif
 
@@ -346,7 +346,7 @@ typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLen
 
 /* GL_APPLE_copy_texture_levels */
 /* No new tokens introduced by this extension. */
-    
+
 /* GL_APPLE_framebuffer_multisample */
 #ifndef GL_APPLE_framebuffer_multisample
 #define GL_RENDERBUFFER_SAMPLES_APPLE                           0x8CAB
@@ -371,9 +371,9 @@ typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLen
 #ifndef __gl3_h_
 /* These types are defined with reference to <inttypes.h>
  * in the Apple extension spec, but here we use the Khronos
- * portable types in khrplatform.h, and assume those types 
+ * portable types in khrplatform.h, and assume those types
  * are always defined.
- * If any other extensions using these types are defined, 
+ * If any other extensions using these types are defined,
  * the typedefs must move out of this block and be shared.
  */
 typedef khronos_int64_t GLint64;
@@ -479,7 +479,7 @@ typedef struct __GLsync *GLsync;
 /* GL_EXT_multisampled_render_to_texture */
 #ifndef GL_EXT_multisampled_render_to_texture
 #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT           0x8D6C
-/* reuse values from GL_EXT_framebuffer_multisample (desktop extension) */ 
+/* reuse values from GL_EXT_framebuffer_multisample (desktop extension) */
 #define GL_RENDERBUFFER_SAMPLES_EXT                             0x8CAB
 #define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT               0x8D56
 #define GL_MAX_SAMPLES_EXT                                      0x8D57
@@ -506,6 +506,14 @@ typedef struct __GLsync *GLsync;
 #define GL_QUERY_RESULT_AVAILABLE_EXT                           0x8867
 #endif
 
+/* GL_EXT_pvrtc_sRGB */
+#ifndef GL_EXT_pvrtc_sRGB
+#define GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT                     0x8A54
+#define GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT                     0x8A55
+#define GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT               0x8A56
+#define GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT               0x8A57
+#endif
+
 /* GL_EXT_read_format_bgra */
 #ifndef GL_EXT_read_format_bgra
 #define GL_BGRA_EXT                                             0x80E1
@@ -587,10 +595,10 @@ typedef struct __GLsync *GLsync;
 /* GL_EXT_texture_storage */
 #ifndef GL_EXT_texture_storage
 #define GL_TEXTURE_IMMUTABLE_FORMAT_EXT                         0x912F
-#define GL_ALPHA8_EXT                                           0x803C  
+#define GL_ALPHA8_EXT                                           0x803C
 #define GL_LUMINANCE8_EXT                                       0x8040
 #define GL_LUMINANCE8_ALPHA8_EXT                                0x8045
-#define GL_RGBA32F_EXT                                          0x8814  
+#define GL_RGBA32F_EXT                                          0x8814
 #define GL_RGB32F_EXT                                           0x8815
 #define GL_ALPHA32F_EXT                                         0x8816
 #define GL_LUMINANCE32F_EXT                                     0x8818
@@ -600,12 +608,12 @@ typedef struct __GLsync *GLsync;
 #define GL_ALPHA16F_EXT                                         0x881C
 #define GL_LUMINANCE16F_EXT                                     0x881E
 #define GL_LUMINANCE_ALPHA16F_EXT                               0x881F
-#define GL_RGB10_A2_EXT                                         0x8059  
+#define GL_RGB10_A2_EXT                                         0x8059
 #define GL_RGB10_EXT                                            0x8052
 #define GL_BGRA8_EXT                                            0x93A1
 #define GL_R8_EXT                                               0x8229
 #define GL_RG8_EXT                                              0x822B
-#define GL_R32F_EXT                                             0x822E  
+#define GL_R32F_EXT                                             0x822E
 #define GL_RG32F_EXT                                            0x8230
 #define GL_R16F_EXT                                             0x822D
 #define GL_RG16F_EXT                                            0x822F
@@ -1077,7 +1085,7 @@ GL_APICALL void GL_APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GL
 GL_APICALL void GL_APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label);
 GL_APICALL void GL_APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label);
 GL_APICALL void GL_APIENTRY glGetPointerv (GLenum pname, void **params);
-#endif 
+#endif
 typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled);
 typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf);
 typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam);
@@ -1166,7 +1174,7 @@ GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleANGLE (GLenum target
 typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEANGLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
 #endif
 
-#ifndef GL_ANGLE_instanced_arrays 
+#ifndef GL_ANGLE_instanced_arrays
 #define GL_ANGLE_instanced_arrays 1
 #ifdef GL_GLEXT_PROTOTYPES
 GL_APICALL void GL_APIENTRY glDrawArraysInstancedANGLE (GLenum mode, GLint first, GLsizei count, GLsizei primcount);
@@ -1179,26 +1187,26 @@ typedef void (GL_APIENTRYP PFLGLVERTEXATTRIBDIVISORANGLEPROC) (GLuint index, GLu
 #endif
 
 /* GL_ANGLE_pack_reverse_row_order */
-#ifndef GL_ANGLE_pack_reverse_row_order 
+#ifndef GL_ANGLE_pack_reverse_row_order
 #define GL_ANGLE_pack_reverse_row_order 1
 #endif
 
 /* GL_ANGLE_texture_compression_dxt3 */
-#ifndef GL_ANGLE_texture_compression_dxt3 
+#ifndef GL_ANGLE_texture_compression_dxt3
 #define GL_ANGLE_texture_compression_dxt3 1
 #endif
 
 /* GL_ANGLE_texture_compression_dxt5 */
-#ifndef GL_ANGLE_texture_compression_dxt5 
+#ifndef GL_ANGLE_texture_compression_dxt5
 #define GL_ANGLE_texture_compression_dxt5 1
 #endif
 
 /* GL_ANGLE_texture_usage */
-#ifndef GL_ANGLE_texture_usage 
+#ifndef GL_ANGLE_texture_usage
 #define GL_ANGLE_texture_usage 1
 #endif
 
-#ifndef GL_ANGLE_translated_shader_source 
+#ifndef GL_ANGLE_translated_shader_source
 #define GL_ANGLE_translated_shader_source 1
 #ifdef GL_GLEXT_PROTOTYPES
 GL_APICALL void GL_APIENTRY glGetTranslatedShaderSourceANGLE (GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source);
@@ -1689,6 +1697,11 @@ typedef void (GL_APIENTRYP PFNGLREADBUFFERNVPROC) (GLenum mode);
 /* GL_NV_read_stencil */
 #ifndef GL_NV_read_stencil
 #define GL_NV_read_stencil 1
+/* GL_NV_sRGB_formats */
+#ifndef GL_NV_sRGB_formats
+#define GL_NV_sRGB_formats 1
+#define GL_SLUMINANCE8_NV                                       0x8C47
+#endif
 #endif
 
 /* GL_NV_texture_compression_s3tc_update */
diff --git a/panda/src/glstuff/glGraphicsBuffer_src.cxx b/panda/src/glstuff/glGraphicsBuffer_src.cxx
index 038bb6b..08c30ef 100644
--- a/panda/src/glstuff/glGraphicsBuffer_src.cxx
+++ b/panda/src/glstuff/glGraphicsBuffer_src.cxx
@@ -1675,7 +1675,7 @@ resolve_multisamples() {
                               GL_NEAREST);
   }
   // Now handle the other color buffers.
-#ifndef OPENGLES_1
+#ifndef OPENGLES
   int next = GL_COLOR_ATTACHMENT1_EXT;
   if (_fb_properties.is_stereo()) {
     glReadBuffer(next);
diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx
index 4784fec..7928ebe 100644
--- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx
+++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx
@@ -2576,11 +2576,13 @@ clear_before_callback() {
   // makes this assumption.
   _glActiveTexture(GL_TEXTURE0);
 
+#ifndef OPENGLES
   // Clear the bound sampler object, so that we do not inadvertently
   // override the callback's desired sampler settings.
   if (_supports_sampler_objects) {
     _glBindSampler(0, 0);
   }
+#endif
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -2721,7 +2723,7 @@ begin_frame(Thread *current_thread) {
   }*/
 #endif
 
-#ifndef OPENGLES_1
+#ifndef OPENGLES
   if (_current_properties->get_srgb_color()) {
     glEnable(GL_FRAMEBUFFER_SRGB);
   }
@@ -2779,7 +2781,7 @@ void CLP(GraphicsStateGuardian)::
 end_frame(Thread *current_thread) {
   report_my_gl_errors();
 
-#ifndef OPENGLES_1
+#ifndef OPENGLES
   if (_current_properties->get_srgb_color()) {
     glDisable(GL_FRAMEBUFFER_SRGB);
   }
@@ -7415,7 +7417,7 @@ get_external_image_format(Texture *tex) const {
       break;
 
     case Texture::CM_dxt1:
-#ifndef OPENGLES_1
+#ifndef OPENGLES
       if (format == Texture::F_srgb_alpha) {
         return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
       } else if (format == Texture::F_srgb) {
@@ -7730,7 +7732,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
 #endif
 
     case Texture::CM_dxt1:
-#ifndef OPENGLES_1
+#ifndef OPENGLES
       if (format == Texture::F_srgb_alpha) {
         return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
       } else if (format == Texture::F_srgb) {
@@ -7808,17 +7810,17 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
   case Texture::F_color_index:
     return GL_COLOR_INDEX;
 #endif
-
   case Texture::F_depth_stencil:
     if (_supports_depth_stencil) {
-#ifndef OPENGLES_1
+#ifndef OPENGLES
       if (tex->get_component_type() == Texture::T_float) {
         return GL_DEPTH32F_STENCIL8;
-      } else
-#endif
-      {
+      } else {
         return force_sized ? GL_DEPTH24_STENCIL8 : GL_DEPTH_STENCIL;
       }
+#else
+      return force_sized ? GL_DEPTH24_STENCIL8_OES : GL_DEPTH_STENCIL;
+#endif
     }
     // Fall through.
 
@@ -7868,16 +7870,19 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
 
   case Texture::F_rgba:
   case Texture::F_rgbm:
-#ifndef OPENGLES_1
+#ifndef OPENGLES
     if (tex->get_component_type() == Texture::T_float) {
       return GL_RGBA16F;
     } else if (tex->get_component_type() == Texture::T_unsigned_short) {
       return GL_RGBA16;
-    } else
-#endif
-    {
+    } else {
       return force_sized ? GL_RGBA8 : GL_RGBA;
     }
+#else
+    {
+      return force_sized ? GL_RGBA8_OES : GL_RGBA;
+    }
+#endif
 
   case Texture::F_rgba4:
     return GL_RGBA4;
@@ -7886,8 +7891,10 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
   case Texture::F_rgba8:
     return GL_RGBA8_OES;
   case Texture::F_rgba12:
-    return force_sized ? GL_RGBA8 : GL_RGBA;
+    return force_sized ? GL_RGBA8_OES : GL_RGBA;
 #else
+  case Texture::F_rgba12:
+    return force_sized ? GL_RGBA8 : GL_RGBA;
   case Texture::F_rgba8:
     return GL_RGBA8;
   case Texture::F_r8i:
@@ -7916,8 +7923,6 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
     }
   case Texture::F_rgba12:
     return GL_RGBA12;
-#endif  // OPENGLES
-#ifndef OPENGLES_1
   case Texture::F_rgba16:
     if (tex->get_component_type() == Texture::T_float) {
       return GL_RGBA16F;
@@ -7932,7 +7937,11 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
     if (tex->get_component_type() == Texture::T_float) {
       return GL_RGB16F;
     } else {
+#ifndef OPENGLES
       return force_sized ? GL_RGB8 : GL_RGB;
+#else
+      return force_sized ? GL_RGB8_OES : GL_RGB;
+#endif
     }
 
   case Texture::F_rgb5:
@@ -7949,7 +7958,13 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
   case Texture::F_rgb8:
     return GL_RGB8_OES;
   case Texture::F_rgb12:
+    return force_sized ? GL_RGB8_OES : GL_RGB;
+#endif
+#ifndef OPENGLES
+  case Texture::F_rgb12:
     return force_sized ? GL_RGB8 : GL_RGB;
+#endif
+#ifdef OPENGLES
   case Texture::F_rgb16:
     return GL_RGB16F;
 #else
@@ -7992,7 +8007,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
     }
 #endif
 
-#ifndef OPENGLES_1
+#ifndef OPENGLES
   case Texture::F_r32:
     return GL_R32F;
   case Texture::F_rg32:
@@ -8002,11 +8017,8 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
   case Texture::F_green:
   case Texture::F_blue:
     return force_sized ? GL_R8 : GL_RED;
-#endif
-
   case Texture::F_alpha:
     return force_sized ? GL_ALPHA8 : GL_ALPHA;
-
   case Texture::F_luminance:
     if (tex->get_component_type() == Texture::T_float) {
       return GL_LUMINANCE16F_ARB;
@@ -8022,8 +8034,22 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
     } else {
       return force_sized ? GL_LUMINANCE8_ALPHA8 : GL_LUMINANCE_ALPHA;
     }
+#endif
+#ifdef OPENGLES_2
+  case Texture::F_alpha:
+    return force_sized ? GL_ALPHA8_OES : GL_ALPHA;
+  case Texture::F_luminance:
+    return force_sized ? GL_LUMINANCE8_OES : GL_LUMINANCE;
+  case Texture::F_luminance_alpha:
+  case Texture::F_luminance_alphamask:
+    if (tex->get_component_type() == Texture::T_float || tex->get_component_type() == Texture::T_unsigned_short) {
+      return GL_LUMINANCE_ALPHA16F_EXT;
+    } else {
+      return force_sized ? GL_LUMINANCE8_ALPHA8_OES : GL_LUMINANCE_ALPHA;
+    }
+#endif
 
-#ifndef OPENGLES_1
+#ifndef OPENGLES
   case Texture::F_srgb:
     return GL_SRGB8;
   case Texture::F_srgb_alpha:
@@ -8032,9 +8058,6 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
     return GL_SLUMINANCE8;
   case Texture::F_sluminance_alpha:
     return GL_SLUMINANCE8_ALPHA8;
-#endif
-
-#ifndef OPENGLES
   case Texture::F_r32i:
     return GL_R32I;
 #endif
@@ -8043,7 +8066,11 @@ get_internal_image_format(Texture *tex, bool force_sized) const {
     GLCAT.error()
       << "Invalid image format in get_internal_image_format(): "
       << (int)tex->get_format() << "\n";
+#ifndef OPENGLES
     return force_sized ? GL_RGB8 : GL_RGB;
+#else
+    return force_sized ? GL_RGB8_OES : GL_RGB;
+#endif
   }
 }
 
@@ -10055,7 +10082,9 @@ apply_sampler(GLuint unit, const SamplerState &sampler, TextureContext *tc) {
 
     gsc->enqueue_lru(&_prepared_objects->_sampler_object_lru);
 
+#ifndef OPENGLES
     _glBindSampler(unit, gsc->_index);
+#endif
 
     if (GLCAT.is_spam()) {
       GLCAT.spam()
@@ -10646,9 +10675,10 @@ upload_texture_image(CLP(TextureContext) *gtc, bool needs_reload,
             if (_supports_clear_texture) {
               // We can do that with the convenient glClearTexImage function.
               string clear_data = tex->get_clear_data();
-
+#ifndef OPENGLES
               _glClearTexImage(gtc->_index, n - mipmap_bias, external_format,
                                component_type, (void *)clear_data.data());
+#endif
               continue;
             } else {
               // Ask the Texture class to create the mipmap level in RAM.
@@ -10696,8 +10726,6 @@ upload_texture_image(CLP(TextureContext) *gtc, bool needs_reload,
 #endif
 #ifndef OPENGLES
       case GL_TEXTURE_3D:
-#endif
-#ifndef OPENGLES_1
         if (_supports_3d_texture) {
           if (image_compression == Texture::CM_off) {
             _glTexSubImage3D(page_target, n - mipmap_bias, 0, 0, 0, width, height, depth,
@@ -10721,8 +10749,6 @@ upload_texture_image(CLP(TextureContext) *gtc, bool needs_reload,
                                      external_format, view_size, image_ptr);
         }
         break;
-#endif
-#ifndef OPENGLES
       case GL_TEXTURE_2D_ARRAY_EXT:
         if (_supports_2d_texture_array) {
           if (image_compression == Texture::CM_off) {
@@ -11280,11 +11306,13 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
     break;
 #endif
   case GL_DEPTH_STENCIL:
+#ifndef OPENGLES_2
   case GL_DEPTH24_STENCIL8:
+#endif
     type = Texture::T_unsigned_int_24_8;
     format = Texture::F_depth_stencil;
     break;
-#ifndef OPENGLES_1
+#ifndef OPENGLES
   case GL_DEPTH32F_STENCIL8:
     type = Texture::T_float;
     format = Texture::F_depth_stencil;
@@ -11395,6 +11423,7 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
     type = Texture::T_float;
     format = Texture::F_rgb32;
     break;
+#ifndef OPENGLES_2
   case GL_RG32F:
     type = Texture::T_float;
     format = Texture::F_rg32;
@@ -11404,6 +11433,7 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
     format = Texture::F_r32;
     break;
 #endif
+#endif
 
 #ifndef OPENGLES
   case GL_RGB16:
@@ -11448,18 +11478,22 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
     format = Texture::F_alpha;
     break;
   case GL_LUMINANCE:
+#ifndef OPENGLES
   case GL_LUMINANCE16:
   case GL_LUMINANCE16F_ARB:
+#endif
   case 1:
     format = Texture::F_luminance;
     break;
   case GL_LUMINANCE_ALPHA:
+#ifndef OPENGLES
   case GL_LUMINANCE_ALPHA16F_ARB:
+#endif
   case 2:
     format = Texture::F_luminance_alpha;
     break;
 
-#ifndef OPENGLES_1
+#ifndef OPENGLES
   case GL_SRGB:
   case GL_SRGB8:
     format = Texture::F_srgb;
@@ -11526,7 +11560,7 @@ do_extract_texture_data(CLP(TextureContext) *gtc) {
     format = Texture::F_rgbm;
     compression = Texture::CM_dxt1;
     break;
-#ifndef OPENGLES_1
+#ifndef OPENGLES
   case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
     format = Texture::F_srgb;
     compression = Texture::CM_dxt1;
@@ -11910,6 +11944,7 @@ do_issue_stencil() {
   const StencilAttrib *stencil = (const StencilAttrib *)
     _target_rs->get_attrib(StencilAttrib::get_class_slot());
 
+#ifndef OPENGLES
   if (stencil != (const StencilAttrib *)NULL) {
     // DEBUG
     if (false) {
@@ -11987,6 +12022,7 @@ do_issue_stencil() {
       glDisable(GL_STENCIL_TEST_TWO_SIDE_EXT);
     }
   }
+#endif  // OPENGLES
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -12028,7 +12064,7 @@ do_issue_scissor() {
 
   } else if (_scissor_attrib_active) {
     _scissor_attrib_active = false;
-
+#ifndef OPENGLES
     if (_scissor_array.size() > 0) {
       // Scissoring is enabled on the display region.
       // Revert to the scissor state specified in the DisplayRegion.
@@ -12048,5 +12084,6 @@ do_issue_scissor() {
       glDisable(GL_SCISSOR_TEST);
       _scissor_enabled = false;
     }
+#endif  // OPENGLES
   }
 }
diff --git a/panda/src/glstuff/glSamplerContext_src.cxx b/panda/src/glstuff/glSamplerContext_src.cxx
index 4231bae..9376bcd 100644
--- a/panda/src/glstuff/glSamplerContext_src.cxx
+++ b/panda/src/glstuff/glSamplerContext_src.cxx
@@ -27,7 +27,9 @@ CLP(SamplerContext)(CLP(GraphicsStateGuardian) *glgsg,
   SamplerContext(sampler)
 {
   _glgsg = glgsg;
+#ifndef OPENGLES
   _glgsg->_glGenSamplers(1, &_index);
+#endif
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -38,7 +40,9 @@ CLP(SamplerContext)(CLP(GraphicsStateGuardian) *glgsg,
 CLP(SamplerContext)::
 ~CLP(SamplerContext)() {
   if (_index != 0) {
+#ifndef OPENGLES
     _glgsg->_glDeleteSamplers(1, &_index);
+#endif
     _index = 0;
   }
 }
@@ -74,7 +78,9 @@ evict_lru() {
 void CLP(SamplerContext)::
 reset_data() {
   // Free the sampler resource.
+#ifndef OPENGLES
   _glgsg->_glDeleteSamplers(1, &_index);
+#endif
   _index = 0;
 
   // We still need a valid index number, though, in case we want to
diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx
index 4aca23a..1380c1e 100755
--- a/panda/src/glstuff/glShaderContext_src.cxx
+++ b/panda/src/glstuff/glShaderContext_src.cxx
@@ -754,10 +754,14 @@ CLP(ShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderContext
                        param_type == GL_INT_VEC2 ||
                        param_type == GL_INT_VEC3 ||
                        param_type == GL_INT_VEC4 ||
-                       param_type == GL_UNSIGNED_INT ||
-                       param_type == GL_UNSIGNED_INT_VEC2 ||
+                       param_type == GL_UNSIGNED_INT
+#ifndef OPENGLES
+                       || param_type == GL_UNSIGNED_INT_VEC2 ||
                        param_type == GL_UNSIGNED_INT_VEC3 ||
                        param_type == GL_UNSIGNED_INT_VEC4);
+#else
+                       );
+#endif
 
       if (noprefix.empty()) {
         // Arbitrarily named attribute.
-- 
1.9.1

