blob: 8a2b4421b3d738e10357a6724bb8049e78d19ef0 [file] [log] [blame]
bigbiff673c7ae2020-12-02 19:44:56 -05001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_PIXELFLINGER_H
18#define ANDROID_PIXELFLINGER_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <pixelflinger/format.h>
24
25// GGL types
26
27typedef int8_t GGLbyte; // b
28typedef int16_t GGLshort; // s
29typedef int32_t GGLint; // i
30typedef ssize_t GGLsizei; // i
31typedef int32_t GGLfixed; // x
32typedef int32_t GGLclampx; // x
33typedef float GGLfloat; // f
34typedef float GGLclampf; // f
35typedef double GGLdouble; // d
36typedef double GGLclampd; // d
37typedef uint8_t GGLubyte; // ub
38typedef uint8_t GGLboolean; // ub
39typedef uint16_t GGLushort; // us
40typedef uint32_t GGLuint; // ui
41typedef unsigned int GGLenum; // ui
42typedef unsigned int GGLbitfield; // ui
43typedef void GGLvoid;
44typedef int32_t GGLfixed32;
45typedef int32_t GGLcolor;
46typedef int32_t GGLcoord;
47
48// ----------------------------------------------------------------------------
49
50#define GGL_MAX_VIEWPORT_DIMS 4096
51#define GGL_MAX_TEXTURE_SIZE 4096
52#define GGL_MAX_ALIASED_POINT_SIZE 0x7FFFFFF
53#define GGL_MAX_SMOOTH_POINT_SIZE 2048
54#define GGL_MAX_SMOOTH_LINE_WIDTH 2048
55
56// ----------------------------------------------------------------------------
57
58// All these names are compatible with their OpenGL equivalents
59// some of them are listed only for completeness
60enum GGLNames {
61 GGL_FALSE = 0,
62 GGL_TRUE = 1,
63
64 // enable/disable
65 GGL_SCISSOR_TEST = 0x0C11,
66 GGL_TEXTURE_2D = 0x0DE1,
67 GGL_ALPHA_TEST = 0x0BC0,
68 GGL_BLEND = 0x0BE2,
69 GGL_COLOR_LOGIC_OP = 0x0BF2,
70 GGL_DITHER = 0x0BD0,
71 GGL_STENCIL_TEST = 0x0B90,
72 GGL_DEPTH_TEST = 0x0B71,
73 GGL_AA = 0x80000001,
74 GGL_W_LERP = 0x80000004,
75 GGL_POINT_SMOOTH_NICE = 0x80000005,
76
77 // buffers, pixel drawing/reading
78 GGL_COLOR = 0x1800,
79
80 // fog
81 GGL_FOG = 0x0B60,
82
83 // shade model
84 GGL_FLAT = 0x1D00,
85 GGL_SMOOTH = 0x1D01,
86
87 // Texture parameter name
88 GGL_TEXTURE_MIN_FILTER = 0x2801,
89 GGL_TEXTURE_MAG_FILTER = 0x2800,
90 GGL_TEXTURE_WRAP_S = 0x2802,
91 GGL_TEXTURE_WRAP_T = 0x2803,
92 GGL_TEXTURE_WRAP_R = 0x2804,
93
94 // Texture Filter
95 GGL_NEAREST = 0x2600,
96 GGL_LINEAR = 0x2601,
97 GGL_NEAREST_MIPMAP_NEAREST = 0x2700,
98 GGL_LINEAR_MIPMAP_NEAREST = 0x2701,
99 GGL_NEAREST_MIPMAP_LINEAR = 0x2702,
100 GGL_LINEAR_MIPMAP_LINEAR = 0x2703,
101
102 // Texture Wrap Mode
103 GGL_CLAMP = 0x2900,
104 GGL_REPEAT = 0x2901,
105 GGL_CLAMP_TO_EDGE = 0x812F,
106
107 // Texture Env Mode
108 GGL_REPLACE = 0x1E01,
109 GGL_MODULATE = 0x2100,
110 GGL_DECAL = 0x2101,
111 GGL_ADD = 0x0104,
112
113 // Texture Env Parameter
114 GGL_TEXTURE_ENV_MODE = 0x2200,
115 GGL_TEXTURE_ENV_COLOR = 0x2201,
116
117 // Texture Env Target
118 GGL_TEXTURE_ENV = 0x2300,
119
120 // Texture coord generation
121 GGL_TEXTURE_GEN_MODE = 0x2500,
122 GGL_S = 0x2000,
123 GGL_T = 0x2001,
124 GGL_R = 0x2002,
125 GGL_Q = 0x2003,
126 GGL_ONE_TO_ONE = 0x80000002,
127 GGL_AUTOMATIC = 0x80000003,
128
129 // AlphaFunction
130 GGL_NEVER = 0x0200,
131 GGL_LESS = 0x0201,
132 GGL_EQUAL = 0x0202,
133 GGL_LEQUAL = 0x0203,
134 GGL_GREATER = 0x0204,
135 GGL_NOTEQUAL = 0x0205,
136 GGL_GEQUAL = 0x0206,
137 GGL_ALWAYS = 0x0207,
138
139 // LogicOp
140 GGL_CLEAR = 0x1500, // 0
141 GGL_AND = 0x1501, // s & d
142 GGL_AND_REVERSE = 0x1502, // s & ~d
143 GGL_COPY = 0x1503, // s
144 GGL_AND_INVERTED = 0x1504, // ~s & d
145 GGL_NOOP = 0x1505, // d
146 GGL_XOR = 0x1506, // s ^ d
147 GGL_OR = 0x1507, // s | d
148 GGL_NOR = 0x1508, // ~(s | d)
149 GGL_EQUIV = 0x1509, // ~(s ^ d)
150 GGL_INVERT = 0x150A, // ~d
151 GGL_OR_REVERSE = 0x150B, // s | ~d
152 GGL_COPY_INVERTED = 0x150C, // ~s
153 GGL_OR_INVERTED = 0x150D, // ~s | d
154 GGL_NAND = 0x150E, // ~(s & d)
155 GGL_SET = 0x150F, // 1
156
157 // blending equation & function
158 GGL_ZERO = 0, // SD
159 GGL_ONE = 1, // SD
160 GGL_SRC_COLOR = 0x0300, // D
161 GGL_ONE_MINUS_SRC_COLOR = 0x0301, // D
162 GGL_SRC_ALPHA = 0x0302, // SD
163 GGL_ONE_MINUS_SRC_ALPHA = 0x0303, // SD
164 GGL_DST_ALPHA = 0x0304, // SD
165 GGL_ONE_MINUS_DST_ALPHA = 0x0305, // SD
166 GGL_DST_COLOR = 0x0306, // S
167 GGL_ONE_MINUS_DST_COLOR = 0x0307, // S
168 GGL_SRC_ALPHA_SATURATE = 0x0308, // S
169
170 // clear bits
171 GGL_DEPTH_BUFFER_BIT = 0x00000100,
172 GGL_STENCIL_BUFFER_BIT = 0x00000400,
173 GGL_COLOR_BUFFER_BIT = 0x00004000,
174
175 // errors
176 GGL_NO_ERROR = 0,
177 GGL_INVALID_ENUM = 0x0500,
178 GGL_INVALID_VALUE = 0x0501,
179 GGL_INVALID_OPERATION = 0x0502,
180 GGL_STACK_OVERFLOW = 0x0503,
181 GGL_STACK_UNDERFLOW = 0x0504,
182 GGL_OUT_OF_MEMORY = 0x0505
183};
184
185// ----------------------------------------------------------------------------
186
187typedef struct {
188 GGLsizei version; // always set to sizeof(GGLSurface)
189 GGLuint width; // width in pixels
190 GGLuint height; // height in pixels
191 GGLint stride; // stride in pixels
192 GGLubyte* data; // pointer to the bits
193 GGLubyte format; // pixel format
194 GGLubyte rfu[3]; // must be zero
195 // these values are dependent on the used format
196 union {
197 GGLint compressedFormat;
198 GGLint vstride;
199 };
200 void* reserved;
201} GGLSurface;
202
203
204typedef struct {
205 // immediate rendering
206 void (*pointx)(void *con, const GGLcoord* v, GGLcoord r);
207 void (*linex)(void *con,
208 const GGLcoord* v0, const GGLcoord* v1, GGLcoord width);
209 void (*recti)(void* c, GGLint l, GGLint t, GGLint r, GGLint b);
210 void (*trianglex)(void* c,
211 GGLcoord const* v0, GGLcoord const* v1, GGLcoord const* v2);
212
213 // scissor
214 void (*scissor)(void* c, GGLint x, GGLint y, GGLsizei width, GGLsizei height);
215
216 // Set the textures and color buffers
217 void (*activeTexture)(void* c, GGLuint tmu);
218 void (*bindTexture)(void* c, const GGLSurface* surface);
219 void (*colorBuffer)(void* c, const GGLSurface* surface);
220 void (*readBuffer)(void* c, const GGLSurface* surface);
221 void (*depthBuffer)(void* c, const GGLSurface* surface);
222 void (*bindTextureLod)(void* c, GGLuint tmu, const GGLSurface* surface);
223
224 // enable/disable features
225 void (*enable)(void* c, GGLenum name);
226 void (*disable)(void* c, GGLenum name);
227 void (*enableDisable)(void* c, GGLenum name, GGLboolean en);
228
229 // specify the fragment's color
230 void (*shadeModel)(void* c, GGLenum mode);
231 void (*color4xv)(void* c, const GGLclampx* color);
232 // specify color iterators (16.16)
233 void (*colorGrad12xv)(void* c, const GGLcolor* grad);
234
235 // specify Z coordinate iterators (0.32)
236 void (*zGrad3xv)(void* c, const GGLfixed32* grad);
237
238 // specify W coordinate iterators (16.16)
239 void (*wGrad3xv)(void* c, const GGLfixed* grad);
240
241 // specify fog iterator & color (16.16)
242 void (*fogGrad3xv)(void* c, const GGLfixed* grad);
243 void (*fogColor3xv)(void* c, const GGLclampx* color);
244
245 // specify blending parameters
246 void (*blendFunc)(void* c, GGLenum src, GGLenum dst);
247 void (*blendFuncSeparate)(void* c, GGLenum src, GGLenum dst,
248 GGLenum srcAlpha, GGLenum dstAplha);
249
250 // texture environnement (REPLACE / MODULATE / DECAL / BLEND)
251 void (*texEnvi)(void* c, GGLenum target,
252 GGLenum pname,
253 GGLint param);
254
255 void (*texEnvxv)(void* c, GGLenum target,
256 GGLenum pname, const GGLfixed* params);
257
258 // texture parameters (Wrapping, filter)
259 void (*texParameteri)(void* c, GGLenum target,
260 GGLenum pname,
261 GGLint param);
262
263 // texture iterators (16.16)
264 void (*texCoord2i)(void* c, GGLint s, GGLint t);
265 void (*texCoord2x)(void* c, GGLfixed s, GGLfixed t);
266
267 // s, dsdx, dsdy, scale, t, dtdx, dtdy, tscale
268 // This api uses block floating-point for S and T texture coordinates.
269 // All values are given in 16.16, scaled by 'scale'. In other words,
270 // set scale to 0, for 16.16 values.
271 void (*texCoordGradScale8xv)(void* c, GGLint tmu, const int32_t* grad8);
272
273 void (*texGeni)(void* c, GGLenum coord, GGLenum pname, GGLint param);
274
275 // masking
276 void (*colorMask)(void* c, GGLboolean red,
277 GGLboolean green,
278 GGLboolean blue,
279 GGLboolean alpha);
280
281 void (*depthMask)(void* c, GGLboolean flag);
282
283 void (*stencilMask)(void* c, GGLuint mask);
284
285 // alpha func
286 void (*alphaFuncx)(void* c, GGLenum func, GGLclampx ref);
287
288 // depth func
289 void (*depthFunc)(void* c, GGLenum func);
290
291 // logic op
292 void (*logicOp)(void* c, GGLenum opcode);
293
294 // clear
295 void (*clear)(void* c, GGLbitfield mask);
296 void (*clearColorx)(void* c,
297 GGLclampx r, GGLclampx g, GGLclampx b, GGLclampx a);
298 void (*clearDepthx)(void* c, GGLclampx depth);
299 void (*clearStencil)(void* c, GGLint s);
300
301 // framebuffer operations
302 void (*copyPixels)(void* c, GGLint x, GGLint y,
303 GGLsizei width, GGLsizei height, GGLenum type);
304 void (*rasterPos2x)(void* c, GGLfixed x, GGLfixed y);
305 void (*rasterPos2i)(void* c, GGLint x, GGLint y);
306} GGLContext;
307
308// ----------------------------------------------------------------------------
309
310#ifdef __cplusplus
311extern "C" {
312#endif
313
314// construct / destroy the context
315ssize_t gglInit(GGLContext** context);
316ssize_t gglUninit(GGLContext* context);
317
318GGLint gglBitBlit(
319 GGLContext* c,
320 int tmu,
321 GGLint crop[4],
322 GGLint where[4]);
323
324#ifdef __cplusplus
325};
326#endif
327
328// ----------------------------------------------------------------------------
329
330#endif // ANDROID_PIXELFLINGER_H