2 * Mesa 3-D graphics library
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #include "s_arbshader.h"
32 #include "s_context.h"
33 #include "shaderobjects.h"
34 #include "shaderobjects_3dlabs.h"
35 #include "slang_utility.h"
36 #include "slang_link.h"
38 void _swrast_exec_arbshader (GLcontext
*ctx
, struct sw_span
*span
)
40 struct gl2_program_intf
**pro
;
43 if (!ctx
->ShaderObjects
._FragmentShaderPresent
)
45 pro
= ctx
->ShaderObjects
.CurrentProgram
;
46 if (!ctx
->ShaderObjects
._VertexShaderPresent
)
47 (**pro
).UpdateFixedUniforms (pro
);
49 for (i
= span
->start
; i
< span
->end
; i
++)
51 /* only run shader on active fragments */
52 if (span
->array
->mask
[i
]) {
57 vec
[0] = (GLfloat
) span
->x
+ i
;
58 vec
[1] = (GLfloat
) span
->y
;
59 vec
[2] = (GLfloat
) span
->array
->z
[i
] / ctx
->DrawBuffer
->_DepthMaxF
;
60 vec
[3] = span
->w
+ span
->dwdx
* i
;
61 (**pro
).UpdateFixedVarying (pro
, SLANG_FRAGMENT_FIXED_FRAGCOORD
, vec
, 0,
62 4 * sizeof (GLfloat
), GL_TRUE
);
63 vec
[0] = CHAN_TO_FLOAT(span
->array
->rgba
[i
][RCOMP
]);
64 vec
[1] = CHAN_TO_FLOAT(span
->array
->rgba
[i
][GCOMP
]);
65 vec
[2] = CHAN_TO_FLOAT(span
->array
->rgba
[i
][BCOMP
]);
66 vec
[3] = CHAN_TO_FLOAT(span
->array
->rgba
[i
][ACOMP
]);
67 (**pro
).UpdateFixedVarying (pro
, SLANG_FRAGMENT_FIXED_COLOR
, vec
, 0, 4 * sizeof (GLfloat
),
69 for (j
= 0; j
< ctx
->Const
.MaxTextureCoordUnits
; j
++)
71 vec
[0] = span
->array
->texcoords
[j
][i
][0];
72 vec
[1] = span
->array
->texcoords
[j
][i
][1];
73 vec
[2] = span
->array
->texcoords
[j
][i
][2];
74 vec
[3] = span
->array
->texcoords
[j
][i
][3];
75 (**pro
).UpdateFixedVarying (pro
, SLANG_FRAGMENT_FIXED_TEXCOORD
, vec
, j
,
76 4 * sizeof (GLfloat
), GL_TRUE
);
78 for (j
= 0; j
< MAX_VARYING_VECTORS
; j
++)
82 for (k
= 0; k
< VARYINGS_PER_VECTOR
; k
++)
84 (**pro
).UpdateVarying (pro
, j
* VARYINGS_PER_VECTOR
+ k
,
85 &span
->array
->varying
[i
][j
][k
], GL_FALSE
);
89 _slang_exec_fragment_shader (pro
);
91 _slang_fetch_discard (pro
, &discard
);
94 span
->array
->mask
[i
] = GL_FALSE
;
95 span
->writeAll
= GL_FALSE
;
99 (**pro
).UpdateFixedVarying (pro
, SLANG_FRAGMENT_FIXED_FRAGCOLOR
, vec
, 0,
100 4 * sizeof (GLfloat
), GL_FALSE
);
101 UNCLAMPED_FLOAT_TO_CHAN(span
->array
->rgba
[i
][RCOMP
], vec
[0]);
102 UNCLAMPED_FLOAT_TO_CHAN(span
->array
->rgba
[i
][GCOMP
], vec
[1]);
103 UNCLAMPED_FLOAT_TO_CHAN(span
->array
->rgba
[i
][BCOMP
], vec
[2]);
104 UNCLAMPED_FLOAT_TO_CHAN(span
->array
->rgba
[i
][ACOMP
], vec
[3]);