[Mesa-dev] [PATCH] glsl/geom-stipple-lines: Pass pattern as int to GS.

Fabian Bieler fabianbieler at fastmail.fm
Wed Feb 5 11:50:51 PST 2014


Pass pattern as bitmask in a unsigned int instead of as array of floats to the
geometry shader.

Signed-off-by: Fabian Bieler <fabianbieler at fastmail.fm>
---
 src/glsl/geom-stipple-lines.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/src/glsl/geom-stipple-lines.c b/src/glsl/geom-stipple-lines.c
index e56d1f3..e5f8879 100644
--- a/src/glsl/geom-stipple-lines.c
+++ b/src/glsl/geom-stipple-lines.c
@@ -41,24 +41,11 @@ CheckError(int line)
  /**
  * Set stipple factor and pattern for geometry shader.
- *
- * We convert the 16-bit stipple pattern into an array of 16 float values
- * then pass the array as a uniform variable.
- *
- * Note: With GLSL 1.30 or later the stipple pattern could be implemented
- * as an ordinary integer since GLSL 1.30 has true integer types and bit
- * shifts and bit masks.
- *
  */
 static void
 SetStippleUniform(GLint factor, GLushort pattern)
 {
-   GLfloat p[16];
-   int i;
-   for (i = 0; i < 16; i++) {
-      p[i] = (pattern & (1 << i)) ? 1.0f : 0.0f;
-   }
-   glUniform1fv(uStipplePattern, 16, p);
+   glUniform1ui(uStipplePattern, pattern);
    glUniform1f(uStippleFactor, factor);
 }
 @@ -270,7 +257,7 @@ Init(void)
 {
    static const char *fragShaderText =
       "#version 150 \n"
-      "uniform float StipplePattern[16]; \n"
+      "uniform uint StipplePattern; \n"
       "in vec4 g2f_Color; \n"
       "in float stippleCoord; \n"
       "out vec4 FragColor; \n"
@@ -279,8 +266,8 @@ Init(void)
       "   // check the stipple pattern and discard if value is zero \n"
       "   // TODO: we should really undo the perspective interpolation here \n"
       "   // so that it's linear. \n"
-      "   float stip = StipplePattern[int(fract(stippleCoord) * 16.0)]; \n"
-      "   if (stip == 0.0) \n"
+      "   uint stip = (StipplePattern >> uint(fract(stippleCoord) * 16.0)) & 1u; \n"
+      "   if (stip == 0u) \n"
       "      discard; \n"
       "   FragColor = g2f_Color; \n"
       "} \n";
-- 
1.8.5.3



More information about the mesa-dev mailing list