mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-25 15:10:10 +01:00
Implement gl_PointCoord attribute for GLSL fragment shaders.
Contains the normalized fragment position within a point sprite.
This commit is contained in:
parent
3a345e0003
commit
f68fce1f1f
6 changed files with 83 additions and 51 deletions
|
|
@ -282,6 +282,8 @@ sampler_to_texture_index(const slang_type_specifier_type type)
|
|||
}
|
||||
|
||||
|
||||
#define SWIZZLE_ZWWW MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_W, SWIZZLE_W, SWIZZLE_W)
|
||||
|
||||
/**
|
||||
* Return the VERT_ATTRIB_* or FRAG_ATTRIB_* value that corresponds to
|
||||
* a vertex or fragment program input variable. Return -1 if the input
|
||||
|
|
@ -316,9 +318,11 @@ _slang_input_index(const char *name, GLenum target, GLuint *swizzleOut)
|
|||
{ "gl_FragCoord", FRAG_ATTRIB_WPOS, SWIZZLE_NOOP },
|
||||
{ "gl_Color", FRAG_ATTRIB_COL0, SWIZZLE_NOOP },
|
||||
{ "gl_SecondaryColor", FRAG_ATTRIB_COL1, SWIZZLE_NOOP },
|
||||
{ "gl_FogFragCoord", FRAG_ATTRIB_FOGC, SWIZZLE_XXXX },
|
||||
{ "gl_TexCoord", FRAG_ATTRIB_TEX0, SWIZZLE_NOOP },
|
||||
/* note: we're packing several quantities into the fogcoord vector */
|
||||
{ "gl_FogFragCoord", FRAG_ATTRIB_FOGC, SWIZZLE_XXXX },
|
||||
{ "gl_FrontFacing", FRAG_ATTRIB_FOGC, SWIZZLE_YYYY }, /*XXX*/
|
||||
{ "gl_PointCoord", FRAG_ATTRIB_FOGC, SWIZZLE_ZWWW },
|
||||
{ NULL, 0, SWIZZLE_NOOP }
|
||||
};
|
||||
GLuint i;
|
||||
|
|
|
|||
|
|
@ -1983,6 +1983,10 @@ static const byte slang_120_core_gc[] = {
|
|||
#include "library/slang_120_core_gc.h"
|
||||
};
|
||||
|
||||
static const byte slang_120_fragment_gc[] = {
|
||||
#include "library/slang_builtin_120_fragment_gc.h"
|
||||
};
|
||||
|
||||
static const byte slang_common_builtin_gc[] = {
|
||||
#include "library/slang_common_builtin_gc.h"
|
||||
};
|
||||
|
|
@ -2059,6 +2063,13 @@ compile_object(grammar * id, const char *source, slang_code_object * object,
|
|||
SLANG_UNIT_FRAGMENT_BUILTIN, infolog, NULL,
|
||||
&object->builtin[SLANG_BUILTIN_COMMON], NULL))
|
||||
return GL_FALSE;
|
||||
#if FEATURE_ARB_shading_language_120
|
||||
if (!compile_binary(slang_120_fragment_gc,
|
||||
&object->builtin[SLANG_BUILTIN_TARGET],
|
||||
SLANG_UNIT_FRAGMENT_BUILTIN, infolog, NULL,
|
||||
&object->builtin[SLANG_BUILTIN_COMMON], NULL))
|
||||
return GL_FALSE;
|
||||
#endif
|
||||
}
|
||||
else if (type == SLANG_UNIT_VERTEX_SHADER) {
|
||||
if (!compile_binary(slang_vertex_builtin_gc,
|
||||
|
|
|
|||
|
|
@ -168,7 +168,6 @@ _swrast_fog_rgba_span( const GLcontext *ctx, SWspan *span )
|
|||
GLfloat rFog, gFog, bFog;
|
||||
|
||||
ASSERT(swrast->_FogEnabled);
|
||||
ASSERT(swrast->_ActiveAttribMask & FRAG_BIT_FOGC);
|
||||
ASSERT(span->arrayMask & SPAN_RGBA);
|
||||
|
||||
/* compute (scaled) fog color */
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine,
|
|||
machine->DerivY = (GLfloat (*)[4]) span->attrStepY;
|
||||
machine->NumDeriv = FRAG_ATTRIB_MAX;
|
||||
|
||||
/* if running a GLSL program (not ARB_fragment_program) */
|
||||
if (ctx->Shader.CurrentProgram) {
|
||||
/* Store front/back facing value in register FOGC.Y */
|
||||
machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = (GLfloat) ctx->_Facing;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
{
|
||||
GLfloat s, r, dsdx;
|
||||
|
||||
s = 0.0;
|
||||
dsdx = 1.0 / size;
|
||||
/* 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;
|
||||
}
|
||||
|
||||
if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT) {
|
||||
t0 = 0.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 {
|
||||
/* 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;
|
||||
|
||||
}
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -1180,7 +1180,7 @@ shade_texture_span(GLcontext *ctx, SWspan *span)
|
|||
if (span->primitive == GL_BITMAP && span->array->ChanType != GL_FLOAT) {
|
||||
convert_color_type(span, GL_FLOAT, 0);
|
||||
}
|
||||
if (span->primitive != GL_POINT) {
|
||||
if (span->primitive != GL_POINT || ctx->Point.PointSprite) {
|
||||
/* for points, we populated the arrays already */
|
||||
interpolate_active_attribs(ctx, span, ~0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue