Rev 56 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
56 | pj | 1 | /* $Id: t_vb_points.c,v 1.1 2003-02-28 11:48:07 pj Exp $ */ |
2 | |||
3 | /* |
||
4 | * Mesa 3-D graphics library |
||
5 | * Version: 4.1 |
||
6 | * |
||
7 | * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. |
||
8 | * |
||
9 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
10 | * copy of this software and associated documentation files (the "Software"), |
||
11 | * to deal in the Software without restriction, including without limitation |
||
12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
13 | * and/or sell copies of the Software, and to permit persons to whom the |
||
14 | * Software is furnished to do so, subject to the following conditions: |
||
15 | * |
||
16 | * The above copyright notice and this permission notice shall be included |
||
17 | * in all copies or substantial portions of the Software. |
||
18 | * |
||
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||
23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||
24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
25 | * |
||
26 | * Authors: |
||
27 | * Brian Paul |
||
28 | */ |
||
29 | |||
30 | #include "mtypes.h" |
||
31 | #include "imports.h" |
||
32 | #include "t_context.h" |
||
33 | #include "t_pipeline.h" |
||
34 | |||
35 | |||
36 | struct point_stage_data { |
||
37 | GLvector4f PointSize; |
||
38 | }; |
||
39 | |||
40 | #define POINT_STAGE_DATA(stage) ((struct point_stage_data *)stage->privatePtr) |
||
41 | |||
42 | |||
43 | /* |
||
44 | * Compute attenuated point sizes |
||
45 | */ |
||
46 | static GLboolean run_point_stage( GLcontext *ctx, |
||
47 | struct gl_pipeline_stage *stage ) |
||
48 | { |
||
49 | struct point_stage_data *store = POINT_STAGE_DATA(stage); |
||
50 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
||
51 | const GLfloat (*eye)[4] = (const GLfloat (*)[4]) VB->EyePtr->data; |
||
52 | const GLfloat p0 = ctx->Point.Params[0]; |
||
53 | const GLfloat p1 = ctx->Point.Params[1]; |
||
54 | const GLfloat p2 = ctx->Point.Params[2]; |
||
55 | const GLfloat pointSize = ctx->Point._Size; |
||
56 | GLfloat (*size)[4] = store->PointSize.data; |
||
57 | GLuint i; |
||
58 | |||
59 | if (stage->changed_inputs) { |
||
60 | /* XXX do threshold and min/max clamping here? */ |
||
61 | for (i = 0; i < VB->Count; i++) { |
||
62 | const GLfloat dist = -eye[i][2]; |
||
63 | /* GLfloat dist = GL_SQRT(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2]);*/ |
||
64 | size[i][0] = pointSize / (p0 + dist * (p1 + dist * p2)); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | VB->PointSizePtr = &store->PointSize; |
||
69 | |||
70 | return GL_TRUE; |
||
71 | } |
||
72 | |||
73 | |||
74 | /* If point size attenuation is on we'll compute the point size for |
||
75 | * each vertex in a special pipeline stage. |
||
76 | */ |
||
77 | static void check_point_size( GLcontext *ctx, struct gl_pipeline_stage *d ) |
||
78 | { |
||
79 | d->active = ctx->Point._Attenuated && !ctx->VertexProgram.Enabled; |
||
80 | } |
||
81 | |||
82 | static GLboolean alloc_point_data( GLcontext *ctx, |
||
83 | struct gl_pipeline_stage *stage ) |
||
84 | { |
||
85 | struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; |
||
86 | struct point_stage_data *store; |
||
87 | stage->privatePtr = MALLOC(sizeof(*store)); |
||
88 | store = POINT_STAGE_DATA(stage); |
||
89 | if (!store) |
||
90 | return GL_FALSE; |
||
91 | |||
92 | _mesa_vector4f_alloc( &store->PointSize, 0, VB->Size, 32 ); |
||
93 | |||
94 | /* Now run the stage. |
||
95 | */ |
||
96 | stage->run = run_point_stage; |
||
97 | return stage->run( ctx, stage ); |
||
98 | } |
||
99 | |||
100 | |||
101 | static void free_point_data( struct gl_pipeline_stage *stage ) |
||
102 | { |
||
103 | struct point_stage_data *store = POINT_STAGE_DATA(stage); |
||
104 | if (store) { |
||
105 | _mesa_vector4f_free( &store->PointSize ); |
||
106 | FREE( store ); |
||
107 | stage->privatePtr = 0; |
||
108 | } |
||
109 | } |
||
110 | |||
111 | const struct gl_pipeline_stage _tnl_point_attenuation_stage = |
||
112 | { |
||
113 | "point size attenuation", /* name */ |
||
114 | _NEW_POINT, /* build_state_change */ |
||
115 | _NEW_POINT, /* run_state_change */ |
||
116 | GL_FALSE, /* active */ |
||
117 | VERT_BIT_EYE, /* inputs */ |
||
118 | VERT_BIT_POINT_SIZE, /* outputs */ |
||
119 | 0, /* changed_inputs (temporary value) */ |
||
120 | NULL, /* stage private data */ |
||
121 | free_point_data, /* destructor */ |
||
122 | check_point_size, /* check */ |
||
123 | alloc_point_data /* run -- initially set to alloc data */ |
||
124 | }; |