YaGL: Added extension string
authorStanislav Vorobiov <s.vorobiov@samsung.com>
Mon, 24 Sep 2012 06:53:32 +0000 (10:53 +0400)
committerEvgeny Voevodin <e.voevodin@samsung.com>
Mon, 8 Oct 2012 08:21:44 +0000 (12:21 +0400)
YaGL: Fixed invisible points bug

hw/yagl_apis/gles/yagl_gles_context.c
hw/yagl_apis/gles/yagl_gles_context.h
hw/yagl_apis/gles/yagl_host_gles_calls.c
hw/yagl_apis/gles/yagl_host_gles_calls.h
hw/yagl_apis/gles1/yagl_gles1_calls.c
hw/yagl_apis/gles2/yagl_gles2_calls.c
hw/yagl_apis/gles2/yagl_gles2_context.c
hw/yagl_apis/gles2/yagl_gles2_context.h
hw/yagl_drivers/gles_ogl/yagl_gles_ogl.c
hw/yagl_gles_driver.h
hw/yagl_version.h

index 582d8ddfcf105e81e09aeacfcaea03d4d7134282..eeb5dcdf764801d023841e5557772ca2f45e3d04 100644 (file)
@@ -188,6 +188,14 @@ void yagl_gles_context_init(struct yagl_gles_context *ctx,
 
     ctx->num_compressed_texture_formats = 0;
 
+    ctx->pack_depth_stencil = false;
+
+    ctx->texture_npot = false;
+
+    ctx->texture_rectangle = false;
+
+    ctx->texture_filter_anisotropic = false;
+
     ctx->active_texture_unit = 0;
 
     ctx->vbo = NULL;
@@ -211,6 +219,7 @@ void yagl_gles_context_prepare(struct yagl_gles_context *ctx,
                                int num_texture_units)
 {
     int i;
+    const char *extensions;
 
     if (num_texture_units < 1) {
         num_texture_units = 1;
@@ -237,6 +246,19 @@ void yagl_gles_context_prepare(struct yagl_gles_context *ctx,
                                 GL_NUM_COMPRESSED_TEXTURE_FORMATS,
                                 &ctx->num_compressed_texture_formats);
 
+    extensions = (const char*)ctx->driver_ps->GetString(ctx->driver_ps, GL_EXTENSIONS);
+
+    ctx->pack_depth_stencil = (strstr(extensions, "GL_EXT_packed_depth_stencil ") != NULL);
+
+    ctx->texture_npot = (strstr(extensions, "GL_OES_texture_npot ") != NULL) ||
+                        (strstr(extensions, "GL_ARB_texture_non_power_of_two ") != NULL);
+
+    ctx->texture_rectangle = (strstr(extensions, "GL_NV_texture_rectangle ") != NULL) ||
+                             (strstr(extensions, "GL_EXT_texture_rectangle ") != NULL) ||
+                             (strstr(extensions, "GL_ARB_texture_rectangle ") != NULL);
+
+    ctx->texture_filter_anisotropic = (strstr(extensions, "GL_EXT_texture_filter_anisotropic ") != NULL);
+
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
index 60f5f98eec2a159cd45921f080847610ed083306..65f9f7ce98613450e94fa6cb0c8c7dead2fe5185 100644 (file)
@@ -32,6 +32,12 @@ struct yagl_gles_context
                        GLenum /*pname*/,
                        GLfloat */*params*/);
 
+    GLchar *(*get_extensions)(struct yagl_gles_context */*ctx*/);
+
+    void (*pre_draw)(struct yagl_gles_context */*ctx*/, GLenum mode);
+
+    void (*post_draw)(struct yagl_gles_context */*ctx*/, GLenum mode);
+
     /*
      * Pixel Buffer Object (PBO) for quick access to current surface pixels.
      * 'read_pixels' will automatically detect surface size changes and
@@ -68,6 +74,14 @@ struct yagl_gles_context
 
     int num_compressed_texture_formats;
 
+    bool pack_depth_stencil;
+
+    bool texture_npot;
+
+    bool texture_rectangle;
+
+    bool texture_filter_anisotropic;
+
     int active_texture_unit;
 
     struct yagl_gles_buffer *vbo;
index 421a0f92383723ce21a228e813ddb5cdf52022ff..a0e0d07111f03a9665cfb2b2931cfe667ac39a8b 100644 (file)
@@ -635,7 +635,11 @@ void yagl_host_glDrawArrays(GLenum mode,
         return;
     }
 
+    ctx->pre_draw(ctx, mode);
+
     ctx->driver_ps->DrawArrays(ctx->driver_ps, mode, first, count);
+
+    ctx->post_draw(ctx, mode);
 }
 
 void yagl_host_glDrawElements(GLenum mode,
@@ -724,12 +728,16 @@ void yagl_host_glDrawElements(GLenum mode,
         goto out;
     }
 
+    ctx->pre_draw(ctx, mode);
+
     ctx->driver_ps->DrawElements(ctx->driver_ps,
                                  mode,
                                  count,
                                  type,
                                  (ctx->ebo ? (GLvoid*)indices_ : indices));
 
+    ctx->post_draw(ctx, mode);
+
 out:
     if (ebo_bound) {
         ctx->driver_ps->BindBuffer(ctx->driver_ps,
@@ -1285,3 +1293,23 @@ void yagl_host_glViewport(GLint x,
 
     ctx->driver_ps->Viewport(ctx->driver_ps, x, y, width, height);
 }
+
+GLuint yagl_host_glGetExtensionStringYAGL(target_ulong /* GLchar* */ str_)
+{
+    GLchar *str;
+    GLuint str_len;
+
+    YAGL_GET_CTX_RET(glGetExtensionStringYAGL, 1);
+
+    str = ctx->get_extensions(ctx);
+
+    str_len = strlen(str);
+
+    if (str_) {
+        yagl_mem_put(ts, str_, str_len + 1, str);
+    }
+
+    g_free(str);
+
+    return str_len + 1;
+}
index 95ac2f74fd0ac817a4a1892c9fef136c98fe46aa..d48c1c90c2c63c1f65ab331b7e96940ff3de297e 100644 (file)
@@ -167,5 +167,6 @@ void yagl_host_glViewport(GLint x,
     GLint y,
     GLsizei width,
     GLsizei height);
+GLuint yagl_host_glGetExtensionStringYAGL(target_ulong /* GLchar* */ str_);
 
 #endif
index 0fd52cce376735507f033983e6d3b3dded069949..23daf3be59c31009d29d4a042796b8b2bf2286c7 100644 (file)
@@ -2255,7 +2255,22 @@ static uint8_t* yagl_func_glViewport(struct yagl_thread_state *ts,
     return out_buff;
 }
 
-const uint32_t yagl_gles1_api_num_funcs = 143;
+/*
+ * glGetExtensionStringYAGL dispatcher. id = 144
+ */
+static uint8_t* yagl_func_glGetExtensionStringYAGL(struct yagl_thread_state *ts,
+    uint8_t *out_buff,
+    uint8_t *in_buff)
+{
+    target_ulong str = yagl_marshal_get_ptr(&out_buff);
+    YAGL_LOG_FUNC_ENTER_SPLIT1(ts->ps->id, ts->id, glGetExtensionStringYAGL, target_ulong, str);
+    GLuint ret = yagl_host_glGetExtensionStringYAGL(str);
+    YAGL_LOG_FUNC_EXIT_SPLIT(GLuint, ret);
+    yagl_marshal_put_GLuint(&in_buff, ret);
+    return out_buff;
+}
+
+const uint32_t yagl_gles1_api_num_funcs = 144;
 
 yagl_api_func yagl_gles1_api_funcs[] = {
     &yagl_func_glAlphaFunc,
@@ -2400,5 +2415,6 @@ yagl_api_func yagl_gles1_api_funcs[] = {
     &yagl_func_glTexSubImage2D,
     &yagl_func_glTranslatex,
     &yagl_func_glVertexPointer,
-    &yagl_func_glViewport
+    &yagl_func_glViewport,
+    &yagl_func_glGetExtensionStringYAGL
 };
index 8a1a0e63ec267dac9b4099e338b2a7bfb3f3dd9a..82d2a4bf64f0e8efee9c8d56bc8aac04c7ca6980 100644 (file)
@@ -2250,7 +2250,22 @@ static uint8_t* yagl_func_glViewport(struct yagl_thread_state *ts,
     return out_buff;
 }
 
-const uint32_t yagl_gles2_api_num_funcs = 141;
+/*
+ * glGetExtensionStringYAGL dispatcher. id = 142
+ */
+static uint8_t* yagl_func_glGetExtensionStringYAGL(struct yagl_thread_state *ts,
+    uint8_t *out_buff,
+    uint8_t *in_buff)
+{
+    target_ulong str = yagl_marshal_get_ptr(&out_buff);
+    YAGL_LOG_FUNC_ENTER_SPLIT1(ts->ps->id, ts->id, glGetExtensionStringYAGL, target_ulong, str);
+    GLuint ret = yagl_host_glGetExtensionStringYAGL(str);
+    YAGL_LOG_FUNC_EXIT_SPLIT(GLuint, ret);
+    yagl_marshal_put_GLuint(&in_buff, ret);
+    return out_buff;
+}
+
+const uint32_t yagl_gles2_api_num_funcs = 142;
 
 yagl_api_func yagl_gles2_api_funcs[] = {
     &yagl_func_glActiveTexture,
@@ -2393,5 +2408,6 @@ yagl_api_func yagl_gles2_api_funcs[] = {
     &yagl_func_glVertexAttrib4f,
     &yagl_func_glVertexAttrib4fv,
     &yagl_func_glVertexAttribPointer,
-    &yagl_func_glViewport
+    &yagl_func_glViewport,
+    &yagl_func_glGetExtensionStringYAGL
 };
index ec8835c53c8dbcff5eebf24bf2047a07c69d250c..73de5fef2d735a828365d2aa07a3cb33afc8047c 100644 (file)
@@ -9,6 +9,12 @@
 #include <GLES2/gl2ext.h>
 #include "yagl_gles2_driver.h"
 
+/*
+ * We can't include GL/glext.h here
+ */
+#define GL_POINT_SPRITE                   0x8861
+#define GL_VERTEX_PROGRAM_POINT_SIZE      0x8642
+
 static void yagl_gles2_array_apply(struct yagl_gles_array *array)
 {
     struct yagl_gles2_context *gles2_ctx = (struct yagl_gles2_context*)array->ctx;
@@ -139,6 +145,7 @@ static bool yagl_gles2_context_get_param_count(struct yagl_gles_context *ctx,
     case GL_UNPACK_ALIGNMENT: *count = 1; break;
     case GL_VIEWPORT: *count = 4; break;
     case GL_MAX_SAMPLES_IMG: *count = 1; break;
+    case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: *count = 1; break;
     default: return false;
     }
     return true;
@@ -211,6 +218,110 @@ static bool yagl_gles2_context_get_floatv(struct yagl_gles_context *ctx,
     return true;
 }
 
+static GLchar *yagl_gles2_context_get_extensions(struct yagl_gles_context *ctx)
+{
+    struct yagl_gles2_context *gles2_ctx = (struct yagl_gles2_context*)ctx;
+
+    const GLchar *mandatory_extensions =
+        "GL_OES_depth24 GL_OES_depth32 "
+        "GL_OES_texture_float GL_OES_texture_float_linear "
+        "GL_OES_depth_texture ";
+    const GLchar *pack_depth_stencil = "GL_OES_packed_depth_stencil ";
+    const GLchar *texture_npot = "GL_OES_texture_npot ";
+    const GLchar *texture_rectangle = "GL_ARB_texture_rectangle ";
+    const GLchar *texture_filter_anisotropic = "GL_EXT_texture_filter_anisotropic ";
+    const GLchar *texture_half_float = "GL_OES_texture_half_float GL_OES_texture_half_float_linear ";
+    const GLchar *vertex_half_float = "GL_OES_vertex_half_float ";
+    const GLchar *standard_derivatives = "GL_OES_standard_derivatives ";
+
+    GLuint len = strlen(mandatory_extensions);
+    GLchar *str;
+
+    if (gles2_ctx->base.pack_depth_stencil) {
+        len += strlen(pack_depth_stencil);
+    }
+
+    if (gles2_ctx->base.texture_npot) {
+        len += strlen(texture_npot);
+    }
+
+    if (gles2_ctx->base.texture_rectangle) {
+        len += strlen(texture_rectangle);
+    }
+
+    if (gles2_ctx->base.texture_filter_anisotropic) {
+        len += strlen(texture_filter_anisotropic);
+    }
+
+    if (gles2_ctx->texture_half_float) {
+        len += strlen(texture_half_float);
+    }
+
+    if (gles2_ctx->vertex_half_float) {
+        len += strlen(vertex_half_float);
+    }
+
+    if (gles2_ctx->standard_derivatives) {
+        len += strlen(standard_derivatives);
+    }
+
+    str = g_malloc0(len + 1);
+
+    strcpy(str, mandatory_extensions);
+
+    if (gles2_ctx->base.pack_depth_stencil) {
+        strcat(str, pack_depth_stencil);
+    }
+
+    if (gles2_ctx->base.texture_npot) {
+        strcat(str, texture_npot);
+    }
+
+    if (gles2_ctx->base.texture_rectangle) {
+        strcat(str, texture_rectangle);
+    }
+
+    if (gles2_ctx->base.texture_filter_anisotropic) {
+        strcat(str, texture_filter_anisotropic);
+    }
+
+    if (gles2_ctx->texture_half_float) {
+        strcat(str, texture_half_float);
+    }
+
+    if (gles2_ctx->vertex_half_float) {
+        strcat(str, vertex_half_float);
+    }
+
+    if (gles2_ctx->standard_derivatives) {
+        strcat(str, standard_derivatives);
+    }
+
+    return str;
+}
+
+static void yagl_gles2_context_pre_draw(struct yagl_gles_context *ctx, GLenum mode)
+{
+    /*
+     * Enable texture generation for GL_POINTS and gl_PointSize shader variable.
+     * GLESv2 assumes this is enabled by default, we need to set this
+     * state for GL.
+     */
+
+    if (mode == GL_POINTS) {
+        ctx->driver_ps->Enable(ctx->driver_ps, GL_POINT_SPRITE);
+        ctx->driver_ps->Enable(ctx->driver_ps, GL_VERTEX_PROGRAM_POINT_SIZE);
+    }
+}
+
+static void yagl_gles2_context_post_draw(struct yagl_gles_context *ctx, GLenum mode)
+{
+    if (mode == GL_POINTS) {
+        ctx->driver_ps->Disable(ctx->driver_ps, GL_VERTEX_PROGRAM_POINT_SIZE);
+        ctx->driver_ps->Disable(ctx->driver_ps, GL_POINT_SPRITE);
+    }
+}
+
 static void yagl_gles2_context_destroy(struct yagl_client_context *ctx)
 {
     struct yagl_gles2_context *gles2_ctx = (struct yagl_gles2_context*)ctx;
@@ -265,6 +376,7 @@ static void yagl_gles2_context_prepare(struct yagl_gles2_context *gles2_ctx,
     struct yagl_gles_driver_ps *gles_driver = gles2_ctx->driver_ps->common;
     GLint i, num_arrays = 0, num_texture_units = 0;
     struct yagl_gles_array *arrays;
+    const char *extensions;
 
     YAGL_LOG_FUNC_ENTER_TS(ts,
                            yagl_gles2_context_prepare,
@@ -295,6 +407,15 @@ static void yagl_gles2_context_prepare(struct yagl_gles2_context *gles2_ctx,
                              GL_NUM_SHADER_BINARY_FORMATS,
                              &gles2_ctx->num_shader_binary_formats);
 
+    extensions = (const char*)gles_driver->GetString(gles_driver, GL_EXTENSIONS);
+
+    gles2_ctx->texture_half_float = (strstr(extensions, "GL_ARB_half_float_pixel ") != NULL) ||
+                                    (strstr(extensions, "GL_NV_half_float ") != NULL);
+
+    gles2_ctx->vertex_half_float = (strstr(extensions, "GL_ARB_half_float_vertex ") != NULL);
+
+    gles2_ctx->standard_derivatives = (strstr(extensions, "GL_OES_standard_derivatives ") != NULL);
+
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -343,6 +464,9 @@ struct yagl_gles2_context
     gles2_ctx->base.get_booleanv = &yagl_gles2_context_get_booleanv;
     gles2_ctx->base.get_integerv = &yagl_gles2_context_get_integerv;
     gles2_ctx->base.get_floatv = &yagl_gles2_context_get_floatv;
+    gles2_ctx->base.get_extensions = &yagl_gles2_context_get_extensions;
+    gles2_ctx->base.pre_draw = &yagl_gles2_context_pre_draw;
+    gles2_ctx->base.post_draw = &yagl_gles2_context_post_draw;
 
     gles2_ctx->driver_ps = driver_ps;
     gles2_ctx->prepared = false;
@@ -351,6 +475,10 @@ struct yagl_gles2_context
 
     gles2_ctx->num_shader_binary_formats = 0;
 
+    gles2_ctx->texture_half_float = false;
+    gles2_ctx->vertex_half_float = false;
+    gles2_ctx->standard_derivatives = false;
+
     gles2_ctx->program_local_name = 0;
 
     YAGL_LOG_FUNC_EXIT("%p", gles2_ctx);
index a2dd8fdcc153b812c8381c0c124e73edb99abc78..33279f9a3788e93cab262ae3dc1f86133d0df37b 100644 (file)
@@ -28,6 +28,12 @@ struct yagl_gles2_context
 
     int num_shader_binary_formats;
 
+    bool texture_half_float;
+
+    bool vertex_half_float;
+
+    bool standard_derivatives;
+
     yagl_object_name program_local_name;
 };
 
index 8df12ed0c8c45c2894c16ae1d963144ccab1d1c0..977c272e6b0b2ec775147bf08fd1e82dc4eb34ac 100644 (file)
@@ -80,6 +80,7 @@ struct yagl_gles_ogl
     YAGL_GLES_OGL_PROC4(glFramebufferRenderbufferEXT, GLenum, GLenum, GLenum, GLuint, target, attachment, renderbuffertarget, renderbuffer)
     YAGL_GLES_OGL_PROC_RET1(GLenum, glCheckFramebufferStatusEXT, GLenum, target)
     YAGL_GLES_OGL_PROC1(glGenerateMipmapEXT, GLenum, target)
+    YAGL_GLES_OGL_PROC_RET1(const GLubyte*, glGetString, GLenum, name)
 };
 
 YAGL_GLES_OGL_PROC_IMPL1(yagl_gles_driver_ps, yagl_gles_ogl_ps, yagl_gles_ogl, ActiveTexture, GLenum, texture)
@@ -154,6 +155,7 @@ YAGL_GLES_OGL_PROC_IMPL4(yagl_gles_driver_ps, yagl_gles_ogl_ps, yagl_gles_ogl, R
 YAGL_GLES_OGL_PROC_IMPL4(yagl_gles_driver_ps, yagl_gles_ogl_ps, yagl_gles_ogl, FramebufferRenderbufferEXT, GLenum, GLenum, GLenum, GLuint, target, attachment, renderbuffertarget, renderbuffer)
 YAGL_GLES_OGL_PROC_IMPL_RET1(yagl_gles_driver_ps, yagl_gles_ogl_ps, yagl_gles_ogl, GLenum, CheckFramebufferStatusEXT, GLenum, target)
 YAGL_GLES_OGL_PROC_IMPL1(yagl_gles_driver_ps, yagl_gles_ogl_ps, yagl_gles_ogl, GenerateMipmapEXT, GLenum, target)
+YAGL_GLES_OGL_PROC_IMPL_RET1(yagl_gles_driver_ps, yagl_gles_ogl_ps, yagl_gles_ogl, const GLubyte*, GetString, GLenum, name)
 
 struct yagl_gles_ogl_ps
     *yagl_gles_ogl_ps_create(struct yagl_gles_ogl *gles_ogl,
@@ -240,6 +242,7 @@ struct yagl_gles_ogl_ps
     gles_ogl_ps->base.FramebufferRenderbuffer = &yagl_gles_ogl_FramebufferRenderbufferEXT;
     gles_ogl_ps->base.CheckFramebufferStatus = &yagl_gles_ogl_CheckFramebufferStatusEXT;
     gles_ogl_ps->base.GenerateMipmap = &yagl_gles_ogl_GenerateMipmapEXT;
+    YAGL_GLES_OGL_ASSIGN_PROC(yagl_gles_ogl, gles_ogl_ps, GetString);
 
     YAGL_LOG_FUNC_EXIT(NULL);
 
@@ -345,6 +348,7 @@ struct yagl_gles_ogl
     YAGL_GLES_OGL_GET_PROC(gles_ogl, glFramebufferRenderbufferEXT);
     YAGL_GLES_OGL_GET_PROC(gles_ogl, glCheckFramebufferStatusEXT);
     YAGL_GLES_OGL_GET_PROC(gles_ogl, glGenerateMipmapEXT);
+    YAGL_GLES_OGL_GET_PROC(gles_ogl, glGetString);
 
     YAGL_LOG_FUNC_EXIT(NULL);
 
index 59350f50724b0cf4c137253c073b2eae904e1300..e293cb519aab39716daf6ddba2935de02a4aacb7 100644 (file)
@@ -142,6 +142,7 @@ struct yagl_gles_driver_ps
     YAGL_GLES_DRIVER_FUNC4(struct yagl_gles_driver_ps *driver_ps, FramebufferRenderbuffer, GLenum, GLenum, GLenum, GLuint, target, attachment, renderbuffertarget, renderbuffer)
     YAGL_GLES_DRIVER_FUNC_RET1(struct yagl_gles_driver_ps *driver_ps, GLenum, CheckFramebufferStatus, GLenum, target)
     YAGL_GLES_DRIVER_FUNC1(struct yagl_gles_driver_ps *driver_ps, GenerateMipmap, GLenum, target)
+    YAGL_GLES_DRIVER_FUNC_RET1(struct yagl_gles_driver_ps *driver_ps, const GLubyte*, GetString, GLenum, name)
 };
 
 void yagl_gles_driver_ps_init(struct yagl_gles_driver_ps *driver_ps,
index 5e084f4ec27f45ed22ec63929fe244126ff91be1..2c7aee3f7b694c73ba6ed0745527f849e5992377 100644 (file)
@@ -6,6 +6,6 @@
 /*
  * Whenever protocol changes be sure to bump this.
  */
-#define YAGL_VERSION 7
+#define YAGL_VERSION 8
 
 #endif