void cogl_shader_compile (CoglHandle handle) { CoglShader *shader; _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_shader (handle)) return; #ifdef HAVE_COGL_GL shader = handle; if (shader->language == COGL_SHADER_LANGUAGE_ARBFP) _cogl_shader_compile_real (handle, NULL); #endif /* XXX: For GLSL we don't actually compile anything until the shader * gets used so we have an opportunity to add some boilerplate to * the shader. * * At the end of the day this is obviously a badly designed API * given that we are having to lie to the user. It was a mistake to * so thinly wrap the OpenGL shader API and the current plan is to * replace it with a pipeline snippets API. */ }
CoglBool cogl_shader_is_compiled (CoglHandle handle) { #if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES2) if (!cogl_is_shader (handle)) return FALSE; /* XXX: This API doesn't really do anything! * * This API is purely for compatibility and blatantly lies to the * user about whether their shader has been compiled. * * I suppose we could say we're stretching the definition of * "compile" and are deferring any related errors to be "linker" * errors. * * The reason we don't do anything is because a shader needs to * be associated with a CoglPipeline for Cogl to be able to * compile and link anything. * * The CoglShader API is mostly deprecated by CoglSnippets and so * these days we do the bare minimum to support the existing users * of it until they are able to migrate to the snippets api. */ return TRUE; #else return FALSE; #endif }
char * cogl_shader_get_info_log (CoglHandle handle) { if (!cogl_is_shader (handle)) return NULL; /* XXX: This API doesn't really do anything! * * This API is purely for compatibility * * The reason we don't do anything is because a shader needs to * be associated with a CoglPipeline for Cogl to be able to * compile and link anything. * * The way this API was originally designed as a very thin wrapper * over the GL api was a mistake and it's now very difficult to * make the API work in a meaningful way given how the rest of Cogl * has evolved. * * The CoglShader API is mostly deprecated by CoglSnippets and so * these days we do the bare minimum to support the existing users * of it until they are able to migrate to the snippets api. */ return g_strdup (""); }
void cogl_program_attach_shader (CoglHandle program_handle, CoglHandle shader_handle) { CoglProgram *program; CoglShader *shader; _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_program (program_handle) || !cogl_is_shader (shader_handle)) return; program = _cogl_program_pointer_from_handle (program_handle); shader = _cogl_shader_pointer_from_handle (shader_handle); /* Only one shader is allowed if the type is ARBfp */ if (shader->language == COGL_SHADER_LANGUAGE_ARBFP) g_return_if_fail (program->attached_shaders == NULL); else if (shader->language == COGL_SHADER_LANGUAGE_GLSL) g_return_if_fail (_cogl_program_get_language (program) == COGL_SHADER_LANGUAGE_GLSL); program->attached_shaders = g_slist_prepend (program->attached_shaders, cogl_handle_ref (shader_handle)); program->age++; }
void cogl_shader_source (CoglHandle handle, const char *source) { CoglShader *shader; CoglShaderLanguage language; _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_shader (handle)) return; shader = handle; #ifdef HAVE_COGL_GL if (strncmp (source, "!!ARBfp1.0", 10) == 0) language = COGL_SHADER_LANGUAGE_ARBFP; else #endif language = COGL_SHADER_LANGUAGE_GLSL; /* Delete the old object if the language is changing... */ if (G_UNLIKELY (language != shader->language) && shader->gl_handle) delete_shader (shader); shader->source = g_strdup (source); shader->language = language; }
CoglShaderType cogl_shader_get_type (CoglHandle handle) { GLint type; CoglShader *shader; if (!cogl_is_shader (handle)) { g_warning ("Non shader handle type passed to cogl_shader_get_type"); return COGL_SHADER_TYPE_VERTEX; } shader = _cogl_shader_pointer_from_handle (handle); GE (glGetShaderiv (shader->gl_handle, GL_SHADER_TYPE, &type)); if (type == GL_VERTEX_SHADER) return COGL_SHADER_TYPE_VERTEX; else if (type == GL_FRAGMENT_SHADER) return COGL_SHADER_TYPE_VERTEX; else { g_warning ("Unexpected shader type 0x%08lX", (unsigned long)type); return COGL_SHADER_TYPE_VERTEX; } }
void cogl_shader_compile (CoglHandle handle) { CoglShader *shader; _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_shader (handle)) return; shader = _cogl_shader_pointer_from_handle (handle); glCompileShaderARB (shader->gl_handle); }
void cogl_shader_source (CoglHandle handle, const gchar *source) { CoglShader *shader; _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_shader (handle)) return; shader = _cogl_shader_pointer_from_handle (handle); glShaderSourceARB (shader->gl_handle, 1, &source, NULL); }
void cogl_shader_get_parameteriv (CoglHandle handle, COGLenum pname, COGLint *dest) { CoglShader *shader; _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_shader (handle)) return; shader = _cogl_shader_pointer_from_handle (handle); glGetObjectParameterivARB (shader->gl_handle, pname, dest); }
CoglShaderType cogl_shader_get_type (CoglHandle handle) { CoglShader *shader; _COGL_GET_CONTEXT (ctx, COGL_SHADER_TYPE_VERTEX); if (!cogl_is_shader (handle)) { g_warning ("Non shader handle type passed to cogl_shader_get_type"); return COGL_SHADER_TYPE_VERTEX; } shader = handle; return shader->type; }
void cogl_program_attach_shader (CoglHandle program_handle, CoglHandle shader_handle) { CoglProgram *program; CoglShader *shader; _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_program (program_handle) || !cogl_is_shader (shader_handle)) return; program = _cogl_program_pointer_from_handle (program_handle); shader = _cogl_shader_pointer_from_handle (shader_handle); glAttachObject (program->gl_handle, shader->gl_handle); }
void cogl_shader_get_info_log (CoglHandle handle, guint size, gchar *buffer) { CoglShader *shader; COGLint len; _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_shader (handle)) return; shader = _cogl_shader_pointer_from_handle (handle); glGetInfoLogARB (shader->gl_handle, size-1, &len, buffer); buffer[len]='\0'; }
gboolean cogl_shader_is_compiled (CoglHandle handle) { GLint status; CoglShader *shader; if (!cogl_is_shader (handle)) return FALSE; shader = _cogl_shader_pointer_from_handle (handle); GE (glGetShaderiv (shader->gl_handle, GL_COMPILE_STATUS, &status)); if (status == GL_TRUE) return TRUE; else return FALSE; }
gchar * cogl_shader_get_info_log (CoglHandle handle) { CoglShader *shader; char buffer[512]; int len = 0; _COGL_GET_CONTEXT (ctx, NULL); if (!cogl_is_shader (handle)) return NULL; shader = _cogl_shader_pointer_from_handle (handle); glGetShaderInfoLog (shader->gl_handle, 511, &len, buffer); buffer[len] = '\0'; return g_strdup (buffer); }
void cogl_program_attach_shader (CoglHandle program_handle, CoglHandle shader_handle) { CoglProgram *program; _COGL_GET_CONTEXT (ctx, NO_RETVAL); if (!cogl_is_program (program_handle) || !cogl_is_shader (shader_handle)) return; program = _cogl_program_pointer_from_handle (program_handle); program->attached_shaders = g_slist_prepend (program->attached_shaders, cogl_handle_ref (shader_handle)); /* Whenever the shader changes we will need to relink the program with the fixed functionality shaders so we should forget the cached programs */ _cogl_gles2_clear_cache_for_program (program); }