Support for shaders in clutter. At the moment limited to drivers
providing GLSL support. * clutter/cogl/cogl.h: added rather direct binding of needed for glsl shaders. * clutter/cogl/gl/cogl-defines.h.in: * clutter/cogl/gl/cogl.c: * clutter/cogl/gles/cogl-defines.h: added stubs. * clutter/cogl/gles/cogl.c: added stubs. * clutter/glx/clutter-stage-glx.c: (clutter_stage_glx_realize): unrelated memory management sanity fix. (clutter_stage_glx_unrealize): unbind all shaders on stage unrealize. * clutter/Makefile.am: added clutter-shader.[ch] * clutter/clutter-actor.[ch]: adding shader capability to actors. * clutter/clutter-feature.h: added CLUTTER_FEATURE_SHADERS_GLSL * clutter/clutter-private.h: added stack of shaders to context. * clutter/clutter-shader.[ch]: new. * tests/Makefile.am: added shader test. * tests/test-shader.c: (frame_cb), (main): simple shader test, cycle through the inline shader with right/left mouse buttons.
This commit is contained in:
parent
947f47b6a4
commit
4dea166d53
52
cogl.h
52
cogl.h
@ -207,6 +207,58 @@ cogl_fog_set (const ClutterColor *fog_color,
|
||||
ClutterFixed z_near,
|
||||
ClutterFixed z_far);
|
||||
|
||||
|
||||
COGLint
|
||||
cogl_create_shader (COGLenum shaderType);
|
||||
|
||||
void
|
||||
cogl_shader_destroy (COGLint handle);
|
||||
|
||||
|
||||
void
|
||||
cogl_shader_source (COGLint shader,
|
||||
const gchar *source);
|
||||
void
|
||||
cogl_shader_compile (COGLint shader_handle);
|
||||
|
||||
void
|
||||
cogl_shader_get_info_log (COGLint handle,
|
||||
guint size,
|
||||
gchar *buffer);
|
||||
|
||||
void
|
||||
cogl_shader_get_parameteriv (COGLint handle,
|
||||
COGLenum pname,
|
||||
COGLint *dest);
|
||||
|
||||
|
||||
COGLint
|
||||
cogl_create_program (void);
|
||||
|
||||
void
|
||||
cogl_program_destroy (COGLint handle);
|
||||
|
||||
void
|
||||
cogl_program_attach_shader (COGLint program_handle,
|
||||
COGLint shader_handle);
|
||||
|
||||
/* 0 to use none */
|
||||
void
|
||||
cogl_program_link (COGLint program_handle);
|
||||
|
||||
void
|
||||
cogl_program_use (COGLint program_handle);
|
||||
|
||||
COGLint
|
||||
cogl_program_get_uniform_location (COGLint program_int,
|
||||
const gchar *uniform_name);
|
||||
|
||||
|
||||
void
|
||||
cogl_program_uniform_1f (COGLint uniform_no,
|
||||
gfloat value);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_H__ */
|
||||
|
@ -698,6 +698,12 @@ typedef GLuint COGLuint;
|
||||
#define CGL_UNSIGNED_SHORT_8_8_MESA 0
|
||||
#endif
|
||||
|
||||
#define CGL_FRAGMENT_SHADER GL_FRAGMENT_SHADER_ARB
|
||||
#define CGL_VERTEX_SHADER GL_VERTEX_SHADER_ARB
|
||||
|
||||
#define CGL_OBJECT_COMPILE_STATUS GL_OBJECT_COMPILE_STATUS_ARB
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
137
gl/cogl.c
137
gl/cogl.c
@ -621,6 +621,12 @@ cogl_get_features ()
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cogl_check_extension ("GL_ARB_vertex_shader", gl_extensions) &&
|
||||
cogl_check_extension ("GL_ARB_fragment_shader", gl_extensions))
|
||||
{
|
||||
flags |= CLUTTER_FEATURE_SHADERS_GLSL;
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
@ -746,3 +752,134 @@ cogl_fog_set (const ClutterColor *fog_color,
|
||||
glFogf (GL_FOG_START, CLUTTER_FIXED_TO_FLOAT (start));
|
||||
glFogf (GL_FOG_END, CLUTTER_FIXED_TO_FLOAT (stop));
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
#define PROC(rettype, retval, procname, args...) \
|
||||
static rettype (*proc) (args) = NULL; \
|
||||
if (proc == NULL) \
|
||||
{ \
|
||||
proc = (void*)cogl_get_proc_address (#procname);\
|
||||
if (!proc)\
|
||||
{\
|
||||
g_warning ("failed to lookup proc: %s", #procname);\
|
||||
return retval;\
|
||||
}\
|
||||
}
|
||||
#else
|
||||
|
||||
#define PROC(rettype, retval, procname, ...) \
|
||||
static rettype (*proc) (__VA_ARGS__) = NULL; \
|
||||
if (proc == NULL) \
|
||||
{ \
|
||||
proc = (void*)cogl_get_proc_address (#procname);\
|
||||
if (!proc)\
|
||||
{\
|
||||
g_warning ("failed to lookup proc: %s", #procname);\
|
||||
return retval;\
|
||||
}\
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
COGLint
|
||||
cogl_create_program (void)
|
||||
{
|
||||
PROC (GLhandleARB, 0, glCreateProgramObjectARB, void);
|
||||
return proc ();
|
||||
}
|
||||
|
||||
COGLint
|
||||
cogl_create_shader (COGLenum shaderType)
|
||||
{
|
||||
PROC (GLhandleARB, 0, glCreateShaderObjectARB, GLenum);
|
||||
return proc (shaderType);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_shader_source (COGLint shader,
|
||||
const gchar *source)
|
||||
{
|
||||
PROC (GLvoid,, glShaderSourceARB, GLhandleARB, GLsizei, const GLcharARB **, const GLint *)
|
||||
proc (shader, 1, &source, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_shader_compile (COGLint shader_handle)
|
||||
{
|
||||
PROC (GLvoid,, glCompileShaderARB, GLhandleARB);
|
||||
proc (shader_handle);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_attach_shader (COGLint program_handle,
|
||||
COGLint shader_handle)
|
||||
{
|
||||
PROC (GLvoid,, glAttachObjectARB, GLhandleARB, GLhandleARB);
|
||||
proc (program_handle, shader_handle);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_link (COGLint program_handle)
|
||||
{
|
||||
PROC (GLvoid,, glLinkProgramARB, GLhandleARB);
|
||||
proc (program_handle);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_use (COGLint program_handle)
|
||||
{
|
||||
PROC (GLvoid,, glUseProgramObjectARB, GLhandleARB);
|
||||
proc (program_handle);
|
||||
}
|
||||
|
||||
COGLint
|
||||
cogl_program_get_uniform_location (COGLint program_handle,
|
||||
const gchar *uniform_name)
|
||||
{
|
||||
PROC (GLint,0, glGetUniformLocationARB, GLhandleARB, const GLcharARB *)
|
||||
return proc (program_handle, uniform_name);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_program_destroy (COGLint handle)
|
||||
{
|
||||
PROC (GLvoid,, glDeleteObjectARB, GLhandleARB);
|
||||
proc (handle);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_shader_destroy (COGLint handle)
|
||||
{
|
||||
PROC (GLvoid,, glDeleteObjectARB, GLhandleARB);
|
||||
proc (handle);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_shader_get_info_log (COGLint handle,
|
||||
guint size,
|
||||
gchar *buffer)
|
||||
{
|
||||
gint len;
|
||||
PROC (GLvoid,, glGetInfoLogARB, GLhandleARB, GLsizei, GLsizei *, GLcharARB *);
|
||||
proc (handle, size-1, &len, buffer);
|
||||
buffer[len]='\0';
|
||||
}
|
||||
|
||||
void
|
||||
cogl_shader_get_parameteriv (COGLint handle,
|
||||
COGLenum pname,
|
||||
COGLint *dest)
|
||||
{
|
||||
PROC (GLvoid,, glGetObjectParameterivARB, GLhandleARB, GLenum, GLint*)
|
||||
proc (handle, pname, dest);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
cogl_program_uniform_1f (COGLint uniform_no,
|
||||
gfloat value)
|
||||
{
|
||||
PROC (GLvoid,, glUniform1fARB, GLint, GLfloat);
|
||||
proc (uniform_no, value);
|
||||
}
|
||||
|
@ -460,6 +460,24 @@ typedef GLuint COGLuint;
|
||||
#define CGL_UNSIGNED_SHORT_8_8_REV_MESA 0
|
||||
#define CGL_UNSIGNED_SHORT_8_8_MESA 0
|
||||
|
||||
#ifdef GL_FRAGMENT_SHADER
|
||||
#define CGL_FRAGMENT_SHADER GL_FRAGMENT_SHADER
|
||||
#else
|
||||
#define CGL_FRAGMENT_SHADER 0
|
||||
#endif
|
||||
|
||||
#ifdef GL_VERTEX_SHADER
|
||||
#define CGL_VERTEX_SHADER GL_VERTEX_SHADER
|
||||
#else
|
||||
#define CGL_VERTEX_SHADER 0
|
||||
#endif
|
||||
|
||||
#ifdef GL_OBJECT_COMPILE_STATUS
|
||||
#define CGL_OBJECT_COMPILE_STATUS GL_OBJECT_COMPILE_STATUS
|
||||
#else
|
||||
#define CGL_OBJECT_COMPILE_STATUS 0
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
68
gles/cogl.c
68
gles/cogl.c
@ -214,13 +214,13 @@ cogl_enable (gulong flags)
|
||||
if (flags & CGL_ENABLE_TEXTURE_RECT)
|
||||
{
|
||||
if (!(__enable_flags & CGL_ENABLE_TEXTURE_RECT))
|
||||
glEnable (GL_TEXTURE_RECTANGLE_ARB);
|
||||
glEnable (GL_TEXTURE_RECTANGLE_);
|
||||
|
||||
__enable_flags |= CGL_ENABLE_TEXTURE_RECT;
|
||||
}
|
||||
else if (__enable_flags & CGL_ENABLE_TEXTURE_RECT)
|
||||
{
|
||||
glDisable (GL_TEXTURE_RECTANGLE_ARB);
|
||||
glDisable (GL_TEXTURE_RECTANGLE_);
|
||||
__enable_flags &= ~CGL_ENABLE_TEXTURE_RECT;
|
||||
}
|
||||
#endif
|
||||
@ -630,3 +630,67 @@ cogl_fog_set (const ClutterColor *fog_color,
|
||||
glFogx (GL_FOG_START, (GLfixed) z_near);
|
||||
glFogx (GL_FOG_END, (GLfixed) z_far);
|
||||
}
|
||||
|
||||
COGLint cogl_create_program (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
COGLint cogl_create_shader (COGLenum shaderType)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cogl_shader_source (COGLint shader,
|
||||
const gchar *source)
|
||||
{
|
||||
}
|
||||
|
||||
void cogl_shader_compile (COGLint shader_handle)
|
||||
{
|
||||
}
|
||||
|
||||
void cogl_program_attach_shader (COGLint program_handle,
|
||||
COGLint shader_handle)
|
||||
{
|
||||
}
|
||||
|
||||
void cogl_program_link (COGLint program_handle)
|
||||
{
|
||||
}
|
||||
|
||||
void cogl_program_use (COGLint program_handle)
|
||||
{
|
||||
}
|
||||
|
||||
COGLint cogl_program_get_uniform_location (COGLint program_handle,
|
||||
const gchar *uniform_name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cogl_program_destroy (COGLint handle)
|
||||
{
|
||||
}
|
||||
|
||||
void cogl_shader_destroy (COGLint handle)
|
||||
{
|
||||
}
|
||||
|
||||
void cogl_shader_get_info_log (COGLint handle,
|
||||
guint size,
|
||||
gchar *buffer)
|
||||
{
|
||||
}
|
||||
|
||||
void cogl_shader_get_parameteriv (COGLint handle,
|
||||
COGLenum pname,
|
||||
COGLint *dest)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void cogl_program_uniform_1f (COGLint uniform_no,
|
||||
gfloat value)
|
||||
{
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user