OSDN Git Service

es/main: Better glGetString support.
authorChia-I Wu <olvaffe@gmail.com>
Sat, 12 Sep 2009 18:22:38 +0000 (02:22 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Sun, 13 Sep 2009 09:06:21 +0000 (17:06 +0800)
src/mesa/es/main/specials_es1.c
src/mesa/es/main/specials_es2.c

index 8c1edab..1bba8b1 100644 (file)
 extern const GLubyte * GLAPIENTRY _es_GetString(GLenum name);
 
 
-static const char *
+static const GLubyte *
 compute_es_version(void)
 {
+   GET_CURRENT_CONTEXT(ctx);
    static const char es_1_0[] = "OpenGL ES-CM 1.0";
    static const char es_1_1[] = "OpenGL ES-CM 1.1";
+   /* OpenGL ES 1.0 is derived from OpenGL 1.3 */
+   const GLboolean ver_1_0 = (ctx->Extensions.ARB_multisample &&
+                              ctx->Extensions.ARB_multitexture &&
+                              ctx->Extensions.ARB_texture_compression &&
+                              ctx->Extensions.EXT_texture_env_add &&
+                              ctx->Extensions.ARB_texture_env_combine &&
+                              ctx->Extensions.ARB_texture_env_dot3);
+   /* OpenGL ES 1.1 is derived from OpenGL 1.5 */
+   const GLboolean ver_1_1 = (ver_1_0 &&
+                              ctx->Extensions.EXT_point_parameters &&
+                              ctx->Extensions.SGIS_generate_mipmap &&
+                              ctx->Extensions.ARB_vertex_buffer_object);
+   if (ver_1_1)
+      return (const GLubyte *) es_1_1;
+
+   if (!ver_1_0)
+      _mesa_problem(ctx, "Incomplete OpenGL ES 1.0 support.");
+   return (const GLubyte *) es_1_0;
+}
+
+
+static size_t
+append_extension(char **str, const char *ext)
+{
+   char *s = *str;
+   size_t len = strlen(ext);
+
+   if (s) {
+      memcpy(s, ext, len);
+      s[len++] = ' ';
+      s[len] = '\0';
 
-   (void) es_1_0;
-   return es_1_1;
+      *str += len;
+   }
+   else {
+      len++;
+   }
+
+   return len;
 }
 
 
-/**
- * Note: a more dynamic solution would be query the underlying GL
- * and translate extension names...
- */
-static const char *
-extension_string(void)
+static size_t
+make_extension_string(const GLcontext *ctx, char *str)
 {
-   return
-      /* Core additions */
-      "GL_OES_byte_coordinates "
-      "GL_OES_fixed_point "
-      "GL_OES_single_precision "
-      "GL_OES_matrix_get "
-
-      /* 1.1 required extensions */
-      "GL_OES_read_format "
-      "GL_OES_compressed_paletted_texture "
-      "GL_OES_point_size_array "
-      "GL_OES_point_sprite "
-
-      /* 1.1 optional extensions */
-      "GL_OES_draw_texture "
-
-      /* 1.1 deprecated extensions */
-      "GL_OES_query_matrix "
-
-      /* Newer extensions */
-      "GL_OES_blend_equation_separate "
-      "GL_OES_blend_func_separate "
-      "GL_OES_blend_subtract "
-      "GL_OES_depth24 "
-      "GL_OES_depth32 "
-      "GL_OES_element_index_uint "
-      "GL_OES_fbo_render_mipmap "
-      "GL_OES_framebuffer_object "
-      "GL_OES_mapbuffer "
-      "GL_OES_rgb8_rgba8 "
-      "GL_OES_stencil1 "
-      "GL_OES_stencil4 "
-      "GL_OES_stencil8 "
-      "GL_OES_texture_cube_map "
-      "GL_OES_texture_env_crossbar "
-      "GL_OES_texture_mirrored_repeat "
-      "GL_EXT_texture_filter_anisotropic "
-      ;
+   size_t len = 0;
+
+   /* Core additions */
+   len += append_extension(&str, "GL_OES_byte_coordinates");
+   len += append_extension(&str, "GL_OES_fixed_point");
+   len += append_extension(&str, "GL_OES_single_precision");
+   len += append_extension(&str, "GL_OES_matrix_get");
+
+   /* 1.1 required extensions */
+   len += append_extension(&str, "GL_OES_read_format");
+   len += append_extension(&str, "GL_OES_compressed_paletted_texture");
+   len += append_extension(&str, "GL_OES_point_size_array");
+   len += append_extension(&str, "GL_OES_point_sprite");
+
+   /* 1.1 optional extensions */
+   len += append_extension(&str, "GL_OES_draw_texture");
+   /* 1.1 deprecated extensions */
+   len += append_extension(&str, "GL_OES_query_matrix");
+
+   if (ctx->Extensions.EXT_blend_equation_separate)
+      len += append_extension(&str, "GL_OES_blend_equation_separate");
+   if (ctx->Extensions.EXT_blend_func_separate)
+      len += append_extension(&str, "GL_OES_blend_func_separate");
+   if (ctx->Extensions.EXT_blend_subtract)
+      len += append_extension(&str, "GL_OES_blend_subtract");
+
+   if (ctx->Extensions.ARB_texture_cube_map)
+      len += append_extension(&str, "GL_OES_texture_cube_map");
+   if (ctx->Extensions.ARB_texture_env_crossbar)
+      len += append_extension(&str, "GL_OES_texture_env_crossbar");
+   if (ctx->Extensions.ARB_texture_mirrored_repeat)
+      len += append_extension(&str, "GL_OES_texture_mirrored_repeat");
+
+   if (ctx->Extensions.ARB_framebuffer_object) {
+      len += append_extension(&str, "GL_OES_framebuffer_object");
+      len += append_extension(&str, "GL_OES_depth24");
+      len += append_extension(&str, "GL_OES_depth32");
+      len += append_extension(&str, "GL_OES_fbo_render_mipmap");
+      len += append_extension(&str, "GL_OES_rgb8_rgba8");
+      len += append_extension(&str, "GL_OES_stencil1");
+      len += append_extension(&str, "GL_OES_stencil4");
+      len += append_extension(&str, "GL_OES_stencil8");
+   }
+
+   if (ctx->Extensions.EXT_vertex_array)
+      len += append_extension(&str, "GL_OES_element_index_uint");
+   if (ctx->Extensions.ARB_vertex_buffer_object)
+      len += append_extension(&str, "GL_OES_mapbuffer");
+   if (ctx->Extensions.EXT_texture_filter_anisotropic)
+      len += append_extension(&str, "GL_EXT_texture_filter_anisotropic");
+
+   return len;
+}
+
+
+static const GLubyte *
+compute_es_extensions(void)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (!ctx->Extensions.String) {
+      char *s;
+      unsigned int len;
+
+      len = make_extension_string(ctx, NULL);
+      s = (char *) _mesa_malloc(len + 1);
+      if (!s)
+         return NULL;
+      make_extension_string(ctx, s);
+      ctx->Extensions.String = (const GLubyte *) s;
+   }
+
+   return ctx->Extensions.String;
 }
 
 
