GLuint VAO;
GLuint VBO;
GLuint DepthFP;
- GLuint ShaderProg;
- GLuint RectShaderProg;
+ struct sampler_table samplers;
struct temp_texture depthTex;
};
"void main()\n"
"{\n"
" gl_FragColor = %s(texSampler, %s);\n"
+ " gl_FragDepth = gl_FragColor.x;\n"
"}\n",
sampler->type,
sampler->func, sampler->texcoords);
"void main()\n"
"{\n"
" out_color = texture(texSampler, %s);\n"
+ " gl_FragDepth = out_color.x;\n"
"}\n",
_mesa_is_desktop_gl(ctx) ? "130" : "300 es",
sampler->type,
struct blit_state *blit,
GLenum target)
{
- const char *vs_source;
- char *fs_source;
- GLuint vs, fs;
- void *mem_ctx;
- GLuint ShaderProg;
- GLboolean texture_2d = (target == GL_TEXTURE_2D);
+ struct glsl_sampler *sampler;
/* target = GL_TEXTURE_RECTANGLE is not supported in GLES 3.0 */
- assert(_mesa_is_desktop_gl(ctx) || texture_2d);
+ assert(_mesa_is_desktop_gl(ctx) || target == GL_TEXTURE_2D);
setup_vertex_objects(&blit->VAO, &blit->VBO, true, 2, 2, 0);
/* Generate a relevant fragment shader program for the texture target */
- if ((target == GL_TEXTURE_2D && blit->ShaderProg != 0) ||
- (target == GL_TEXTURE_RECTANGLE && blit->RectShaderProg != 0)) {
- return;
- }
-
- mem_ctx = ralloc_context(NULL);
-
- if (ctx->Const.GLSLVersion < 130) {
- vs_source =
- "attribute vec2 position;\n"
- "attribute vec2 textureCoords;\n"
- "varying vec2 texCoords;\n"
- "void main()\n"
- "{\n"
- " texCoords = textureCoords;\n"
- " gl_Position = vec4(position, 0.0, 1.0);\n"
- "}\n";
-
- fs_source = ralloc_asprintf(mem_ctx,
- "#ifdef GL_ES\n"
- "precision highp float;\n"
- "#endif\n"
- "uniform %s texSampler;\n"
- "varying vec2 texCoords;\n"
- "void main()\n"
- "{\n"
- " gl_FragColor = %s(texSampler, texCoords);\n"
- " gl_FragDepth = gl_FragColor.r;\n"
- "}\n",
- texture_2d ? "sampler2D" : "sampler2DRect",
- texture_2d ? "texture2D" : "texture2DRect");
- }
- else {
- vs_source = ralloc_asprintf(mem_ctx,
- "#version %s\n"
- "in vec2 position;\n"
- "in vec2 textureCoords;\n"
- "out vec2 texCoords;\n"
- "void main()\n"
- "{\n"
- " texCoords = textureCoords;\n"
- " gl_Position = vec4(position, 0.0, 1.0);\n"
- "}\n",
- _mesa_is_desktop_gl(ctx) ? "130" : "300 es");
- fs_source = ralloc_asprintf(mem_ctx,
- "#version %s\n"
- "#ifdef GL_ES\n"
- "precision highp float;\n"
- "#endif\n"
- "uniform %s texSampler;\n"
- "in vec2 texCoords;\n"
- "out vec4 out_color;\n"
- "\n"
- "void main()\n"
- "{\n"
- " out_color = %s(texSampler, texCoords);\n"
- " gl_FragDepth = out_color.r;\n"
- "}\n",
- _mesa_is_desktop_gl(ctx) ? "130" : "300 es",
- texture_2d ? "sampler2D" : "sampler2DRect",
- texture_2d ? "texture" : "texture2DRect");
- }
-
- vs = compile_shader_with_debug(ctx, GL_VERTEX_SHADER, vs_source);
- fs = compile_shader_with_debug(ctx, GL_FRAGMENT_SHADER, fs_source);
+ sampler = setup_texture_sampler(target, &blit->samplers);
+ assert(sampler != NULL);
- ShaderProg = _mesa_CreateProgramObjectARB();
- _mesa_AttachShader(ShaderProg, fs);
- _mesa_DeleteObjectARB(fs);
- _mesa_AttachShader(ShaderProg, vs);
- _mesa_DeleteObjectARB(vs);
- _mesa_BindAttribLocation(ShaderProg, 0, "position");
- _mesa_BindAttribLocation(ShaderProg, 1, "texcoords");
- link_program_with_debug(ctx, ShaderProg);
- ralloc_free(mem_ctx);
- if (texture_2d)
- blit->ShaderProg = ShaderProg;
- else
- blit->RectShaderProg = ShaderProg;
+ setup_shader_for_sampler(ctx, sampler);
}
/**
if (glsl_version) {
setup_glsl_blit_framebuffer(ctx, blit, target);
if (target == GL_TEXTURE_2D)
- _mesa_UseProgram(blit->ShaderProg);
+ _mesa_UseProgram(blit->samplers.sampler_2d.shader_prog);
else
- _mesa_UseProgram(blit->RectShaderProg);
+ _mesa_UseProgram(blit->samplers.sampler_rect.shader_prog);
}
else {
setup_ff_tnl_for_blit(&ctx->Meta->Blit.VAO,
if (use_glsl_version) {
setup_glsl_blit_framebuffer(ctx, blit, tex->Target);
if (tex->Target == GL_TEXTURE_2D)
- _mesa_UseProgram(blit->ShaderProg);
+ _mesa_UseProgram(blit->samplers.sampler_2d.shader_prog);
else
- _mesa_UseProgram(blit->RectShaderProg);
+ _mesa_UseProgram(blit->samplers.sampler_rect.shader_prog);
}
else {
setup_ff_tnl_for_blit(&blit->VAO, &blit->VBO, 2);
blit->DepthFP = 0;
}
- _mesa_DeleteObjectARB(blit->ShaderProg);
- blit->ShaderProg = 0;
- _mesa_DeleteObjectARB(blit->RectShaderProg);
- blit->RectShaderProg = 0;
+ sampler_table_cleanup(&blit->samplers);
_mesa_DeleteTextures(1, &blit->depthTex.TexObj);
blit->depthTex.TexObj = 0;