ff26856679c41840adfa149a7a500dfdd164afac
[mesa.git] / src / mesa / swrast / s_spantemp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.1
4 *
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25
26 /*
27 * Templates for the span/pixel-array write/read functions called via
28 * the gl_renderbuffer's GetRow, GetValues, PutRow, and PutValues.
29 *
30 * Define the following macros before including this file:
31 * NAME(BASE) to generate the function name (i.e. add prefix or suffix)
32 * RB_TYPE the renderbuffer DataType
33 * SPAN_VARS to declare any local variables
34 * INIT_PIXEL_PTR(P, X, Y) to initialize a pointer to a pixel
35 * INC_PIXEL_PTR(P) to increment a pixel pointer by one pixel
36 * STORE_PIXEL(DST, X, Y, VALUE) to store pixel values in buffer
37 * FETCH_PIXEL(DST, SRC) to fetch pixel values from buffer
38 *
39 * Note that in the STORE_PIXEL macros, we also pass in the (X,Y) coordinates
40 * for the pixels to be stored. This is useful when dithering and probably
41 * ignored otherwise.
42 */
43
44 #include "main/macros.h"
45
46
47 #if !defined(RB_COMPONENTS)
48 #define RB_COMPONENTS 4
49 #endif
50
51
52 static void
53 NAME(get_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
54 GLuint count, GLint x, GLint y, void *values )
55 {
56 #ifdef SPAN_VARS
57 SPAN_VARS
58 #endif
59 RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
60 GLuint i;
61 INIT_PIXEL_PTR(pixel, x, y);
62 for (i = 0; i < count; i++) {
63 FETCH_PIXEL(dest[i], pixel);
64 INC_PIXEL_PTR(pixel);
65 }
66 (void) rb;
67 (void) ctx;
68 }
69
70
71 static void
72 NAME(get_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
73 GLuint count, const GLint x[], const GLint y[], void *values )
74 {
75 #ifdef SPAN_VARS
76 SPAN_VARS
77 #endif
78 RB_TYPE (*dest)[RB_COMPONENTS] = (RB_TYPE (*)[RB_COMPONENTS]) values;
79 GLuint i;
80 for (i = 0; i < count; i++) {
81 INIT_PIXEL_PTR(pixel, x[i], y[i]);
82 FETCH_PIXEL(dest[i], pixel);
83 }
84 (void) rb;
85 (void) ctx;
86 }
87
88
89 static void
90 NAME(put_row)( struct gl_context *ctx, struct gl_renderbuffer *rb,
91 GLuint count, GLint x, GLint y,
92 const void *values, const GLubyte mask[] )
93 {
94 #ifdef SPAN_VARS
95 SPAN_VARS
96 #endif
97 const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
98 GLuint i;
99 INIT_PIXEL_PTR(pixel, x, y);
100 if (mask) {
101 for (i = 0; i < count; i++) {
102 if (mask[i]) {
103 STORE_PIXEL(pixel, x + i, y, src[i]);
104 }
105 INC_PIXEL_PTR(pixel);
106 }
107 }
108 else {
109 for (i = 0; i < count; i++) {
110 STORE_PIXEL(pixel, x + i, y, src[i]);
111 INC_PIXEL_PTR(pixel);
112 }
113 }
114 (void) rb;
115 (void) ctx;
116 }
117
118
119 static void
120 NAME(put_row_rgb)( struct gl_context *ctx, struct gl_renderbuffer *rb,
121 GLuint count, GLint x, GLint y,
122 const void *values, const GLubyte mask[] )
123 {
124 #ifdef SPAN_VARS
125 SPAN_VARS
126 #endif
127 const RB_TYPE (*src)[3] = (const RB_TYPE (*)[3]) values;
128 GLuint i;
129 INIT_PIXEL_PTR(pixel, x, y);
130 for (i = 0; i < count; i++) {
131 if (!mask || mask[i]) {
132 #ifdef STORE_PIXEL_RGB
133 STORE_PIXEL_RGB(pixel, x + i, y, src[i]);
134 #else
135 STORE_PIXEL(pixel, x + i, y, src[i]);
136 #endif
137 }
138 INC_PIXEL_PTR(pixel);
139 }
140 (void) rb;
141 (void) ctx;
142 }
143
144
145 static void
146 NAME(put_values)( struct gl_context *ctx, struct gl_renderbuffer *rb,
147 GLuint count, const GLint x[], const GLint y[],
148 const void *values, const GLubyte mask[] )
149 {
150 #ifdef SPAN_VARS
151 SPAN_VARS
152 #endif
153 const RB_TYPE (*src)[RB_COMPONENTS] = (const RB_TYPE (*)[RB_COMPONENTS]) values;
154 GLuint i;
155 ASSERT(mask);
156 for (i = 0; i < count; i++) {
157 if (mask[i]) {
158 INIT_PIXEL_PTR(pixel, x[i], y[i]);
159 STORE_PIXEL(pixel, x[i], y[i], src[i]);
160 }
161 }
162 (void) rb;
163 (void) ctx;
164 }
165
166
167 #undef NAME
168 #undef RB_TYPE
169 #undef RB_COMPONENTS
170 #undef SPAN_VARS
171 #undef INIT_PIXEL_PTR
172 #undef INC_PIXEL_PTR
173 #undef STORE_PIXEL
174 #undef STORE_PIXEL_RGB
175 #undef FETCH_PIXEL