1 /* $Id: points.c,v 1.9 2000/05/10 22:36:05 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
47 _mesa_PointSize( GLfloat size
)
49 GET_CURRENT_CONTEXT(ctx
);
50 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPointSize");
53 gl_error( ctx
, GL_INVALID_VALUE
, "glPointSize" );
57 if (ctx
->Point
.UserSize
!= size
) {
58 ctx
->Point
.UserSize
= size
;
59 ctx
->Point
.Size
= CLAMP(size
, ctx
->Const
.MinPointSize
, ctx
->Const
.MaxPointSize
);
60 ctx
->TriangleCaps
&= ~DD_POINT_SIZE
;
62 ctx
->TriangleCaps
|= DD_POINT_SIZE
;
63 ctx
->NewState
|= NEW_RASTER_OPS
;
70 _mesa_PointParameterfEXT( GLenum pname
, GLfloat param
)
72 _mesa_PointParameterfvEXT(pname
, ¶m
);
77 _mesa_PointParameterfvEXT( GLenum pname
, const GLfloat
*params
)
79 GET_CURRENT_CONTEXT(ctx
);
80 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glPointParameterfvEXT");
83 case GL_DISTANCE_ATTENUATION_EXT
:
85 const GLboolean tmp
= ctx
->Point
.Attenuated
;
86 COPY_3V(ctx
->Point
.Params
, params
);
87 ctx
->Point
.Attenuated
= (params
[0] != 1.0 ||
91 if (tmp
!= ctx
->Point
.Attenuated
) {
92 ctx
->Enabled
^= ENABLE_POINT_ATTEN
;
93 ctx
->TriangleCaps
^= DD_POINT_ATTEN
;
94 ctx
->NewState
|= NEW_RASTER_OPS
;
98 case GL_POINT_SIZE_MIN_EXT
:
100 gl_error( ctx
, GL_INVALID_VALUE
, "glPointParameterfvEXT" );
103 ctx
->Point
.MinSize
= *params
;
105 case GL_POINT_SIZE_MAX_EXT
:
106 if (*params
< 0.0F
) {
107 gl_error( ctx
, GL_INVALID_VALUE
, "glPointParameterfvEXT" );
110 ctx
->Point
.MaxSize
= *params
;
112 case GL_POINT_FADE_THRESHOLD_SIZE_EXT
:
113 if (*params
< 0.0F
) {
114 gl_error( ctx
, GL_INVALID_VALUE
, "glPointParameterfvEXT" );
117 ctx
->Point
.Threshold
= *params
;
120 gl_error( ctx
, GL_INVALID_ENUM
, "glPointParameterfvEXT" );
124 ctx
->NewState
|= NEW_RASTER_OPS
;
128 /**********************************************************************/
129 /***** Rasterization *****/
130 /**********************************************************************/
134 * There are 3 pairs (RGBA, CI) of point rendering functions:
135 * 1. simple: size=1 and no special rasterization functions (fastest)
136 * 2. size1: size=1 and any rasterization functions
137 * 3. general: any size and rasterization functions (slowest)
139 * All point rendering functions take the same two arguments: first and
140 * last which specify that the points specified by VB[first] through
141 * VB[last] are to be rendered.
149 * CI points with size == 1.0
152 size1_ci_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
154 struct vertex_buffer
*VB
= ctx
->VB
;
155 struct pixel_buffer
*PB
= ctx
->PB
;
157 GLint
*pbx
= PB
->x
, *pby
= PB
->y
;
158 GLdepth
*pbz
= PB
->z
;
159 GLuint
*pbi
= PB
->index
;
160 GLuint pbcount
= PB
->count
;
163 win
= &VB
->Win
.data
[first
][0];
164 for (i
= first
; i
<= last
; i
++) {
165 if (VB
->ClipMask
[i
] == 0) {
166 pbx
[pbcount
] = (GLint
) win
[0];
167 pby
[pbcount
] = (GLint
) win
[1];
168 pbz
[pbcount
] = (GLint
) (win
[2] + ctx
->PointZoffset
);
169 pbi
[pbcount
] = VB
->IndexPtr
->data
[i
];
175 PB_CHECK_FLUSH(ctx
, PB
);
181 * RGBA points with size == 1.0
184 size1_rgba_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
186 struct vertex_buffer
*VB
= ctx
->VB
;
187 struct pixel_buffer
*PB
= ctx
->PB
;
190 for (i
= first
; i
<= last
; i
++) {
191 if (VB
->ClipMask
[i
] == 0) {
193 GLint red
, green
, blue
, alpha
;
195 x
= (GLint
) VB
->Win
.data
[i
][0];
196 y
= (GLint
) VB
->Win
.data
[i
][1];
197 z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
199 red
= VB
->ColorPtr
->data
[i
][0];
200 green
= VB
->ColorPtr
->data
[i
][1];
201 blue
= VB
->ColorPtr
->data
[i
][2];
202 alpha
= VB
->ColorPtr
->data
[i
][3];
204 PB_WRITE_RGBA_PIXEL( PB
, x
, y
, z
, red
, green
, blue
, alpha
);
207 PB_CHECK_FLUSH(ctx
, PB
);
216 general_ci_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
218 struct vertex_buffer
*VB
= ctx
->VB
;
219 struct pixel_buffer
*PB
= ctx
->PB
;
220 const GLint isize
= (GLint
) (ctx
->Point
.Size
+ 0.5F
);
221 GLint radius
= isize
>> 1;
224 for (i
= first
; i
<= last
; i
++) {
225 if (VB
->ClipMask
[i
] == 0) {
226 GLint x0
, x1
, y0
, y1
;
229 GLint x
= (GLint
) VB
->Win
.data
[i
][0];
230 GLint y
= (GLint
) VB
->Win
.data
[i
][1];
231 GLint z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
242 x0
= (GLint
) (x
+ 1.5F
) - radius
;
244 y0
= (GLint
) (y
+ 1.5F
) - radius
;
248 PB_SET_INDEX( PB
, VB
->IndexPtr
->data
[i
] );
250 for (iy
= y0
; iy
<= y1
; iy
++) {
251 for (ix
= x0
; ix
<= x1
; ix
++) {
252 PB_WRITE_PIXEL( PB
, ix
, iy
, z
);
255 PB_CHECK_FLUSH(ctx
,PB
);
262 * General RGBA points.
265 general_rgba_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
267 struct vertex_buffer
*VB
= ctx
->VB
;
268 struct pixel_buffer
*PB
= ctx
->PB
;
269 GLint isize
= (GLint
) (ctx
->Point
.Size
+ 0.5F
);
270 GLint radius
= isize
>> 1;
273 for (i
= first
; i
<= last
; i
++) {
274 if (VB
->ClipMask
[i
] == 0) {
275 GLint x0
, x1
, y0
, y1
;
278 GLint x
= (GLint
) VB
->Win
.data
[i
][0];
279 GLint y
= (GLint
) VB
->Win
.data
[i
][1];
280 GLint z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
291 x0
= (GLint
) (x
+ 1.5F
) - radius
;
293 y0
= (GLint
) (y
+ 1.5F
) - radius
;
298 VB
->ColorPtr
->data
[i
][0],
299 VB
->ColorPtr
->data
[i
][1],
300 VB
->ColorPtr
->data
[i
][2],
301 VB
->ColorPtr
->data
[i
][3] );
303 for (iy
= y0
; iy
<= y1
; iy
++) {
304 for (ix
= x0
; ix
<= x1
; ix
++) {
305 PB_WRITE_PIXEL( PB
, ix
, iy
, z
);
308 PB_CHECK_FLUSH(ctx
,PB
);
317 * Textured RGBA points.
320 textured_rgba_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
322 struct vertex_buffer
*VB
= ctx
->VB
;
323 struct pixel_buffer
*PB
= ctx
->PB
;
326 for (i
= first
; i
<= last
; i
++) {
327 if (VB
->ClipMask
[i
] == 0) {
328 GLint x0
, x1
, y0
, y1
;
329 GLint ix
, iy
, radius
;
330 GLint red
, green
, blue
, alpha
;
333 GLint x
= (GLint
) VB
->Win
.data
[i
][0];
334 GLint y
= (GLint
) VB
->Win
.data
[i
][1];
335 GLint z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
336 GLint isize
= (GLint
) (ctx
->Point
.Size
+ 0.5F
);
352 x0
= (GLint
) (x
+ 1.5F
) - radius
;
354 y0
= (GLint
) (y
+ 1.5F
) - radius
;
358 red
= VB
->ColorPtr
->data
[i
][0];
359 green
= VB
->ColorPtr
->data
[i
][1];
360 blue
= VB
->ColorPtr
->data
[i
][2];
361 alpha
= VB
->ColorPtr
->data
[i
][3];
363 switch (VB
->TexCoordPtr
[0]->size
) {
365 s
= VB
->TexCoordPtr
[0]->data
[i
][0]/VB
->TexCoordPtr
[0]->data
[i
][3];
366 t
= VB
->TexCoordPtr
[0]->data
[i
][1]/VB
->TexCoordPtr
[0]->data
[i
][3];
367 u
= VB
->TexCoordPtr
[0]->data
[i
][2]/VB
->TexCoordPtr
[0]->data
[i
][3];
370 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
371 t
= VB
->TexCoordPtr
[0]->data
[i
][1];
372 u
= VB
->TexCoordPtr
[0]->data
[i
][2];
375 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
376 t
= VB
->TexCoordPtr
[0]->data
[i
][1];
380 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
385 /* should never get here */
387 gl_problem(ctx
, "unexpected texcoord size in textured_rgba_points()");
390 /* don't think this is needed
391 PB_SET_COLOR( red, green, blue, alpha );
394 for (iy
= y0
; iy
<= y1
; iy
++) {
395 for (ix
= x0
; ix
<= x1
; ix
++) {
396 PB_WRITE_TEX_PIXEL( PB
, ix
, iy
, z
, red
, green
, blue
, alpha
, s
, t
, u
);
399 PB_CHECK_FLUSH(ctx
, PB
);
406 * Multitextured RGBA points.
409 multitextured_rgba_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
411 struct vertex_buffer
*VB
= ctx
->VB
;
412 struct pixel_buffer
*PB
= ctx
->PB
;
415 for (i
= first
; i
<= last
; i
++) {
416 if (VB
->ClipMask
[i
] == 0) {
417 GLint x0
, x1
, y0
, y1
;
420 GLint red
, green
, blue
, alpha
;
424 GLint x
= (GLint
) VB
->Win
.data
[i
][0];
425 GLint y
= (GLint
) VB
->Win
.data
[i
][1];
426 GLint z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
427 GLint isize
= (GLint
) (ctx
->Point
.Size
+ 0.5F
);
443 x0
= (GLint
) (x
+ 1.5F
) - radius
;
445 y0
= (GLint
) (y
+ 1.5F
) - radius
;
449 red
= VB
->ColorPtr
->data
[i
][0];
450 green
= VB
->ColorPtr
->data
[i
][1];
451 blue
= VB
->ColorPtr
->data
[i
][2];
452 alpha
= VB
->ColorPtr
->data
[i
][3];
454 switch (VB
->TexCoordPtr
[0]->size
) {
456 s
= VB
->TexCoordPtr
[0]->data
[i
][0]/VB
->TexCoordPtr
[0]->data
[i
][3];
457 t
= VB
->TexCoordPtr
[0]->data
[i
][1]/VB
->TexCoordPtr
[0]->data
[i
][3];
458 u
= VB
->TexCoordPtr
[0]->data
[i
][2]/VB
->TexCoordPtr
[0]->data
[i
][3];
461 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
462 t
= VB
->TexCoordPtr
[0]->data
[i
][1];
463 u
= VB
->TexCoordPtr
[0]->data
[i
][2];
466 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
467 t
= VB
->TexCoordPtr
[0]->data
[i
][1];
471 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
476 /* should never get here */
478 gl_problem(ctx
, "unexpected texcoord size in multitextured_rgba_points()");
481 switch (VB
->TexCoordPtr
[1]->size
) {
483 s1
= VB
->TexCoordPtr
[1]->data
[i
][0]/VB
->TexCoordPtr
[1]->data
[i
][3];
484 t1
= VB
->TexCoordPtr
[1]->data
[i
][1]/VB
->TexCoordPtr
[1]->data
[i
][3];
485 u1
= VB
->TexCoordPtr
[1]->data
[i
][2]/VB
->TexCoordPtr
[1]->data
[i
][3];
488 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
489 t1
= VB
->TexCoordPtr
[1]->data
[i
][1];
490 u1
= VB
->TexCoordPtr
[1]->data
[i
][2];
493 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
494 t1
= VB
->TexCoordPtr
[1]->data
[i
][1];
498 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
503 /* should never get here */
505 gl_problem(ctx
, "unexpected texcoord size in multitextured_rgba_points()");
508 for (iy
=y0
;iy
<=y1
;iy
++) {
509 for (ix
=x0
;ix
<=x1
;ix
++) {
510 PB_WRITE_MULTITEX_PIXEL( PB
, ix
, iy
, z
, red
, green
, blue
, alpha
,
511 s
, t
, u
, s1
, t1
, u1
);
514 PB_CHECK_FLUSH(ctx
, PB
);
523 * Antialiased points with or without texture mapping.
526 antialiased_rgba_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
528 struct vertex_buffer
*VB
= ctx
->VB
;
529 struct pixel_buffer
*PB
= ctx
->PB
;
530 const GLfloat radius
= ctx
->Point
.Size
* 0.5F
;
531 const GLfloat rmin
= radius
- 0.7071F
; /* 0.7071 = sqrt(2)/2 */
532 const GLfloat rmax
= radius
+ 0.7071F
;
533 const GLfloat rmin2
= rmin
* rmin
;
534 const GLfloat rmax2
= rmax
* rmax
;
535 const GLfloat cscale
= 256.0F
/ (rmax2
- rmin2
);
538 if (ctx
->Texture
.ReallyEnabled
) {
539 for (i
= first
; i
<= last
; i
++) {
540 if (VB
->ClipMask
[i
] == 0) {
542 GLint red
, green
, blue
, alpha
;
546 GLint xmin
= (GLint
) (VB
->Win
.data
[i
][0] - radius
);
547 GLint xmax
= (GLint
) (VB
->Win
.data
[i
][0] + radius
);
548 GLint ymin
= (GLint
) (VB
->Win
.data
[i
][1] - radius
);
549 GLint ymax
= (GLint
) (VB
->Win
.data
[i
][1] + radius
);
550 GLint z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
552 red
= VB
->ColorPtr
->data
[i
][0];
553 green
= VB
->ColorPtr
->data
[i
][1];
554 blue
= VB
->ColorPtr
->data
[i
][2];
556 switch (VB
->TexCoordPtr
[0]->size
) {
558 s
= (VB
->TexCoordPtr
[0]->data
[i
][0]/
559 VB
->TexCoordPtr
[0]->data
[i
][3]);
560 t
= (VB
->TexCoordPtr
[0]->data
[i
][1]/
561 VB
->TexCoordPtr
[0]->data
[i
][3]);
562 u
= (VB
->TexCoordPtr
[0]->data
[i
][2]/
563 VB
->TexCoordPtr
[0]->data
[i
][3]);
566 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
567 t
= VB
->TexCoordPtr
[0]->data
[i
][1];
568 u
= VB
->TexCoordPtr
[0]->data
[i
][2];
571 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
572 t
= VB
->TexCoordPtr
[0]->data
[i
][1];
576 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
581 /* should never get here */
583 gl_problem(ctx
, "unexpected texcoord size in antialiased_rgba_points()");
586 if (ctx
->Texture
.ReallyEnabled
>= TEXTURE1_1D
) {
587 /* Multitextured! This is probably a slow enough path that
588 there's no reason to specialize the multitexture case. */
589 switch (VB
->TexCoordPtr
[1]->size
) {
591 s1
= ( VB
->TexCoordPtr
[1]->data
[i
][0] /
592 VB
->TexCoordPtr
[1]->data
[i
][3]);
593 t1
= ( VB
->TexCoordPtr
[1]->data
[i
][1] /
594 VB
->TexCoordPtr
[1]->data
[i
][3]);
595 u1
= ( VB
->TexCoordPtr
[1]->data
[i
][2] /
596 VB
->TexCoordPtr
[1]->data
[i
][3]);
599 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
600 t1
= VB
->TexCoordPtr
[1]->data
[i
][1];
601 u1
= VB
->TexCoordPtr
[1]->data
[i
][2];
604 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
605 t1
= VB
->TexCoordPtr
[1]->data
[i
][1];
609 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
614 /* should never get here */
616 gl_problem(ctx
, "unexpected texcoord size in antialiased_rgba_points()");
620 for (y
=ymin
;y
<=ymax
;y
++) {
621 for (x
=xmin
;x
<=xmax
;x
++) {
622 GLfloat dx
= x
/*+0.5F*/ - VB
->Win
.data
[i
][0];
623 GLfloat dy
= y
/*+0.5F*/ - VB
->Win
.data
[i
][1];
624 GLfloat dist2
= dx
*dx
+ dy
*dy
;
626 alpha
= VB
->ColorPtr
->data
[i
][3];
628 GLint coverage
= (GLint
) (256.0F
-(dist2
-rmin2
)*cscale
);
629 /* coverage is in [0,256] */
630 alpha
= (alpha
* coverage
) >> 8;
632 if (ctx
->Texture
.ReallyEnabled
>= TEXTURE1_1D
) {
633 PB_WRITE_MULTITEX_PIXEL( PB
, x
,y
,z
, red
, green
, blue
,
634 alpha
, s
, t
, u
, s1
, t1
, u1
);
636 PB_WRITE_TEX_PIXEL( PB
, x
,y
,z
, red
, green
, blue
,
643 PB_CHECK_FLUSH(ctx
,PB
);
648 /* Not texture mapped */
649 for (i
=first
;i
<=last
;i
++) {
650 if (VB
->ClipMask
[i
]==0) {
651 GLint xmin
, ymin
, xmax
, ymax
;
653 GLint red
, green
, blue
, alpha
;
655 xmin
= (GLint
) (VB
->Win
.data
[i
][0] - radius
);
656 xmax
= (GLint
) (VB
->Win
.data
[i
][0] + radius
);
657 ymin
= (GLint
) (VB
->Win
.data
[i
][1] - radius
);
658 ymax
= (GLint
) (VB
->Win
.data
[i
][1] + radius
);
659 z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
661 red
= VB
->ColorPtr
->data
[i
][0];
662 green
= VB
->ColorPtr
->data
[i
][1];
663 blue
= VB
->ColorPtr
->data
[i
][2];
665 for (y
=ymin
;y
<=ymax
;y
++) {
666 for (x
=xmin
;x
<=xmax
;x
++) {
667 GLfloat dx
= x
/*+0.5F*/ - VB
->Win
.data
[i
][0];
668 GLfloat dy
= y
/*+0.5F*/ - VB
->Win
.data
[i
][1];
669 GLfloat dist2
= dx
*dx
+ dy
*dy
;
671 alpha
= VB
->ColorPtr
->data
[i
][3];
673 GLint coverage
= (GLint
) (256.0F
-(dist2
-rmin2
)*cscale
);
674 /* coverage is in [0,256] */
675 alpha
= (alpha
* coverage
) >> 8;
677 PB_WRITE_RGBA_PIXEL( PB
, x
, y
, z
, red
, green
, blue
,
682 PB_CHECK_FLUSH(ctx
,PB
);
691 * Null rasterizer for measuring transformation speed.
694 null_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
703 /* Definition of the functions for GL_EXT_point_parameters */
705 /* Calculates the distance attenuation formula of a vector of points in
706 * eye space coordinates
709 dist3(GLfloat
*out
, GLuint first
, GLuint last
,
710 const GLcontext
*ctx
, const GLvector4f
*v
)
712 GLuint stride
= v
->stride
;
713 const GLfloat
*p
= VEC_ELT(v
, GLfloat
, first
);
716 for (i
= first
; i
<= last
; i
++, STRIDE_F(p
, stride
) ) {
717 GLfloat dist
= GL_SQRT(p
[0]*p
[0]+p
[1]*p
[1]+p
[2]*p
[2]);
718 out
[i
] = 1.0F
/ (ctx
->Point
.Params
[0] +
719 dist
* (ctx
->Point
.Params
[1] +
720 dist
* ctx
->Point
.Params
[2]));
726 dist2(GLfloat
*out
, GLuint first
, GLuint last
,
727 const GLcontext
*ctx
, const GLvector4f
*v
)
729 GLuint stride
= v
->stride
;
730 const GLfloat
*p
= VEC_ELT(v
, GLfloat
, first
);
733 for (i
= first
; i
<= last
; i
++, STRIDE_F(p
, stride
) ) {
734 GLfloat dist
= GL_SQRT(p
[0]*p
[0]+p
[1]*p
[1]);
735 out
[i
] = 1.0F
/ (ctx
->Point
.Params
[0] +
736 dist
* (ctx
->Point
.Params
[1] +
737 dist
* ctx
->Point
.Params
[2]));
742 typedef void (*dist_func
)(GLfloat
*out
, GLuint first
, GLuint last
,
743 const GLcontext
*ctx
, const GLvector4f
*v
);
746 static dist_func eye_dist_tab
[5] = {
756 clip_dist(GLfloat
*out
, GLuint first
, GLuint last
,
757 const GLcontext
*ctx
, GLvector4f
*clip
)
759 /* this is never called */
760 gl_problem(NULL
, "clip_dist() called - dead code!\n");
770 const GLfloat
*from
= (GLfloat
*)clip_vec
->start
;
771 const GLuint stride
= clip_vec
->stride
;
773 for (i
= first
; i
<= last
; i
++ )
775 GLfloat dist
= win
[i
][2];
776 out
[i
] = 1/(ctx
->Point
.Params
[0]+
777 dist
* (ctx
->Point
.Params
[1] +
778 dist
* ctx
->Point
.Params
[2]));
786 * Distance Attenuated General CI points.
789 dist_atten_general_ci_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
791 struct vertex_buffer
*VB
= ctx
->VB
;
792 struct pixel_buffer
*PB
= ctx
->PB
;
793 GLfloat dist
[VB_SIZE
];
794 const GLfloat psize
= ctx
->Point
.Size
;
797 if (ctx
->NeedEyeCoords
)
798 (eye_dist_tab
[VB
->EyePtr
->size
])( dist
, first
, last
, ctx
, VB
->EyePtr
);
800 clip_dist( dist
, first
, last
, ctx
, VB
->ClipPtr
);
802 for (i
=first
;i
<=last
;i
++) {
803 if (VB
->ClipMask
[i
]==0) {
804 GLint x0
, x1
, y0
, y1
;
807 GLint x
= (GLint
) VB
->Win
.data
[i
][0];
808 GLint y
= (GLint
) VB
->Win
.data
[i
][1];
809 GLint z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
810 GLfloat dsize
= psize
* dist
[i
];
812 if (dsize
>= ctx
->Point
.Threshold
) {
813 isize
= (GLint
) (MIN2(dsize
, ctx
->Point
.MaxSize
) + 0.5F
);
816 isize
= (GLint
) (MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
) + 0.5F
);
829 x0
= (GLint
) (x
+ 1.5F
) - radius
;
831 y0
= (GLint
) (y
+ 1.5F
) - radius
;
835 PB_SET_INDEX( PB
, VB
->IndexPtr
->data
[i
] );
837 for (iy
=y0
;iy
<=y1
;iy
++) {
838 for (ix
=x0
;ix
<=x1
;ix
++) {
839 PB_WRITE_PIXEL( PB
, ix
, iy
, z
);
842 PB_CHECK_FLUSH(ctx
,PB
);
848 * Distance Attenuated General RGBA points.
851 dist_atten_general_rgba_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
853 struct vertex_buffer
*VB
= ctx
->VB
;
854 struct pixel_buffer
*PB
= ctx
->PB
;
855 GLfloat dist
[VB_SIZE
];
856 const GLfloat psize
= ctx
->Point
.Size
;
859 if (ctx
->NeedEyeCoords
)
860 (eye_dist_tab
[VB
->EyePtr
->size
])( dist
, first
, last
, ctx
, VB
->EyePtr
);
862 clip_dist( dist
, first
, last
, ctx
, VB
->ClipPtr
);
864 for (i
=first
;i
<=last
;i
++) {
865 if (VB
->ClipMask
[i
]==0) {
866 GLint x0
, x1
, y0
, y1
;
869 GLint x
= (GLint
) VB
->Win
.data
[i
][0];
870 GLint y
= (GLint
) VB
->Win
.data
[i
][1];
871 GLint z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
872 GLfloat dsize
=psize
*dist
[i
];
875 if (dsize
>= ctx
->Point
.Threshold
) {
876 isize
= (GLint
) (MIN2(dsize
,ctx
->Point
.MaxSize
)+0.5F
);
877 alpha
= VB
->ColorPtr
->data
[i
][3];
880 isize
= (GLint
) (MAX2(ctx
->Point
.Threshold
,ctx
->Point
.MinSize
)+0.5F
);
881 dsize
/= ctx
->Point
.Threshold
;
882 alpha
= (GLint
) (VB
->ColorPtr
->data
[i
][3]* (dsize
*dsize
));
895 x0
= (GLint
) (x
+ 1.5F
) - radius
;
897 y0
= (GLint
) (y
+ 1.5F
) - radius
;
902 VB
->ColorPtr
->data
[i
][0],
903 VB
->ColorPtr
->data
[i
][1],
904 VB
->ColorPtr
->data
[i
][2],
907 for (iy
=y0
;iy
<=y1
;iy
++) {
908 for (ix
=x0
;ix
<=x1
;ix
++) {
909 PB_WRITE_PIXEL( PB
, ix
, iy
, z
);
912 PB_CHECK_FLUSH(ctx
,PB
);
918 * Distance Attenuated Textured RGBA points.
921 dist_atten_textured_rgba_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
923 struct vertex_buffer
*VB
= ctx
->VB
;
924 struct pixel_buffer
*PB
= ctx
->PB
;
925 GLfloat dist
[VB_SIZE
];
926 const GLfloat psize
= ctx
->Point
.Size
;
929 if (ctx
->NeedEyeCoords
)
930 (eye_dist_tab
[VB
->EyePtr
->size
])( dist
, first
, last
, ctx
, VB
->EyePtr
);
932 clip_dist( dist
, first
, last
, ctx
, VB
->ClipPtr
);
934 for (i
=first
;i
<=last
;i
++) {
935 if (VB
->ClipMask
[i
]==0) {
936 GLint x0
, x1
, y0
, y1
;
939 GLint red
, green
, blue
, alpha
;
943 GLint x
= (GLint
) VB
->Win
.data
[i
][0];
944 GLint y
= (GLint
) VB
->Win
.data
[i
][1];
945 GLint z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
947 GLfloat dsize
= psize
*dist
[i
];
948 if(dsize
>= ctx
->Point
.Threshold
) {
949 isize
= (GLint
) (MIN2(dsize
, ctx
->Point
.MaxSize
) + 0.5F
);
950 alpha
= VB
->ColorPtr
->data
[i
][3];
953 isize
= (GLint
) (MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
) + 0.5F
);
954 dsize
/= ctx
->Point
.Threshold
;
955 alpha
= (GLint
) (VB
->ColorPtr
->data
[i
][3] * (dsize
* dsize
));
972 x0
= (GLint
) (x
+ 1.5F
) - radius
;
974 y0
= (GLint
) (y
+ 1.5F
) - radius
;
978 red
= VB
->ColorPtr
->data
[i
][0];
979 green
= VB
->ColorPtr
->data
[i
][1];
980 blue
= VB
->ColorPtr
->data
[i
][2];
982 switch (VB
->TexCoordPtr
[0]->size
) {
984 s
= (VB
->TexCoordPtr
[0]->data
[i
][0]/
985 VB
->TexCoordPtr
[0]->data
[i
][3]);
986 t
= (VB
->TexCoordPtr
[0]->data
[i
][1]/
987 VB
->TexCoordPtr
[0]->data
[i
][3]);
988 u
= (VB
->TexCoordPtr
[0]->data
[i
][2]/
989 VB
->TexCoordPtr
[0]->data
[i
][3]);
992 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
993 t
= VB
->TexCoordPtr
[0]->data
[i
][1];
994 u
= VB
->TexCoordPtr
[0]->data
[i
][2];
997 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
998 t
= VB
->TexCoordPtr
[0]->data
[i
][1];
1002 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
1007 /* should never get here */
1009 gl_problem(ctx
, "unexpected texcoord size in dist_atten_textured_rgba_points()");
1012 if (ctx
->Texture
.ReallyEnabled
>= TEXTURE1_1D
) {
1013 /* Multitextured! This is probably a slow enough path that
1014 there's no reason to specialize the multitexture case. */
1015 switch (VB
->TexCoordPtr
[1]->size
) {
1017 s1
= ( VB
->TexCoordPtr
[1]->data
[i
][0] /
1018 VB
->TexCoordPtr
[1]->data
[i
][3] );
1019 t1
= ( VB
->TexCoordPtr
[1]->data
[i
][1] /
1020 VB
->TexCoordPtr
[1]->data
[i
][3] );
1021 u1
= ( VB
->TexCoordPtr
[1]->data
[i
][2] /
1022 VB
->TexCoordPtr
[1]->data
[i
][3] );
1025 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
1026 t1
= VB
->TexCoordPtr
[1]->data
[i
][1];
1027 u1
= VB
->TexCoordPtr
[1]->data
[i
][2];
1030 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
1031 t1
= VB
->TexCoordPtr
[1]->data
[i
][1];
1035 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
1040 /* should never get here */
1042 gl_problem(ctx
, "unexpected texcoord size in dist_atten_textured_rgba_points()");
1046 /* don't think this is needed
1047 PB_SET_COLOR( red, green, blue, alpha );
1050 for (iy
=y0
;iy
<=y1
;iy
++) {
1051 for (ix
=x0
;ix
<=x1
;ix
++) {
1052 if (ctx
->Texture
.ReallyEnabled
>= TEXTURE1_1D
) {
1053 PB_WRITE_MULTITEX_PIXEL( PB
, ix
, iy
, z
, red
, green
, blue
, alpha
, s
, t
, u
, s1
, t1
, u1
);
1055 PB_WRITE_TEX_PIXEL( PB
, ix
, iy
, z
, red
, green
, blue
, alpha
, s
, t
, u
);
1059 PB_CHECK_FLUSH(ctx
,PB
);
1065 * Distance Attenuated Antialiased points with or without texture mapping.
1068 dist_atten_antialiased_rgba_points( GLcontext
*ctx
, GLuint first
, GLuint last
)
1070 struct vertex_buffer
*VB
= ctx
->VB
;
1071 struct pixel_buffer
*PB
= ctx
->PB
;
1072 GLfloat dist
[VB_SIZE
];
1073 const GLfloat psize
= ctx
->Point
.Size
;
1076 if (ctx
->NeedEyeCoords
)
1077 (eye_dist_tab
[VB
->EyePtr
->size
])( dist
, first
, last
, ctx
, VB
->EyePtr
);
1079 clip_dist( dist
, first
, last
, ctx
, VB
->ClipPtr
);
1081 if (ctx
->Texture
.ReallyEnabled
) {
1082 for (i
=first
;i
<=last
;i
++) {
1083 if (VB
->ClipMask
[i
]==0) {
1084 GLfloat radius
, rmin
, rmax
, rmin2
, rmax2
, cscale
, alphaf
;
1085 GLint xmin
, ymin
, xmax
, ymax
;
1087 GLint red
, green
, blue
, alpha
;
1090 GLfloat dsize
= psize
* dist
[i
];
1092 if (dsize
>= ctx
->Point
.Threshold
) {
1093 radius
= MIN2(dsize
, ctx
->Point
.MaxSize
) * 0.5F
;
1097 radius
= (MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
) * 0.5F
);
1098 dsize
/= ctx
->Point
.Threshold
;
1099 alphaf
= (dsize
*dsize
);
1101 rmin
= radius
- 0.7071F
; /* 0.7071 = sqrt(2)/2 */
1102 rmax
= radius
+ 0.7071F
;
1105 cscale
= 256.0F
/ (rmax2
-rmin2
);
1107 xmin
= (GLint
) (VB
->Win
.data
[i
][0] - radius
);
1108 xmax
= (GLint
) (VB
->Win
.data
[i
][0] + radius
);
1109 ymin
= (GLint
) (VB
->Win
.data
[i
][1] - radius
);
1110 ymax
= (GLint
) (VB
->Win
.data
[i
][1] + radius
);
1111 z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
1113 red
= VB
->ColorPtr
->data
[i
][0];
1114 green
= VB
->ColorPtr
->data
[i
][1];
1115 blue
= VB
->ColorPtr
->data
[i
][2];
1117 switch (VB
->TexCoordPtr
[0]->size
) {
1119 s
= (VB
->TexCoordPtr
[0]->data
[i
][0]/
1120 VB
->TexCoordPtr
[0]->data
[i
][3]);
1121 t
= (VB
->TexCoordPtr
[0]->data
[i
][1]/
1122 VB
->TexCoordPtr
[0]->data
[i
][3]);
1123 u
= (VB
->TexCoordPtr
[0]->data
[i
][2]/
1124 VB
->TexCoordPtr
[0]->data
[i
][3]);
1127 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
1128 t
= VB
->TexCoordPtr
[0]->data
[i
][1];
1129 u
= VB
->TexCoordPtr
[0]->data
[i
][2];
1132 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
1133 t
= VB
->TexCoordPtr
[0]->data
[i
][1];
1137 s
= VB
->TexCoordPtr
[0]->data
[i
][0];
1142 /* should never get here */
1144 gl_problem(ctx
, "unexpected texcoord size in dist_atten_antialiased_rgba_points()");
1147 if (ctx
->Texture
.ReallyEnabled
>= TEXTURE1_1D
) {
1148 /* Multitextured! This is probably a slow enough path that
1149 there's no reason to specialize the multitexture case. */
1150 switch (VB
->TexCoordPtr
[1]->size
) {
1152 s1
= ( VB
->TexCoordPtr
[1]->data
[i
][0] /
1153 VB
->TexCoordPtr
[1]->data
[i
][3] );
1154 t1
= ( VB
->TexCoordPtr
[1]->data
[i
][1] /
1155 VB
->TexCoordPtr
[1]->data
[i
][3] );
1156 u1
= ( VB
->TexCoordPtr
[1]->data
[i
][2] /
1157 VB
->TexCoordPtr
[1]->data
[i
][3] );
1160 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
1161 t1
= VB
->TexCoordPtr
[1]->data
[i
][1];
1162 u1
= VB
->TexCoordPtr
[1]->data
[i
][2];
1165 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
1166 t1
= VB
->TexCoordPtr
[1]->data
[i
][1];
1170 s1
= VB
->TexCoordPtr
[1]->data
[i
][0];
1175 /* should never get here */
1177 gl_problem(ctx
, "unexpected texcoord size in dist_atten_antialiased_rgba_points()");
1181 for (y
= ymin
; y
<= ymax
; y
++) {
1182 for (x
= xmin
; x
<= xmax
; x
++) {
1183 GLfloat dx
= x
/*+0.5F*/ - VB
->Win
.data
[i
][0];
1184 GLfloat dy
= y
/*+0.5F*/ - VB
->Win
.data
[i
][1];
1185 GLfloat dist2
= dx
*dx
+ dy
*dy
;
1186 if (dist2
< rmax2
) {
1187 alpha
= VB
->ColorPtr
->data
[i
][3];
1188 if (dist2
>= rmin2
) {
1189 GLint coverage
= (GLint
) (256.0F
- (dist2
- rmin2
) * cscale
);
1190 /* coverage is in [0,256] */
1191 alpha
= (alpha
* coverage
) >> 8;
1193 alpha
= (GLint
) (alpha
* alphaf
);
1194 if (ctx
->Texture
.ReallyEnabled
>= TEXTURE1_1D
) {
1195 PB_WRITE_MULTITEX_PIXEL( PB
, x
,y
,z
, red
, green
, blue
,
1196 alpha
, s
, t
, u
, s1
, t1
, u1
);
1198 PB_WRITE_TEX_PIXEL( PB
, x
,y
,z
, red
, green
, blue
, alpha
,
1204 PB_CHECK_FLUSH(ctx
,PB
);
1209 /* Not texture mapped */
1210 for (i
= first
; i
<= last
; i
++) {
1211 if (VB
->ClipMask
[i
] == 0) {
1212 GLfloat radius
, rmin
, rmax
, rmin2
, rmax2
, cscale
, alphaf
;
1213 GLint xmin
, ymin
, xmax
, ymax
;
1215 GLint red
, green
, blue
, alpha
;
1216 GLfloat dsize
= psize
* dist
[i
];
1218 if (dsize
>= ctx
->Point
.Threshold
) {
1219 radius
= MIN2(dsize
, ctx
->Point
.MaxSize
) * 0.5F
;
1223 radius
= (MAX2(ctx
->Point
.Threshold
, ctx
->Point
.MinSize
) * 0.5F
);
1224 dsize
/= ctx
->Point
.Threshold
;
1225 alphaf
= dsize
* dsize
;
1227 rmin
= radius
- 0.7071F
; /* 0.7071 = sqrt(2)/2 */
1228 rmax
= radius
+ 0.7071F
;
1229 rmin2
= rmin
* rmin
;
1230 rmax2
= rmax
* rmax
;
1231 cscale
= 256.0F
/ (rmax2
- rmin2
);
1233 xmin
= (GLint
) (VB
->Win
.data
[i
][0] - radius
);
1234 xmax
= (GLint
) (VB
->Win
.data
[i
][0] + radius
);
1235 ymin
= (GLint
) (VB
->Win
.data
[i
][1] - radius
);
1236 ymax
= (GLint
) (VB
->Win
.data
[i
][1] + radius
);
1237 z
= (GLint
) (VB
->Win
.data
[i
][2] + ctx
->PointZoffset
);
1239 red
= VB
->ColorPtr
->data
[i
][0];
1240 green
= VB
->ColorPtr
->data
[i
][1];
1241 blue
= VB
->ColorPtr
->data
[i
][2];
1243 for (y
= ymin
; y
<= ymax
; y
++) {
1244 for (x
= xmin
; x
<= xmax
; x
++) {
1245 GLfloat dx
= x
/*+0.5F*/ - VB
->Win
.data
[i
][0];
1246 GLfloat dy
= y
/*+0.5F*/ - VB
->Win
.data
[i
][1];
1247 GLfloat dist2
= dx
* dx
+ dy
* dy
;
1248 if (dist2
< rmax2
) {
1249 alpha
= VB
->ColorPtr
->data
[i
][3];
1250 if (dist2
>= rmin2
) {
1251 GLint coverage
= (GLint
) (256.0F
- (dist2
- rmin2
) * cscale
);
1252 /* coverage is in [0,256] */
1253 alpha
= (alpha
* coverage
) >> 8;
1255 alpha
= (GLint
) (alpha
* alphaf
);
1256 PB_WRITE_RGBA_PIXEL(PB
, x
, y
, z
, red
, green
, blue
, alpha
);
1260 PB_CHECK_FLUSH(ctx
,PB
);
1269 _mesa_print_points_function(GLcontext
*ctx
)
1271 printf("Point Func == ");
1272 if (ctx
->Driver
.PointsFunc
== size1_ci_points
)
1273 printf("size1_ci_points\n");
1274 else if (ctx
->Driver
.PointsFunc
== size1_rgba_points
)
1275 printf("size1_rgba_points\n");
1276 else if (ctx
->Driver
.PointsFunc
== general_ci_points
)
1277 printf("general_ci_points\n");
1278 else if (ctx
->Driver
.PointsFunc
== general_rgba_points
)
1279 printf("general_rgba_points\n");
1280 else if (ctx
->Driver
.PointsFunc
== textured_rgba_points
)
1281 printf("textured_rgba_points\n");
1282 else if (ctx
->Driver
.PointsFunc
== multitextured_rgba_points
)
1283 printf("multitextured_rgba_points\n");
1284 else if (ctx
->Driver
.PointsFunc
== antialiased_rgba_points
)
1285 printf("antialiased_rgba_points\n");
1286 else if (ctx
->Driver
.PointsFunc
== null_points
)
1287 printf("null_points\n");
1288 else if (ctx
->Driver
.PointsFunc
== dist_atten_general_ci_points
)
1289 printf("dist_atten_general_ci_points\n");
1290 else if (ctx
->Driver
.PointsFunc
== dist_atten_general_rgba_points
)
1291 printf("dist_atten_general_rgba_points\n");
1292 else if (ctx
->Driver
.PointsFunc
== dist_atten_textured_rgba_points
)
1293 printf("dist_atten_textured_rgba_points\n");
1294 else if (ctx
->Driver
.PointsFunc
== dist_atten_antialiased_rgba_points
)
1295 printf("dist_atten_antialiased_rgba_points\n");
1296 else if (!ctx
->Driver
.PointsFunc
)
1299 printf("Driver func %p\n", ctx
->Driver
.PointsFunc
);
1305 * Examine the current context to determine which point drawing function
1308 void gl_set_point_function( GLcontext
*ctx
)
1310 GLboolean rgbmode
= ctx
->Visual
->RGBAflag
;
1312 if (ctx
->RenderMode
==GL_RENDER
) {
1313 if (ctx
->NoRaster
) {
1314 ctx
->Driver
.PointsFunc
= null_points
;
1317 if (ctx
->Driver
.PointsFunc
) {
1318 /* Device driver will draw points. */
1319 ctx
->IndirectTriangles
&= ~DD_POINT_SW_RASTERIZE
;
1323 if (!ctx
->Point
.Attenuated
) {
1324 if (ctx
->Point
.SmoothFlag
&& rgbmode
) {
1325 ctx
->Driver
.PointsFunc
= antialiased_rgba_points
;
1327 else if (ctx
->Texture
.ReallyEnabled
) {
1328 if (ctx
->Texture
.ReallyEnabled
>= TEXTURE1_1D
) {
1329 ctx
->Driver
.PointsFunc
= multitextured_rgba_points
;
1332 ctx
->Driver
.PointsFunc
= textured_rgba_points
;
1335 else if (ctx
->Point
.Size
==1.0) {
1336 /* size=1, any raster ops */
1338 ctx
->Driver
.PointsFunc
= size1_rgba_points
;
1340 ctx
->Driver
.PointsFunc
= size1_ci_points
;
1343 /* every other kind of point rendering */
1345 ctx
->Driver
.PointsFunc
= general_rgba_points
;
1347 ctx
->Driver
.PointsFunc
= general_ci_points
;
1350 else if(ctx
->Point
.SmoothFlag
&& rgbmode
) {
1351 ctx
->Driver
.PointsFunc
= dist_atten_antialiased_rgba_points
;
1353 else if (ctx
->Texture
.ReallyEnabled
) {
1354 ctx
->Driver
.PointsFunc
= dist_atten_textured_rgba_points
;
1357 /* every other kind of point rendering */
1359 ctx
->Driver
.PointsFunc
= dist_atten_general_rgba_points
;
1361 ctx
->Driver
.PointsFunc
= dist_atten_general_ci_points
;
1364 else if (ctx
->RenderMode
==GL_FEEDBACK
) {
1365 ctx
->Driver
.PointsFunc
= gl_feedback_points
;
1368 /* GL_SELECT mode */
1369 ctx
->Driver
.PointsFunc
= gl_select_points
;
1372 /*_mesa_print_points_function(ctx);*/