示例#1
0
int stopOGLRendering()
{

    if ( ( selectedFragmentShader != 0) || ( selectedVertexShader != 0 ) )
    {
        unloadShader(loadedShader);
    }

}
void Animation::loadShader(const char *fragment_path) {

    std::string fragShaderStr = readFile(fragment_path);
    const gchar *fragShaderSrc = fragShaderStr.c_str();

    // Pop off the old shader:
    unloadShader();

    printf("Loading shader: '%s' \n", fragment_path);

    // Setup the GLSL Fragment shaders that we'll use to generate colors
    // Build a GLSL Fragment shader to affect the color output (to the screen at least for now)
    shaderEffect = clutter_shader_effect_new(CLUTTER_FRAGMENT_SHADER);
    clutter_shader_effect_set_shader_source(CLUTTER_SHADER_EFFECT(shaderEffect), fragShaderSrc);

    // Start fuckups:
//    ClutterEffect *effect = clutter_blur_effect_new (); // works
//    ClutterEffect *effect = clutter_sensatron_effect_new ();
//    clutter_sensatron_effect_set_shader_source(CLUTTER_SENSATRON_EFFECT(effect), fragShaderSrc);
    // Now, let's try attaching a texture to this bitch!!
//    CoglTexture *texture = cogl_texture_new_from_file(textureFile,
//                                                      COGL_TEXTURE_NONE,
//                                                      COGL_PIXEL_FORMAT_ANY,
//                                                      &error);
    // Try attaching the texture to the effect (on the 1th layer?):
//    cogl_pipeline_set_layer_texture (priv->pipeline, 1, texture);
//    CoglPipeline *target;
//    target = COGL_PIPELINE (clutter_offscreen_effect_get_target ((ClutterOffscreenEffect)shaderEffect));
    // End fuckups


    // Bind uniforms to the shader so we can hand variables into them
    animationTime = 0.0;
    currentSpeed = 100;

    clutter_shader_effect_set_uniform(CLUTTER_SHADER_EFFECT(shaderEffect), "iGlobalTime", G_TYPE_FLOAT, 1, animationTime);
    clutter_shader_effect_set_uniform(CLUTTER_SHADER_EFFECT(shaderEffect), "iResolution", G_TYPE_FLOAT, 2, HEIGHT*osd_scale, WIDTH*osd_scale);
    clutter_shader_effect_set_uniform(CLUTTER_SHADER_EFFECT(shaderEffect), "iMouse", G_TYPE_FLOAT, 2, input_x*osd_scale, input_y*osd_scale);
//    clutter_shader_effect_set_uniform(CLUTTER_SHADER_EFFECT(shaderEffect), "iChannel0", CLUTTER_TYPE_SHADER_FLOAT, 1, audioTexture);
//    clutter_shader_effect_set_uniform(CLUTTER_SHADER_EFFECT(shaderEffect), "iChannel1", CLUTTER_TYPE_SHADER_FLOAT, 1, noiseTexture);


    // Set the effect live on the on screen display actor...
    clutter_actor_add_effect(shaderOutput, shaderEffect);

//    clutter_actor_add_effect(shaderOutput, effect);
    shaderLoaded = true;
}