static VALUE rb_cogl_program_use (VALUE self, VALUE program) { if (NIL_P (program)) cogl_program_use (COGL_INVALID_HANDLE); else cogl_program_use (rb_cogl_program_get_handle (program)); return program; }
static void clutter_gst_i420_glsl_init (ClutterGstVideoSink *sink) { ClutterGstVideoSinkPrivate *priv = sink->priv; GLint location; clutter_gst_video_sink_set_glsl_shader (sink, yv12_to_rgba_shader); cogl_program_use (priv->program); location = cogl_program_get_uniform_location (priv->program, "ytex"); cogl_program_uniform_1i (location, 0); location = cogl_program_get_uniform_location (priv->program, "vtex"); cogl_program_uniform_1i (location, 1); location = cogl_program_get_uniform_location (priv->program, "utex"); cogl_program_uniform_1i (location, 2); cogl_program_use (COGL_INVALID_HANDLE); _renderer_connect_signals (sink, clutter_gst_yv12_glsl_paint, clutter_gst_yv12_glsl_post_paint); }
static void clutter_gst_yv12_glsl_post_paint (ClutterActor *actor, ClutterGstVideoSink *sink) { CoglHandle material; /* Remove the extra layers */ material = clutter_texture_get_cogl_material (CLUTTER_TEXTURE (actor)); cogl_material_remove_layer (material, 1); cogl_material_remove_layer (material, 2); /* disable the shader */ cogl_program_use (COGL_INVALID_HANDLE); }
/** * clutter_shader_set_is_enabled: * @shader: a #ClutterShader * @enabled: The new state of the shader. * * Enables a shader. This function will attempt to compile and link * the shader, if it isn't already. * * When @enabled is %FALSE the default state of the GL pipeline will be * used instead. * * Since: 0.6 */ void clutter_shader_set_is_enabled (ClutterShader *shader, gboolean enabled) { ClutterShaderPrivate *priv; g_return_if_fail (CLUTTER_IS_SHADER (shader)); priv = shader->priv; if (priv->is_enabled != enabled) { GError *error = NULL; gboolean res; res = clutter_shader_compile (shader, &error); if (!res) { g_warning ("Unable to bind the shader: %s", error ? error->message : "unknown error"); if (error) g_error_free (error); return; } priv->is_enabled = enabled; if (priv->is_enabled) cogl_program_use (priv->program); else cogl_program_use (COGL_INVALID_HANDLE); g_object_notify (G_OBJECT (shader), "enabled"); } }
static void clutter_gst_yv12_glsl_paint (ClutterActor *actor, ClutterGstVideoSink *sink) { ClutterGstVideoSinkPrivate *priv = sink->priv; CoglHandle material; material = clutter_texture_get_cogl_material (CLUTTER_TEXTURE (actor)); /* bind the shader */ cogl_program_use (priv->program); /* Bind the U and V textures in layers 1 and 2 */ if (priv->u_tex) cogl_material_set_layer (material, 1, priv->u_tex); if (priv->v_tex) cogl_material_set_layer (material, 2, priv->v_tex); }
static void paint_legacy (TestState *state) { CoglHandle material = cogl_material_new (); CoglTexture *tex; CoglColor color; CoglError *error = NULL; CoglHandle shader, program; cogl_color_init_from_4ub (&color, 0, 0, 0, 255); cogl_clear (&color, COGL_BUFFER_BIT_COLOR); /* Set the primary vertex color as red */ cogl_color_set_from_4ub (&color, 0xff, 0x00, 0x00, 0xff); cogl_material_set_color (material, &color); /* Override the vertex color in the texture environment with a constant green color provided by a texture */ tex = create_dummy_texture (); cogl_material_set_layer (material, 0, tex); cogl_object_unref (tex); if (!cogl_material_set_layer_combine (material, 0, "RGBA=REPLACE(TEXTURE)", &error)) { g_warning ("Error setting layer combine: %s", error->message); g_assert_not_reached (); } /* Set up a dummy vertex shader that does nothing but the usual fixed function transform */ shader = cogl_create_shader (COGL_SHADER_TYPE_VERTEX); cogl_shader_source (shader, "void\n" "main ()\n" "{\n" " cogl_position_out = " "cogl_modelview_projection_matrix * " "cogl_position_in;\n" " cogl_color_out = cogl_color_in;\n" " cogl_tex_coord_out[0] = cogl_tex_coord_in;\n" "}\n"); cogl_shader_compile (shader); if (!cogl_shader_is_compiled (shader)) { char *log = cogl_shader_get_info_log (shader); g_warning ("Shader compilation failed:\n%s", log); g_free (log); g_assert_not_reached (); } program = cogl_create_program (); cogl_program_attach_shader (program, shader); cogl_program_link (program); cogl_handle_unref (shader); /* Draw something using the material */ cogl_set_source (material); cogl_rectangle (0, 0, 50, 50); /* Draw it again using the program. It should look exactly the same */ cogl_program_use (program); cogl_rectangle (50, 0, 100, 50); cogl_program_use (COGL_INVALID_HANDLE); cogl_handle_unref (material); cogl_handle_unref (program); }