[3597] | 1 | /* $Id: pb.h,v 1.2 2000-05-23 20:34:54 jeroen Exp $ */
|
---|
[2938] | 2 |
|
---|
| 3 | /*
|
---|
| 4 | * Mesa 3-D graphics library
|
---|
[3597] | 5 | * Version: 3.3
|
---|
[2938] | 6 | *
|
---|
| 7 | * Copyright (C) 1999 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 |
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | #ifndef PB_H
|
---|
| 32 | #define PB_H
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | #include "types.h"
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | /*
|
---|
| 39 | * Pixel buffer size, must be larger than MAX_WIDTH.
|
---|
| 40 | */
|
---|
| 41 | #define PB_SIZE (3*MAX_WIDTH)
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | struct pixel_buffer {
|
---|
[3597] | 45 | GLint x[PB_SIZE]; /* X window coord in [0,MAX_WIDTH) */
|
---|
| 46 | GLint y[PB_SIZE]; /* Y window coord in [0,MAX_HEIGHT) */
|
---|
| 47 | GLdepth z[PB_SIZE]; /* Z window coord in [0,Visual.MaxDepth] */
|
---|
| 48 | GLubyte rgba[PB_SIZE][4]; /* Colors */
|
---|
| 49 | GLubyte spec[PB_SIZE][3]; /* Separate specular colors */
|
---|
| 50 | GLuint i[PB_SIZE]; /* Index */
|
---|
| 51 | GLfloat s[MAX_TEXTURE_UNITS][PB_SIZE]; /* Texture S coordinates */
|
---|
| 52 | GLfloat t[MAX_TEXTURE_UNITS][PB_SIZE]; /* Texture T coordinates */
|
---|
| 53 | GLfloat u[MAX_TEXTURE_UNITS][PB_SIZE]; /* Texture R coordinates */
|
---|
| 54 | GLfloat lambda[MAX_TEXTURE_UNITS][PB_SIZE];/* Texture lambda values */
|
---|
| 55 | GLint color[4]; /* Mono color, integers! */
|
---|
| 56 | GLuint index; /* Mono index */
|
---|
| 57 | GLuint count; /* Number of pixels in buffer */
|
---|
| 58 | GLboolean mono; /* Same color or index for all pixels? */
|
---|
| 59 | GLenum primitive; /* GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP*/
|
---|
[2938] | 60 | };
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | /*
|
---|
| 65 | * Set the color used for all subsequent pixels in the buffer.
|
---|
| 66 | */
|
---|
[3597] | 67 | #define PB_SET_COLOR( CTX, PB, R, G, B, A ) \
|
---|
| 68 | if ((PB)->color[RCOMP]!=(R) || (PB)->color[GCOMP]!=(G) \
|
---|
| 69 | || (PB)->color[BCOMP]!=(B) || (PB)->color[ACOMP]!=(A) \
|
---|
| 70 | || !(PB)->mono) { \
|
---|
| 71 | gl_flush_pb( ctx ); \
|
---|
| 72 | } \
|
---|
| 73 | (PB)->color[RCOMP] = R; \
|
---|
| 74 | (PB)->color[GCOMP] = G; \
|
---|
| 75 | (PB)->color[BCOMP] = B; \
|
---|
| 76 | (PB)->color[ACOMP] = A; \
|
---|
| 77 | (PB)->mono = GL_TRUE;
|
---|
[2938] | 78 |
|
---|
| 79 |
|
---|
| 80 | /*
|
---|
| 81 | * Set the color index used for all subsequent pixels in the buffer.
|
---|
| 82 | */
|
---|
[3597] | 83 | #define PB_SET_INDEX( CTX, PB, I ) \
|
---|
| 84 | if ((PB)->index!=(I) || !(PB)->mono) { \
|
---|
| 85 | gl_flush_pb( CTX ); \
|
---|
| 86 | } \
|
---|
| 87 | (PB)->index = I; \
|
---|
| 88 | (PB)->mono = GL_TRUE;
|
---|
[2938] | 89 |
|
---|
| 90 |
|
---|
| 91 | /*
|
---|
| 92 | * "write" a pixel using current color or index
|
---|
| 93 | */
|
---|
[3597] | 94 | #define PB_WRITE_PIXEL( PB, X, Y, Z ) \
|
---|
| 95 | (PB)->x[(PB)->count] = X; \
|
---|
| 96 | (PB)->y[(PB)->count] = Y; \
|
---|
| 97 | (PB)->z[(PB)->count] = Z; \
|
---|
| 98 | (PB)->count++;
|
---|
[2938] | 99 |
|
---|
| 100 |
|
---|
| 101 | /*
|
---|
| 102 | * "write" an RGBA pixel
|
---|
| 103 | */
|
---|
[3597] | 104 | #define PB_WRITE_RGBA_PIXEL( PB, X, Y, Z, R, G, B, A ) \
|
---|
| 105 | (PB)->x[(PB)->count] = X; \
|
---|
| 106 | (PB)->y[(PB)->count] = Y; \
|
---|
| 107 | (PB)->z[(PB)->count] = Z; \
|
---|
| 108 | (PB)->rgba[(PB)->count][RCOMP] = R; \
|
---|
| 109 | (PB)->rgba[(PB)->count][GCOMP] = G; \
|
---|
| 110 | (PB)->rgba[(PB)->count][BCOMP] = B; \
|
---|
| 111 | (PB)->rgba[(PB)->count][ACOMP] = A; \
|
---|
| 112 | (PB)->count++;
|
---|
[2938] | 113 |
|
---|
| 114 | /*
|
---|
| 115 | * "write" a color-index pixel
|
---|
| 116 | */
|
---|
[3597] | 117 | #define PB_WRITE_CI_PIXEL( PB, X, Y, Z, I ) \
|
---|
| 118 | (PB)->x[(PB)->count] = X; \
|
---|
| 119 | (PB)->y[(PB)->count] = Y; \
|
---|
| 120 | (PB)->z[(PB)->count] = Z; \
|
---|
| 121 | (PB)->i[(PB)->count] = I; \
|
---|
| 122 | (PB)->count++;
|
---|
[2938] | 123 |
|
---|
| 124 |
|
---|
| 125 | /*
|
---|
| 126 | * "write" an RGBA pixel with texture coordinates
|
---|
| 127 | */
|
---|
[3597] | 128 | #define PB_WRITE_TEX_PIXEL( PB, X, Y, Z, R, G, B, A, S, T, U ) \
|
---|
| 129 | (PB)->x[(PB)->count] = X; \
|
---|
| 130 | (PB)->y[(PB)->count] = Y; \
|
---|
| 131 | (PB)->z[(PB)->count] = Z; \
|
---|
| 132 | (PB)->rgba[(PB)->count][RCOMP] = R; \
|
---|
| 133 | (PB)->rgba[(PB)->count][GCOMP] = G; \
|
---|
| 134 | (PB)->rgba[(PB)->count][BCOMP] = B; \
|
---|
| 135 | (PB)->rgba[(PB)->count][ACOMP] = A; \
|
---|
| 136 | (PB)->s[0][(PB)->count] = S; \
|
---|
| 137 | (PB)->t[0][(PB)->count] = T; \
|
---|
| 138 | (PB)->u[0][(PB)->count] = U; \
|
---|
| 139 | (PB)->count++;
|
---|
[2938] | 140 |
|
---|
| 141 | /*
|
---|
| 142 | * "write" an RGBA pixel with multiple texture coordinates
|
---|
| 143 | */
|
---|
[3597] | 144 | #define PB_WRITE_MULTITEX_PIXEL( PB, X, Y, Z, R, G, B, A, S, T, U, S1, T1, U1 ) \
|
---|
| 145 | (PB)->x[(PB)->count] = X; \
|
---|
| 146 | (PB)->y[(PB)->count] = Y; \
|
---|
| 147 | (PB)->z[(PB)->count] = Z; \
|
---|
| 148 | (PB)->rgba[(PB)->count][RCOMP] = R; \
|
---|
| 149 | (PB)->rgba[(PB)->count][GCOMP] = G; \
|
---|
| 150 | (PB)->rgba[(PB)->count][BCOMP] = B; \
|
---|
| 151 | (PB)->rgba[(PB)->count][ACOMP] = A; \
|
---|
| 152 | (PB)->s[0][(PB)->count] = S; \
|
---|
| 153 | (PB)->t[0][(PB)->count] = T; \
|
---|
| 154 | (PB)->u[0][(PB)->count] = U; \
|
---|
| 155 | (PB)->s[1][(PB)->count] = S1; \
|
---|
| 156 | (PB)->t[1][(PB)->count] = T1; \
|
---|
| 157 | (PB)->u[1][(PB)->count] = U1; \
|
---|
| 158 | (PB)->count++;
|
---|
[2938] | 159 |
|
---|
| 160 | /*
|
---|
| 161 | * "write" an RGBA pixel with multiple texture coordinates and specular color
|
---|
| 162 | */
|
---|
[3597] | 163 | #define PB_WRITE_MULTITEX_SPEC_PIXEL( PB, X, Y, Z, R, G, B, A, \
|
---|
| 164 | SR, SG, SB, S, T, U, S1, T1, U1 ) \
|
---|
| 165 | (PB)->x[(PB)->count] = X; \
|
---|
| 166 | (PB)->y[(PB)->count] = Y; \
|
---|
| 167 | (PB)->z[(PB)->count] = Z; \
|
---|
| 168 | (PB)->rgba[(PB)->count][RCOMP] = R; \
|
---|
| 169 | (PB)->rgba[(PB)->count][GCOMP] = G; \
|
---|
| 170 | (PB)->rgba[(PB)->count][BCOMP] = B; \
|
---|
| 171 | (PB)->rgba[(PB)->count][ACOMP] = A; \
|
---|
| 172 | (PB)->spec[(PB)->count][RCOMP] = SR; \
|
---|
| 173 | (PB)->spec[(PB)->count][GCOMP] = SG; \
|
---|
| 174 | (PB)->spec[(PB)->count][BCOMP] = SB; \
|
---|
| 175 | (PB)->s[0][(PB)->count] = S; \
|
---|
| 176 | (PB)->t[0][(PB)->count] = T; \
|
---|
| 177 | (PB)->u[0][(PB)->count] = U; \
|
---|
| 178 | (PB)->s[1][(PB)->count] = S1; \
|
---|
| 179 | (PB)->t[1][(PB)->count] = T1; \
|
---|
| 180 | (PB)->u[1][(PB)->count] = U1; \
|
---|
| 181 | (PB)->count++;
|
---|
[2938] | 182 |
|
---|
| 183 |
|
---|
| 184 |
|
---|
| 185 | /*
|
---|
| 186 | * Call this function at least every MAX_WIDTH pixels:
|
---|
| 187 | */
|
---|
[3597] | 188 | #define PB_CHECK_FLUSH( CTX, PB ) \
|
---|
| 189 | do { \
|
---|
| 190 | if ((PB)->count>=PB_SIZE-MAX_WIDTH) { \
|
---|
| 191 | gl_flush_pb( CTX ); \
|
---|
| 192 | } \
|
---|
[2938] | 193 | } while(0)
|
---|
| 194 |
|
---|
| 195 | extern struct pixel_buffer *gl_alloc_pb(void);
|
---|
| 196 |
|
---|
| 197 | extern void gl_flush_pb( GLcontext *ctx );
|
---|
| 198 |
|
---|
| 199 | #endif
|
---|