static void free_fog_data( struct gl_pipeline_stage *stage ) { struct fog_stage_data *store = FOG_STAGE_DATA(stage); if (store) { _mesa_vector1f_free( &store->fogcoord ); FREE( store ); stage->privatePtr = NULL; } }
/* Called the first time stage->run() is invoked. */ static GLboolean alloc_fog_data(struct gl_context *ctx, struct tnl_pipeline_stage *stage) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct fog_stage_data *store; stage->privatePtr = malloc(sizeof(*store)); store = FOG_STAGE_DATA(stage); if (!store) return GL_FALSE; _mesa_vector4f_alloc( &store->fogcoord, 0, tnl->vb.Size, 32 ); if (!inited) init_static_data(); return GL_TRUE; }
/* Called the first time stage->run() is invoked. */ static GLboolean alloc_fog_data( GLcontext *ctx, struct gl_pipeline_stage *stage ) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct fog_stage_data *store; stage->privatePtr = MALLOC(sizeof(*store)); store = FOG_STAGE_DATA(stage); if (!store) return GL_FALSE; _mesa_vector1f_alloc( &store->fogcoord, 0, tnl->vb.Size, 32 ); _mesa_vector1f_init( &store->input, 0, 0 ); if (!inited) init_static_data(); /* Now run the stage. */ stage->run = run_fog_stage; return stage->run( ctx, stage ); }
static GLboolean run_fog_stage(struct gl_context *ctx, struct tnl_pipeline_stage *stage) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; struct fog_stage_data *store = FOG_STAGE_DATA(stage); GLvector4f *input; if (!ctx->Fog.Enabled) return GL_TRUE; if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT && !ctx->VertexProgram._Current) { GLuint i; GLfloat *coord; /* Fog is computed from vertex or fragment Z values */ /* source = VB->AttribPtr[_TNL_ATTRIB_POS] or VB->EyePtr coords */ /* dest = VB->AttribPtr[_TNL_ATTRIB_FOG] = fog stage private storage */ VB->AttribPtr[_TNL_ATTRIB_FOG] = &store->fogcoord; if (!ctx->_NeedEyeCoords) { /* compute fog coords from object coords */ const GLfloat *m = ctx->ModelviewMatrixStack.Top->m; GLfloat plane[4]; /* Use this to store calculated eye z values: */ input = &store->fogcoord; plane[0] = m[2]; plane[1] = m[6]; plane[2] = m[10]; plane[3] = m[14]; /* Full eye coords weren't required, just calculate the * eye Z values. */ _mesa_dotprod_tab[VB->AttribPtr[_TNL_ATTRIB_POS]->size] ( (GLfloat *) input->data, 4 * sizeof(GLfloat), VB->AttribPtr[_TNL_ATTRIB_POS], plane ); input->count = VB->AttribPtr[_TNL_ATTRIB_POS]->count; /* make sure coords are really positive NOTE should avoid going through array twice */ coord = input->start; for (i = 0; i < input->count; i++) { *coord = fabsf(*coord); STRIDE_F(coord, input->stride); } } else { /* fog coordinates = eye Z coordinates - need to copy for ABS */ input = &store->fogcoord; if (VB->EyePtr->size < 2) _mesa_vector4f_clean_elem( VB->EyePtr, VB->Count, 2 ); input->stride = 4 * sizeof(GLfloat); input->count = VB->EyePtr->count; coord = VB->EyePtr->start; for (i = 0 ; i < VB->EyePtr->count; i++) { input->data[i][0] = fabsf(coord[2]); STRIDE_F(coord, VB->EyePtr->stride); } } } else { /* use glFogCoord() coordinates */ input = VB->AttribPtr[_TNL_ATTRIB_FOG]; /* source data */ /* input->count may be one if glFogCoord was only called once * before glBegin. But we need to compute fog for all vertices. */ input->count = VB->AttribPtr[_TNL_ATTRIB_POS]->count; VB->AttribPtr[_TNL_ATTRIB_FOG] = &store->fogcoord; /* dest data */ } if (tnl->_DoVertexFog) { /* compute blend factors from fog coordinates */ compute_fog_blend_factors( ctx, VB->AttribPtr[_TNL_ATTRIB_FOG], input ); } else { /* results = incoming fog coords (compute fog per-fragment later) */ VB->AttribPtr[_TNL_ATTRIB_FOG] = input; } return GL_TRUE; }
static GLboolean run_fog_stage( GLcontext *ctx, struct gl_pipeline_stage *stage ) { struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; struct fog_stage_data *store = FOG_STAGE_DATA(stage); GLvector1f *input; if (stage->changed_inputs == 0) return GL_TRUE; if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT) { /* fog computed from Z depth */ /* source = VB->ObjPtr or VB->EyePtr coords */ /* dest = VB->FogCoordPtr = fog stage private storage */ VB->FogCoordPtr = &store->fogcoord; if (!ctx->_NeedEyeCoords) { GLfloat *m = ctx->ModelView.m; GLfloat plane[4]; /* Use this to store calculated eye z values: */ input = &store->fogcoord; plane[0] = m[2]; plane[1] = m[6]; plane[2] = m[10]; plane[3] = m[14]; /* Full eye coords weren't required, just calculate the * eye Z values. */ _mesa_dotprod_tab[VB->ObjPtr->size]( input->data, sizeof(GLfloat), VB->ObjPtr, plane ); input->count = VB->ObjPtr->count; } else { input = &store->input; if (VB->EyePtr->size < 2) _mesa_vector4f_clean_elem( VB->EyePtr, VB->Count, 2 ); input->data = &(VB->EyePtr->data[0][2]); input->start = VB->EyePtr->start+2; input->stride = VB->EyePtr->stride; input->count = VB->EyePtr->count; } } else { /* use glFogCoord() coordinates */ /* source = VB->FogCoordPtr */ input = VB->FogCoordPtr; /* dest = fog stage private storage */ VB->FogCoordPtr = &store->fogcoord; } make_win_fog_coords( ctx, VB->FogCoordPtr, input ); return GL_TRUE; }
static GLboolean run_fog_stage(GLcontext *ctx, struct tnl_pipeline_stage *stage) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; struct fog_stage_data *store = FOG_STAGE_DATA(stage); GLvector4f *input; if (ctx->ShaderObjects._VertexShaderPresent) return GL_TRUE; if (!ctx->Fog.Enabled || ctx->VertexProgram._Enabled) return GL_TRUE; if (ctx->Fog.FogCoordinateSource == GL_FRAGMENT_DEPTH_EXT) { /* Fog is computed from vertex or fragment Z values */ /* source = VB->ObjPtr or VB->EyePtr coords */ /* dest = VB->FogCoordPtr = fog stage private storage */ VB->FogCoordPtr = &store->fogcoord; if (!ctx->_NeedEyeCoords) { /* compute fog coords from object coords */ const GLfloat *m = ctx->ModelviewMatrixStack.Top->m; GLfloat plane[4]; /* Use this to store calculated eye z values: */ input = &store->fogcoord; /* NOTE: negate plane here so we get positive fog coords! */ plane[0] = -m[2]; plane[1] = -m[6]; plane[2] = -m[10]; plane[3] = -m[14]; /* Full eye coords weren't required, just calculate the * eye Z values. */ _mesa_dotprod_tab[VB->ObjPtr->size]( (GLfloat *) input->data, 4 * sizeof(GLfloat), VB->ObjPtr, plane ); input->count = VB->ObjPtr->count; } else { /* fog coordinates = eye Z coordinates (use ABS later) */ input = &store->input; if (VB->EyePtr->size < 2) _mesa_vector4f_clean_elem( VB->EyePtr, VB->Count, 2 ); input->data = (GLfloat (*)[4]) &(VB->EyePtr->data[0][2]); input->start = VB->EyePtr->start+2; input->stride = VB->EyePtr->stride; input->count = VB->EyePtr->count; } } else { /* use glFogCoord() coordinates */ input = VB->FogCoordPtr; /* source data */ /* input->count may be one if glFogCoord was only called once * before glBegin. But we need to compute fog for all vertices. */ input->count = VB->ObjPtr->count; VB->FogCoordPtr = &store->fogcoord; /* dest data */ } if (tnl->_DoVertexFog) { /* compute blend factors from fog coordinates */ compute_fog_blend_factors( ctx, VB->FogCoordPtr, input ); } else { /* results = incoming fog coords (compute fog per-fragment later) */ VB->FogCoordPtr = input; } VB->AttribPtr[_TNL_ATTRIB_FOG] = VB->FogCoordPtr; return GL_TRUE; }