summaryrefslogtreecommitdiffstats
path: root/src/mesa/swrast/s_points.c
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-10-24 11:37:05 -0600
committerBrian <[email protected]>2007-10-24 12:38:07 -0600
commitf68fce1f1f61997f284b77cca5b5765cd7443240 (patch)
treee1398a0d0a38ca30a25d667cdfab0db025ebc5d5 /src/mesa/swrast/s_points.c
parent3a345e000350c1590367f01be5db6f0f10701283 (diff)
Implement gl_PointCoord attribute for GLSL fragment shaders.
Contains the normalized fragment position within a point sprite.
Diffstat (limited to 'src/mesa/swrast/s_points.c')
-rw-r--r--src/mesa/swrast/s_points.c117
1 files changed, 67 insertions, 50 deletions
diff --git a/src/mesa/swrast/s_points.c b/src/mesa/swrast/s_points.c
index 4768fbea972..c0f32e9c91b 100644
--- a/src/mesa/swrast/s_points.c
+++ b/src/mesa/swrast/s_points.c
@@ -55,7 +55,7 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
SWcontext *swrast = SWRAST_CONTEXT(ctx);
SWspan span;
GLfloat size;
- GLuint tCoords[MAX_TEXTURE_COORD_UNITS];
+ GLuint tCoords[MAX_TEXTURE_COORD_UNITS + 1];
GLuint numTcoords = 0;
GLfloat t0, dtdy;
@@ -99,57 +99,71 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
span.attrStepX[FRAG_ATTRIB_WPOS][3] = 0.0F;
span.attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0F;
- ATTRIB_LOOP_BEGIN
- if (attr >= FRAG_ATTRIB_TEX0 && attr < FRAG_ATTRIB_VAR0) {
- const GLuint u = attr - FRAG_ATTRIB_TEX0;
- /* a texcoord */
- if (ctx->Point.CoordReplace[u]) {
- GLfloat s, r, dsdx;
-
- s = 0.0;
- dsdx = 1.0 / size;
-
- if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT) {
- t0 = 0.0;
- dtdy = 1.0 / size;
- }
- else {
- /* GL_UPPER_LEFT */
- t0 = 1.0;
- dtdy = -1.0 / size;
- }
- tCoords[numTcoords++] = attr;
-
- if (ctx->Point.SpriteRMode == GL_ZERO)
- r = 0.0F;
- else if (ctx->Point.SpriteRMode == GL_S)
- r = vert->attrib[attr][0];
- else /* GL_R */
- r = vert->attrib[attr][2];
-
- span.attrStart[attr][0] = s;
- span.attrStart[attr][1] = 0.0; /* overwritten below */
- span.attrStart[attr][2] = r;
- span.attrStart[attr][3] = 1.0;
-
- span.attrStepX[attr][0] = dsdx;
- span.attrStepX[attr][1] = 0.0;
- span.attrStepX[attr][2] = 0.0;
- span.attrStepX[attr][3] = 0.0;
-
- span.attrStepY[attr][0] = 0.0;
- span.attrStepY[attr][1] = dtdy;
- span.attrStepY[attr][2] = 0.0;
- span.attrStepY[attr][3] = 0.0;
+ {
+ GLfloat s, r, dsdx;
+
+ /* texcoord / pointcoord interpolants */
+ s = 0.0;
+ dsdx = 1.0 / size;
+ if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT) {
+ t0 = 0.0;
+ dtdy = 1.0 / size;
+ }
+ else {
+ /* GL_UPPER_LEFT */
+ t0 = 1.0;
+ dtdy = -1.0 / size;
+ }
+ ATTRIB_LOOP_BEGIN
+ if (attr >= FRAG_ATTRIB_TEX0 && attr < FRAG_ATTRIB_VAR0) {
+ const GLuint u = attr - FRAG_ATTRIB_TEX0;
+ /* a texcoord */
+ if (ctx->Point.CoordReplace[u]) {
+ tCoords[numTcoords++] = attr;
+
+ if (ctx->Point.SpriteRMode == GL_ZERO)
+ r = 0.0F;
+ else if (ctx->Point.SpriteRMode == GL_S)
+ r = vert->attrib[attr][0];
+ else /* GL_R */
+ r = vert->attrib[attr][2];
+
+ span.attrStart[attr][0] = s;
+ span.attrStart[attr][1] = 0.0; /* overwritten below */
+ span.attrStart[attr][2] = r;
+ span.attrStart[attr][3] = 1.0;
+
+ span.attrStepX[attr][0] = dsdx;
+ span.attrStepX[attr][1] = 0.0;
+ span.attrStepX[attr][2] = 0.0;
+ span.attrStepX[attr][3] = 0.0;
+
+ span.attrStepY[attr][0] = 0.0;
+ span.attrStepY[attr][1] = dtdy;
+ span.attrStepY[attr][2] = 0.0;
+ span.attrStepY[attr][3] = 0.0;
+
+ continue;
+ }
+ }
+ else if (attr == FRAG_ATTRIB_FOGC) {
+ /* GLSL gl_PointCoord is stored in fog.zw */
+ span.attrStart[FRAG_ATTRIB_FOGC][2] = 0.0;
+ span.attrStart[FRAG_ATTRIB_FOGC][3] = 0.0; /* t0 set below */
+ span.attrStepX[FRAG_ATTRIB_FOGC][2] = dsdx;
+ span.attrStepX[FRAG_ATTRIB_FOGC][3] = 0.0;
+ span.attrStepY[FRAG_ATTRIB_FOGC][2] = 0.0;
+ span.attrStepY[FRAG_ATTRIB_FOGC][3] = dtdy;
+ tCoords[numTcoords++] = FRAG_ATTRIB_FOGC;
continue;
}
- }
- /* use vertex's texcoord/attrib */
- COPY_4V(span.attrStart[attr], vert->attrib[attr]);
- ASSIGN_4V(span.attrStepX[attr], 0, 0, 0, 0);
- ASSIGN_4V(span.attrStepY[attr], 0, 0, 0, 0);
- ATTRIB_LOOP_END
+ /* use vertex's texcoord/attrib */
+ COPY_4V(span.attrStart[attr], vert->attrib[attr]);
+ ASSIGN_4V(span.attrStepX[attr], 0, 0, 0, 0);
+ ASSIGN_4V(span.attrStepY[attr], 0, 0, 0, 0);
+ ATTRIB_LOOP_END;
+ }
/* compute pos, bounds and render */
{
@@ -183,7 +197,10 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
GLuint i;
/* setup texcoord T for this row */
for (i = 0; i < numTcoords; i++) {
- span.attrStart[tCoords[i]][1] = tcoord;
+ if (tCoords[i] == FRAG_ATTRIB_FOGC)
+ span.attrStart[FRAG_ATTRIB_FOGC][3] = tcoord;
+ else
+ span.attrStart[tCoords[i]][1] = tcoord;
}
/* these might get changed by span clipping */