On 09/11/2012 05:36 PM, Brian Paul wrote:
On 09/11/2012 01:56 AM, Ian Romanick wrote:
On 09/05/2012 05:42 AM, Anuj Phogat wrote:
glsl path of _mesa_meta_GenerateMipmap() function would require
different fragment
shaders depending on the texture target. This patch adds the code to
generate
appropriate fragment shader programs at run time.
Fixes https://bugs.freedesktop.org/show_bug.cgi?id=54296
NOTE: This is a candidate for stable branches.
Signed-off-by: Anuj Phogat <anuj.pho...@gmail.com>
---
src/mesa/drivers/common/meta.c | 100
+++++++++++++++++++++++++++++++++++----
1 files changed, 89 insertions(+), 11 deletions(-)
diff --git a/src/mesa/drivers/common/meta.c
b/src/mesa/drivers/common/meta.c
index 36672a7..7d701f4 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -286,6 +286,15 @@ struct gen_mipmap_state
GLuint IntegerShaderProg;
};
+/**
+ * State for GLSL texture sampler which is used to generate fragment
+ * shader in _mesa_meta_generate_mipmap().
+ */
+struct glsl_sampler {
+ const char *type;
+ const char *func;
+ const char *texcoords;
+};
/**
* State for texture decompression
@@ -2974,7 +2983,7 @@ setup_texture_coords(GLenum faceTarget,
static void
setup_ff_generate_mipmap(struct gl_context *ctx,
- struct gen_mipmap_state *mipmap)
+ struct gen_mipmap_state *mipmap)
{
struct vertex {
GLfloat x, y, tex[3];
@@ -3004,12 +3013,53 @@ setup_ff_generate_mipmap(struct gl_context
*ctx,
static void
+setup_texture_sampler(GLenum target, struct glsl_sampler *sampler)
+{
+ switch(target) {
+ case GL_TEXTURE_1D:
+ sampler->type = "sampler1D";
+ sampler->func = "texture1D";
+ sampler->texcoords = "texCoords.x";
+ break;
+ case GL_TEXTURE_2D:
+ sampler->type = "sampler2D";
+ sampler->func = "texture2D";
+ sampler->texcoords = "texCoords.xy";
+ break;
+ case GL_TEXTURE_3D:
+ sampler->type = "sampler3D";
+ sampler->func = "texture3D";
+ sampler->texcoords = "texCoords";
+ break;
+ case GL_TEXTURE_CUBE_MAP:
+ sampler->type = "samplerCube";
+ sampler->func = "textureCube";
+ sampler->texcoords = "texCoords";
+ break;
+ case GL_TEXTURE_1D_ARRAY:
+ sampler->type = "sampler1DARRAY";
+ sampler->texcoords = "texCoords.xy";
+ break;
+ case GL_TEXTURE_2D_ARRAY:
+ sampler->type = "sampler2DARRAY";
+ sampler->texcoords = "texCoords";
+ break;
+ default:
+ /* unexpected texture target */
+ return;
+ }
+}
+
+
+static void
setup_glsl_generate_mipmap(struct gl_context *ctx,
- struct gen_mipmap_state *mipmap)
+ struct gen_mipmap_state *mipmap,
+ GLenum target)
{
struct vertex {
GLfloat x, y, tex[3];
};
+ struct glsl_sampler sampler;
static const char *vs_source =
"attribute vec2 position;\n"
@@ -3020,14 +3070,17 @@ setup_glsl_generate_mipmap(struct gl_context
*ctx,
" texCoords = textureCoords;\n"
" gl_Position = vec4(position, 0.0, 1.0);\n"
"}\n";
- static const char *fs_source =
- "uniform sampler2D tex2d;\n"
+ static const char *fs_template =
+ "#define SAMPLER_TYPE %s\n"
+ "#define SAMPLER_FUNCTION %s\n"
+ "#define TEX_COORDS %s\n"
Since each of these is only used once, why use the extra #defines? I
believe we can use $ to force the arguments to have the same order.
static const char *fs_template =
"uniform %1$s texSampler;\n"
"varying vec3 texCoords;\n"
"void main()\n"
"{\n"
" gl_FragColor = %2$s(texSampler, %3$s);\n"
"}\n";
This works like the {0} formatting in Python.
Brian, do you know if this is supported on Windows?
I don't think so. I see no mention of it in the MSDN docs and the Linux
man page says "The C99 standard does not include the style using '$',
which comes from the Single Unix Specification."
Dang. :(
To be honest, I wasn't even aware of the $ syntax until you wrote this.
It was added almost 20 years ago for internationalization. It allows
you to have per-language format strings with replacements in different
places to account for word ordering rules in different languages.
-Brian
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev