2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 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.
30 #include "t_context.h"
31 #include "t_pipeline.h"
34 struct point_stage_data
{
38 #define POINT_STAGE_DATA(stage) ((struct point_stage_data *)stage->privatePtr)
42 * Compute attenuated point sizes
44 static GLboolean
run_point_stage( GLcontext
*ctx
,
45 struct tnl_pipeline_stage
*stage
)
47 if (ctx
->Point
._Attenuated
&& !ctx
->VertexProgram
._Enabled
) {
48 struct point_stage_data
*store
= POINT_STAGE_DATA(stage
);
49 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
50 const GLfloat (*eye
)[4] = (const GLfloat (*)[4]) VB
->EyePtr
->data
;
51 const GLfloat p0
= ctx
->Point
.Params
[0];
52 const GLfloat p1
= ctx
->Point
.Params
[1];
53 const GLfloat p2
= ctx
->Point
.Params
[2];
54 const GLfloat pointSize
= ctx
->Point
._Size
;
55 GLfloat (*size
)[4] = store
->PointSize
.data
;
58 for (i
= 0; i
< VB
->Count
; i
++) {
59 const GLfloat dist
= -eye
[i
][2];
60 /* GLfloat dist = SQRTF(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2]);*/
61 size
[i
][0] = pointSize
/ (p0
+ dist
* (p1
+ dist
* p2
));
64 VB
->PointSizePtr
= &store
->PointSize
;
65 VB
->AttribPtr
[_TNL_ATTRIB_POINTSIZE
] = &store
->PointSize
;
73 static GLboolean
alloc_point_data( GLcontext
*ctx
,
74 struct tnl_pipeline_stage
*stage
)
76 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
77 struct point_stage_data
*store
;
78 stage
->privatePtr
= MALLOC(sizeof(*store
));
79 store
= POINT_STAGE_DATA(stage
);
83 _mesa_vector4f_alloc( &store
->PointSize
, 0, VB
->Size
, 32 );
88 static void free_point_data( struct tnl_pipeline_stage
*stage
)
90 struct point_stage_data
*store
= POINT_STAGE_DATA(stage
);
92 _mesa_vector4f_free( &store
->PointSize
);
94 stage
->privatePtr
= NULL
;
98 const struct tnl_pipeline_stage _tnl_point_attenuation_stage
=
100 "point size attenuation", /* name */
101 NULL
, /* stage private data */
102 alloc_point_data
, /* alloc data */
103 free_point_data
, /* destructor */
105 run_point_stage
/* run */