9cd96c5a366166d0aec901e3f4566ed979963058
[mesa.git] / src / mesa / swrast / s_arbshader.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 *
24 * Authors:
25 * Michal Krol
26 */
27
28 #include "glheader.h"
29 #include "context.h"
30 #include "colormac.h"
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"
37
38 void _swrast_exec_arbshader (GLcontext *ctx, struct sw_span *span)
39 {
40 struct gl2_program_intf **pro;
41 GLuint i;
42
43 if (!ctx->ShaderObjects._FragmentShaderPresent)
44 return;
45 pro = ctx->ShaderObjects.CurrentProgram;
46 if (!ctx->ShaderObjects._VertexShaderPresent)
47 (**pro).UpdateFixedUniforms (pro);
48
49 for (i = span->start; i < span->end; i++)
50 {
51 /* only run shader on active fragments */
52 if (span->array->mask[i]) {
53 GLfloat vec[4];
54 GLuint j;
55 GLboolean discard;
56
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),
68 GL_TRUE);
69 for (j = 0; j < ctx->Const.MaxTextureCoordUnits; j++)
70 {
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);
77 }
78 for (j = 0; j < MAX_VARYING_VECTORS; j++)
79 {
80 GLuint k;
81
82 for (k = 0; k < VARYINGS_PER_VECTOR; k++)
83 {
84 (**pro).UpdateVarying (pro, j * VARYINGS_PER_VECTOR + k,
85 &span->array->varying[i][j][k], GL_FALSE);
86 }
87 }
88
89 _slang_exec_fragment_shader (pro);
90
91 _slang_fetch_discard (pro, &discard);
92 if (discard)
93 {
94 span->array->mask[i] = GL_FALSE;
95 span->writeAll = GL_FALSE;
96 }
97 else
98 {
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]);
105 }
106 }
107 }
108 }
109