Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygens_fragprog.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 7.0.3 00004 * 00005 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a 00008 * copy of this software and associated documentation files (the "Software"), 00009 * to deal in the Software without restriction, including without limitation 00010 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 * and/or sell copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included 00015 * in all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00018 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00021 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00022 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 #include "main/glheader.h" 00026 #include "main/colormac.h" 00027 #include "main/context.h" 00028 #include "main/texstate.h" 00029 #include "shader/prog_instruction.h" 00030 00031 #include "s_fragprog.h" 00032 #include "s_span.h" 00033 00034 00039 static void 00040 fetch_texel_lod( GLcontext *ctx, const GLfloat texcoord[4], GLfloat lambda, 00041 GLuint unit, GLfloat color[4] ) 00042 { 00043 const struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current; 00044 00045 if (texObj) { 00046 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00047 GLchan rgba[4]; 00048 00049 lambda = CLAMP(lambda, texObj->MinLod, texObj->MaxLod); 00050 00051 /* XXX use a float-valued TextureSample routine here!!! */ 00052 swrast->TextureSample[unit](ctx, texObj, 1, 00053 (const GLfloat (*)[4]) texcoord, 00054 &lambda, &rgba); 00055 color[0] = CHAN_TO_FLOAT(rgba[0]); 00056 color[1] = CHAN_TO_FLOAT(rgba[1]); 00057 color[2] = CHAN_TO_FLOAT(rgba[2]); 00058 color[3] = CHAN_TO_FLOAT(rgba[3]); 00059 } 00060 else { 00061 color[0] = color[1] = color[2] = 0.0F; 00062 color[3] = 1.0F; 00063 } 00064 } 00065 00066 00072 static void 00073 fetch_texel_deriv( GLcontext *ctx, const GLfloat texcoord[4], 00074 const GLfloat texdx[4], const GLfloat texdy[4], 00075 GLfloat lodBias, GLuint unit, GLfloat color[4] ) 00076 { 00077 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00078 const struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current; 00079 00080 if (texObj) { 00081 const struct gl_texture_image *texImg = 00082 texObj->Image[0][texObj->BaseLevel]; 00083 const GLfloat texW = (GLfloat) texImg->WidthScale; 00084 const GLfloat texH = (GLfloat) texImg->HeightScale; 00085 GLfloat lambda; 00086 GLchan rgba[4]; 00087 00088 lambda = _swrast_compute_lambda(texdx[0], texdy[0], /* ds/dx, ds/dy */ 00089 texdx[1], texdy[1], /* dt/dx, dt/dy */ 00090 texdx[3], texdy[2], /* dq/dx, dq/dy */ 00091 texW, texH, 00092 texcoord[0], texcoord[1], texcoord[3], 00093 1.0F / texcoord[3]) + lodBias; 00094 00095 lambda = CLAMP(lambda, texObj->MinLod, texObj->MaxLod); 00096 00097 /* XXX use a float-valued TextureSample routine here!!! */ 00098 swrast->TextureSample[unit](ctx, texObj, 1, 00099 (const GLfloat (*)[4]) texcoord, 00100 &lambda, &rgba); 00101 color[0] = CHAN_TO_FLOAT(rgba[0]); 00102 color[1] = CHAN_TO_FLOAT(rgba[1]); 00103 color[2] = CHAN_TO_FLOAT(rgba[2]); 00104 color[3] = CHAN_TO_FLOAT(rgba[3]); 00105 } 00106 else { 00107 color[0] = color[1] = color[2] = 0.0F; 00108 color[3] = 1.0F; 00109 } 00110 } 00111 00112 00122 static void 00123 init_machine(GLcontext *ctx, struct gl_program_machine *machine, 00124 const struct gl_fragment_program *program, 00125 const SWspan *span, GLuint col) 00126 { 00127 if (program->Base.Target == GL_FRAGMENT_PROGRAM_NV) { 00128 /* Clear temporary registers (undefined for ARB_f_p) */ 00129 _mesa_bzero(machine->Temporaries, 00130 MAX_PROGRAM_TEMPS * 4 * sizeof(GLfloat)); 00131 } 00132 00133 /* Setup pointer to input attributes */ 00134 machine->Attribs = span->array->attribs; 00135 00136 machine->DerivX = (GLfloat (*)[4]) span->attrStepX; 00137 machine->DerivY = (GLfloat (*)[4]) span->attrStepY; 00138 machine->NumDeriv = FRAG_ATTRIB_MAX; 00139 00140 machine->Samplers = program->Base.SamplerUnits; 00141 00142 /* if running a GLSL program (not ARB_fragment_program) */ 00143 if (ctx->Shader.CurrentProgram) { 00144 /* Store front/back facing value in register FOGC.Y */ 00145 machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = 1.0 - span->facing; 00146 /* Note FOGC.ZW is gl_PointCoord if drawing a sprite */ 00147 } 00148 00149 machine->CurElement = col; 00150 00151 /* init condition codes */ 00152 machine->CondCodes[0] = COND_EQ; 00153 machine->CondCodes[1] = COND_EQ; 00154 machine->CondCodes[2] = COND_EQ; 00155 machine->CondCodes[3] = COND_EQ; 00156 00157 /* init call stack */ 00158 machine->StackDepth = 0; 00159 00160 machine->FetchTexelLod = fetch_texel_lod; 00161 machine->FetchTexelDeriv = fetch_texel_deriv; 00162 } 00163 00164 00168 static void 00169 run_program(GLcontext *ctx, SWspan *span, GLuint start, GLuint end) 00170 { 00171 SWcontext *swrast = SWRAST_CONTEXT(ctx); 00172 const struct gl_fragment_program *program = ctx->FragmentProgram._Current; 00173 const GLbitfield outputsWritten = program->Base.OutputsWritten; 00174 struct gl_program_machine *machine = &swrast->FragProgMachine; 00175 GLuint i; 00176 00177 for (i = start; i < end; i++) { 00178 if (span->array->mask[i]) { 00179 init_machine(ctx, machine, program, span, i); 00180 00181 if (_mesa_execute_program(ctx, &program->Base, machine)) { 00182 00183 /* Store result color */ 00184 if (outputsWritten & (1 << FRAG_RESULT_COLR)) { 00185 COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0][i], 00186 machine->Outputs[FRAG_RESULT_COLR]); 00187 } 00188 else { 00189 /* Multiple drawbuffers / render targets 00190 * Note that colors beyond 0 and 1 will overwrite other 00191 * attributes, such as FOGC, TEX0, TEX1, etc. That's OK. 00192 */ 00193 GLuint buf; 00194 for (buf = 0; buf < ctx->DrawBuffer->_NumColorDrawBuffers; buf++) { 00195 if (outputsWritten & (1 << (FRAG_RESULT_DATA0 + buf))) { 00196 COPY_4V(span->array->attribs[FRAG_ATTRIB_COL0 + buf][i], 00197 machine->Outputs[FRAG_RESULT_DATA0 + buf]); 00198 } 00199 } 00200 } 00201 00202 /* Store result depth/z */ 00203 if (outputsWritten & (1 << FRAG_RESULT_DEPR)) { 00204 const GLfloat depth = machine->Outputs[FRAG_RESULT_DEPR][2]; 00205 if (depth <= 0.0) 00206 span->array->z[i] = 0; 00207 else if (depth >= 1.0) 00208 span->array->z[i] = ctx->DrawBuffer->_DepthMax; 00209 else 00210 span->array->z[i] = IROUND(depth * ctx->DrawBuffer->_DepthMaxF); 00211 } 00212 } 00213 else { 00214 /* killed fragment */ 00215 span->array->mask[i] = GL_FALSE; 00216 span->writeAll = GL_FALSE; 00217 } 00218 } 00219 } 00220 } 00221 00222 00227 void 00228 _swrast_exec_fragment_program( GLcontext *ctx, SWspan *span ) 00229 { 00230 const struct gl_fragment_program *program = ctx->FragmentProgram._Current; 00231 00232 /* incoming colors should be floats */ 00233 if (program->Base.InputsRead & FRAG_BIT_COL0) { 00234 ASSERT(span->array->ChanType == GL_FLOAT); 00235 } 00236 00237 ctx->_CurrentProgram = GL_FRAGMENT_PROGRAM_ARB; /* or NV, doesn't matter */ 00238 00239 run_program(ctx, span, 0, span->end); 00240 00241 if (program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR)) { 00242 span->interpMask &= ~SPAN_RGBA; 00243 span->arrayMask |= SPAN_RGBA; 00244 } 00245 00246 if (program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPR)) { 00247 span->interpMask &= ~SPAN_Z; 00248 span->arrayMask |= SPAN_Z; 00249 } 00250 00251 ctx->_CurrentProgram = 0; 00252 } 00253 Generated on Sat May 26 2012 04:19:32 for ReactOS by
1.7.6.1
|