@@ -96,9 +164,9 @@ _es_GetString(GLenum name)
 {
    switch (name) {
    case GL_VERSION:
-      return (const GLubyte *) compute_es_version();
+      return compute_es_version();
    case GL_EXTENSIONS:
-      return (const GLubyte *) extension_string();
+      return compute_es_extensions();
    default:
       return _mesa_GetString(name);
    }
index c4e4b49..791f178 100644 (file)
 const GLubyte * GLAPIENTRY _es_GetString(GLenum name);
 
 
-static const char *
+static const GLubyte *
 compute_es_version(void)
 {
+   GET_CURRENT_CONTEXT(ctx);
    static const char es_2_0[] = "OpenGL ES 2.0";
-   return es_2_0;
+   /* OpenGL ES 2.0 is derived from OpenGL 2.0 */
+   const GLboolean ver_2_0 = (ctx->Extensions.ARB_multisample &&
+                              ctx->Extensions.ARB_multitexture &&
+                              ctx->Extensions.ARB_texture_compression &&
+                              ctx->Extensions.ARB_texture_cube_map &&
+                              ctx->Extensions.ARB_texture_mirrored_repeat &&
+                              ctx->Extensions.EXT_blend_color &&
+                              ctx->Extensions.EXT_blend_func_separate &&
+                              ctx->Extensions.EXT_blend_minmax &&
+                              ctx->Extensions.EXT_blend_subtract &&
+                              ctx->Extensions.EXT_stencil_wrap &&
+                              ctx->Extensions.ARB_vertex_buffer_object &&
+                              ctx->Extensions.ARB_shader_objects &&
+                              ctx->Extensions.ARB_vertex_shader &&
+                              ctx->Extensions.ARB_fragment_shader &&
+                              ctx->Extensions.ARB_texture_non_power_of_two &&
+                              ctx->Extensions.EXT_blend_equation_separate);
+   if (!ver_2_0)
+      _mesa_problem(ctx, "Incomplete OpenGL ES 2.0 support.");
+   return (const GLubyte *) es_2_0;
 }
 
 
-/**
- * Note: a more dynamic solution would be query the underlying GL
- * and translate extension names...
- */
-static const char *
-extension_string(void)
+static size_t
+append_extension(char **str, const char *ext)
 {
-   return
-      /* Core additions */
-      "GL_OES_single_precision "
-
-      /* Requred extensions */
-      "GL_OES_compressed_paletted_texture "
-
-      /* Normal extensions */
-      "GL_OES_depth24 "
-      "GL_OES_depth32 "
-      "GL_OES_depth_texture "
-      "GL_OES_element_index_uint "
-      "GL_OES_fbo_render_mipmap "
-      "GL_OES_mapbuffer "
-      "GL_OES_packed_depth_stencil "
-      "GL_OES_rgb8_rgba8 "
-      "GL_OES_standard_derivatives "
-      "GL_OES_stencil1 "
-      "GL_OES_stencil4 "
-      "GL_OES_stencil8 "
-      "GL_OES_texture_3D "
-      "GL_OES_texture_npot "
-      "GL_EXT_texture_filter_anisotropic "
-      "GL_EXT_texture_type_2_10_10_10_REV "
-      "GL_OES_depth_texture "
-      "GL_OES_standard_derivatives "
-      ;
+   char *s = *str;
+   size_t len = strlen(ext);
+
+   if (s) {
+      memcpy(s, ext, len);
+      s[len++] = ' ';
+      s[len] = '\0';
+
+      *str += len;
+   }
+   else {
+      len++;
+   }
+
+   return len;
+}
+
+
+static size_t
+make_extension_string(const GLcontext *ctx, char *str)
+{
+   size_t len = 0;
+
+   /* Core additions */
+   len += append_extension(&str, "GL_OES_single_precision");
+
+   /* Required extensions */
+   len += append_extension(&str, "GL_OES_compressed_paletted_texture");
+
+   if (ctx->Extensions.ARB_framebuffer_object) {
+      len += append_extension(&str, "GL_OES_framebuffer_object");
+      len += append_extension(&str, "GL_OES_depth24");
+      len += append_extension(&str, "GL_OES_depth32");
+      len += append_extension(&str, "GL_OES_fbo_render_mipmap");
+      len += append_extension(&str, "GL_OES_rgb8_rgba8");
+      len += append_extension(&str, "GL_OES_stencil1");
+      len += append_extension(&str, "GL_OES_stencil4");
+      len += append_extension(&str, "GL_OES_stencil8");
+   }
+
+   if (ctx->Extensions.EXT_vertex_array)
+      len += append_extension(&str, "GL_OES_element_index_uint");
+   if (ctx->Extensions.ARB_vertex_buffer_object)
+      len += append_extension(&str, "GL_OES_mapbuffer");
+
+   if (ctx->Extensions.EXT_texture3D)
+      len += append_extension(&str, "GL_OES_texture_3D");
+   if (ctx->Extensions.ARB_texture_non_power_of_two)
+      len += append_extension(&str, "GL_OES_texture_npot");
+   if (ctx->Extensions.EXT_texture_filter_anisotropic)
+      len += append_extension(&str, "GL_EXT_texture_filter_anisotropic");
+
+   len += append_extension(&str, "GL_EXT_texture_type_2_10_10_10_REV");
+   if (ctx->Extensions.ARB_depth_texture)
+      len += append_extension(&str, "GL_OES_depth_texture");
+   if (ctx->Extensions.EXT_packed_depth_stencil)
+      len += append_extension(&str, "GL_OES_packed_depth_stencil");
+   if (ctx->Extensions.ARB_fragment_shader)
+      len += append_extension(&str, "GL_OES_standard_derivatives");
+
+   return len;
 }
 
 
+static const GLubyte *
+compute_es_extensions(void)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (!ctx->Extensions.String) {
+      char *s;
+      unsigned int len;
+
+      len = make_extension_string(ctx, NULL);
+      s = (char *) _mesa_malloc(len + 1);
+      if (!s)
+         return NULL;
+      make_extension_string(ctx, s);
+      ctx->Extensions.String = (const GLubyte *) s;
+   }
+
+   return ctx->Extensions.String;
+}
+
 const GLubyte * GLAPIENTRY
 _es_GetString(GLenum name)
 {
    switch (name) {
    case GL_VERSION:
-      return (const GLubyte *) compute_es_version();
+      return compute_es_version();
    case GL_SHADING_LANGUAGE_VERSION:
       return (const GLubyte *) "OpenGL ES GLSL ES 1.0.16";
    case GL_EXTENSIONS:
-      return (const GLubyte *) extension_string();
+      return compute_es_extensions();
    default:
       return _mesa_GetString(name);
    }