summaryrefslogtreecommitdiff
path: root/glamor/glamor_core.c
diff options
context:
space:
mode:
authorZhigang Gong <zhigang.gong@gmail.com>2011-08-11 15:05:02 -0400
committerZhigang Gong <zhigang.gong@linux.intel.com>2011-09-26 16:47:01 +0800
commit172e8cfcd411b1abeaf8ede2e3882d6198cee5b8 (patch)
tree752c0c80a2b1fa8e82e372d3a2cb59800245d9ed /glamor/glamor_core.c
parent2146a25bac4392c47ef06ecddbf12db184926b7e (diff)
glamor: Remove GLEW dependency.
Glamor doesn't need to use GLEW. We can parse the extension by ourself. This patch also fix the fbo size checking from a hard coded style to a dynamic checking style. Signed-off-by: Zhigang Gong <zhigang.gong@gmail.com>
Diffstat (limited to 'glamor/glamor_core.c')
-rw-r--r--glamor/glamor_core.c139
1 files changed, 88 insertions, 51 deletions
diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c
index 096e40b20..09851a0dd 100644
--- a/glamor/glamor_core.c
+++ b/glamor/glamor_core.c
@@ -201,35 +201,27 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
glamor_priv->finish_access_prog[2] = glCreateProgram();
glamor_priv->finish_access_prog[3] = glCreateProgram();
- if (GLEW_ARB_fragment_shader) {
#ifndef GLAMOR_GLES2
- vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
- fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, fs_source);
- glAttachShader(glamor_priv->finish_access_prog[0], vs_prog);
- glAttachShader(glamor_priv->finish_access_prog[0], fs_prog);
-
- avs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
- aswizzle_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, aswizzle_source);
- glAttachShader(glamor_priv->finish_access_prog[1], avs_prog);
- glAttachShader(glamor_priv->finish_access_prog[1], aswizzle_prog);
+ vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
+ fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, fs_source);
+ glAttachShader(glamor_priv->finish_access_prog[0], vs_prog);
+ glAttachShader(glamor_priv->finish_access_prog[0], fs_prog);
+
+ avs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
+ aswizzle_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, aswizzle_source);
+ glAttachShader(glamor_priv->finish_access_prog[1], avs_prog);
+ glAttachShader(glamor_priv->finish_access_prog[1], aswizzle_prog);
#endif
- es_vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, es_vs_source);
- es_fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, es_fs_source);
- glAttachShader(glamor_priv->finish_access_prog[2], es_vs_prog);
- glAttachShader(glamor_priv->finish_access_prog[2], es_fs_prog);
-
- es_avs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, es_vs_source);
- es_aswizzle_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, es_aswizzle_source);
- glAttachShader(glamor_priv->finish_access_prog[3], es_avs_prog);
- glAttachShader(glamor_priv->finish_access_prog[3], es_aswizzle_prog);
+ es_vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, es_vs_source);
+ es_fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, es_fs_source);
+ glAttachShader(glamor_priv->finish_access_prog[2], es_vs_prog);
+ glAttachShader(glamor_priv->finish_access_prog[2], es_fs_prog);
+
+ es_avs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, es_vs_source);
+ es_aswizzle_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, es_aswizzle_source);
+ glAttachShader(glamor_priv->finish_access_prog[3], es_avs_prog);
+ glAttachShader(glamor_priv->finish_access_prog[3], es_aswizzle_prog);
- } else {
-#ifndef GLAMOR_GLES2
- vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
- glAttachShader(glamor_priv->finish_access_prog[0], vs_prog);
- ErrorF("Lack of framgment shader support.\n");
-#endif
- }
#ifndef GLAMOR_GLES2
@@ -244,34 +236,32 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
glBindAttribLocation(glamor_priv->finish_access_prog[3], GLAMOR_VERTEX_SOURCE, "v_texcoord0");
glamor_link_glsl_prog(glamor_priv->finish_access_prog[3]);
- if (GLEW_ARB_fragment_shader) {
- GLint sampler_uniform_location;
+ GLint sampler_uniform_location;
#ifndef GLAMOR_GLES2
- sampler_uniform_location =
- glGetUniformLocation(glamor_priv->finish_access_prog[0], "sampler");
- glUseProgram(glamor_priv->finish_access_prog[0]);
- glUniform1i(sampler_uniform_location, 0);
- glUseProgram(0);
-
- sampler_uniform_location =
- glGetUniformLocation(glamor_priv->finish_access_prog[1], "sampler");
- glUseProgram(glamor_priv->finish_access_prog[1]);
- glUniform1i(sampler_uniform_location, 0);
- glUseProgram(0);
+ sampler_uniform_location =
+ glGetUniformLocation(glamor_priv->finish_access_prog[0], "sampler");
+ glUseProgram(glamor_priv->finish_access_prog[0]);
+ glUniform1i(sampler_uniform_location, 0);
+ glUseProgram(0);
+
+ sampler_uniform_location =
+ glGetUniformLocation(glamor_priv->finish_access_prog[1], "sampler");
+ glUseProgram(glamor_priv->finish_access_prog[1]);
+ glUniform1i(sampler_uniform_location, 0);
+ glUseProgram(0);
#endif
- sampler_uniform_location =
- glGetUniformLocation(glamor_priv->finish_access_prog[2], "sampler");
- glUseProgram(glamor_priv->finish_access_prog[2]);
- glUniform1i(sampler_uniform_location, 0);
- glUseProgram(0);
-
- sampler_uniform_location =
- glGetUniformLocation(glamor_priv->finish_access_prog[3], "sampler");
- glUseProgram(glamor_priv->finish_access_prog[3]);
- glUniform1i(sampler_uniform_location, 0);
- glUseProgram(0);
+ sampler_uniform_location =
+ glGetUniformLocation(glamor_priv->finish_access_prog[2], "sampler");
+ glUseProgram(glamor_priv->finish_access_prog[2]);
+ glUniform1i(sampler_uniform_location, 0);
+ glUseProgram(0);
+
+ sampler_uniform_location =
+ glGetUniformLocation(glamor_priv->finish_access_prog[3], "sampler");
+ glUseProgram(glamor_priv->finish_access_prog[3]);
+ glUniform1i(sampler_uniform_location, 0);
+ glUseProgram(0);
- }
}
void
@@ -494,3 +484,50 @@ glamor_bitmap_to_region(PixmapPtr pixmap)
glamor_finish_access(&pixmap->drawable);
return ret;
}
+
+/* Borrow from cairo. */
+Bool
+glamor_gl_has_extension(char *extension)
+{
+ const char *gl_extensions;
+ char *pext;
+ int ext_len;
+ ext_len = strlen(extension);
+
+ gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
+ pext = (char*)gl_extensions;
+
+ if (pext == NULL || extension == NULL)
+ return FALSE;
+
+ while((pext = strstr(pext, extension)) != NULL) {
+ if (pext[ext_len] == ' ' || pext[ext_len] == '\0')
+ return TRUE;
+ pext += ext_len;
+ }
+ return FALSE;
+}
+
+int
+glamor_gl_get_version (void)
+{
+ int major, minor;
+ const char *version = (const char *) glGetString (GL_VERSION);
+ const char *dot = version == NULL ? NULL : strchr (version, '.');
+ const char *major_start = dot;
+
+ /* Sanity check */
+ if (dot == NULL || dot == version || *(dot + 1) == '\0') {
+ major = 0;
+ minor = 0;
+ } else {
+ /* Find the start of the major version in the string */
+ while (major_start > version && *major_start != ' ')
+ --major_start;
+ major = strtol (major_start, NULL, 10);
+ minor = strtol (dot + 1, NULL, 10);
+ }
+
+ return GLAMOR_GL_VERSION_ENCODE (major, minor);
+}
+