TinyGL 0.4.1 for MinGW
arrays.c
Go to the documentation of this file.
1#include "zgl.h"
2#include <assert.h>
3#include <stdio.h>
4
5#define VERTEX_ARRAY 0x0001
6#define COLOR_ARRAY 0x0002
7#define NORMAL_ARRAY 0x0004
8#define TEXCOORD_ARRAY 0x0008
9
10void
12{
13 int i;
14 int states = c->client_states;
15 int idx = param[1].i;
16
17 if (states & COLOR_ARRAY) {
18 GLParam p[5];
19 int size = c->color_array_size;
20 i = idx * (size + c->color_array_stride);
21 p[1].f = c->color_array[i];
22 p[2].f = c->color_array[i+1];
23 p[3].f = c->color_array[i+2];
24 p[4].f = size > 3 ? c->color_array[i+3] : 1.0f;
25 glopColor(c, p);
26 }
27 if (states & NORMAL_ARRAY) {
28 i = idx * (3 + c->normal_array_stride);
29 c->current_normal.X = c->normal_array[i];
30 c->current_normal.Y = c->normal_array[i+1];
31 c->current_normal.Z = c->normal_array[i+2];
32 c->current_normal.Z = 0.0f;
33 }
34 if (states & TEXCOORD_ARRAY) {
35 int size = c->texcoord_array_size;
36 i = idx * (size + c->texcoord_array_stride);
38 c->current_tex_coord.Y = c->texcoord_array[i+1];
39 c->current_tex_coord.Z = size > 2 ? c->texcoord_array[i+2] : 0.0f;
40 c->current_tex_coord.W = size > 3 ? c->texcoord_array[i+3] : 1.0f;
41 }
42 if (states & VERTEX_ARRAY) {
43 GLParam p[5];
44 int size = c->vertex_array_size;
45 i = idx * (size + c->vertex_array_stride);
46 p[1].f = c->vertex_array[i];
47 p[2].f = c->vertex_array[i+1];
48 p[3].f = size > 2 ? c->vertex_array[i+2] : 0.0f;
49 p[4].f = size > 3 ? c->vertex_array[i+3] : 1.0f;
50 glopVertex(c, p);
51 }
52}
53
54void
56{
57 GLParam p[2];
58 p[0].op = OP_ArrayElement;
59 p[1].i = i;
60 gl_add_op(p);
61}
62
63
64void
66{
67 c->client_states |= p[1].i;
68}
69
70void
72{
73 GLParam p[2];
74 p[0].op = OP_EnableClientState;
75
76 switch(array) {
77 case GL_VERTEX_ARRAY:
78 p[1].i = VERTEX_ARRAY;
79 break;
80 case GL_NORMAL_ARRAY:
81 p[1].i = NORMAL_ARRAY;
82 break;
83 case GL_COLOR_ARRAY:
84 p[1].i = COLOR_ARRAY;
85 break;
87 p[1].i = TEXCOORD_ARRAY;
88 break;
89 default:
90 assert(0);
91 break;
92 }
93 gl_add_op(p);
94}
95
96void
98{
99 c->client_states &= p[1].i;
100}
101
102void
104{
105 GLParam p[2];
106 p[0].op = OP_DisableClientState;
107
108 switch(array) {
109 case GL_VERTEX_ARRAY:
110 p[1].i = ~VERTEX_ARRAY;
111 break;
112 case GL_NORMAL_ARRAY:
113 p[1].i = ~NORMAL_ARRAY;
114 break;
115 case GL_COLOR_ARRAY:
116 p[1].i = ~COLOR_ARRAY;
117 break;
119 p[1].i = ~TEXCOORD_ARRAY;
120 break;
121 default:
122 assert(0);
123 break;
124 }
125 gl_add_op(p);
126}
127
128void
130{
131 c->vertex_array_size = p[1].i;
132 c->vertex_array_stride = p[2].i;
133 c->vertex_array = p[3].p;
134}
135
136void
138 const GLvoid *pointer)
139{
140 GLParam p[4];
141 assert(type == GL_FLOAT);
142 p[0].op = OP_VertexPointer;
143 p[1].i = size;
144 p[2].i = stride;
145 p[3].p = (void*)pointer;
146 gl_add_op(p);
147}
148
149void
151{
152 c->color_array_size = p[1].i;
153 c->color_array_stride = p[2].i;
154 c->color_array = p[3].p;
155}
156
157void
158glColorPointer(GLint size, GLenum type, GLsizei stride,
159 const GLvoid *pointer)
160{
161 GLParam p[4];
162 assert(type == GL_FLOAT);
163 p[0].op = OP_ColorPointer;
164 p[1].i = size;
165 p[2].i = stride;
166 p[3].p = (void*)pointer;
167 gl_add_op(p);
168}
169
170void
172{
173 c->normal_array_stride = p[1].i;
174 c->normal_array = p[2].p;
175}
176
177void
179 const GLvoid *pointer)
180{
181 GLParam p[3];
182 assert(type == GL_FLOAT);
183 p[0].op = OP_NormalPointer;
184 p[1].i = stride;
185 p[2].p = (void*)pointer;
186 gl_add_op(p);
187}
188
189void
191{
192 c->texcoord_array_size = p[1].i;
193 c->texcoord_array_stride = p[2].i;
194 c->texcoord_array = p[3].p;
195}
196
197void
199 const GLvoid *pointer)
200{
201 GLParam p[4];
202 assert(type == GL_FLOAT);
203 p[0].op = OP_TexCoordPointer;
204 p[1].i = size;
205 p[2].i = stride;
206 p[3].p = (void*)pointer;
207 gl_add_op(p);
208}
void glopTexCoordPointer(GLContext *c, GLParam *p)
Definition: arrays.c:190
void glopEnableClientState(GLContext *c, GLParam *p)
Definition: arrays.c:65
void glColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
Definition: arrays.c:158
void glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
Definition: arrays.c:137
void glArrayElement(GLint i)
Definition: arrays.c:55
#define NORMAL_ARRAY
Definition: arrays.c:7
void glTexCoordPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
Definition: arrays.c:198
void glDisableClientState(GLenum array)
Definition: arrays.c:103
void glEnableClientState(GLenum array)
Definition: arrays.c:71
void glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer)
Definition: arrays.c:178
#define TEXCOORD_ARRAY
Definition: arrays.c:8
#define COLOR_ARRAY
Definition: arrays.c:6
void glopArrayElement(GLContext *c, GLParam *param)
Definition: arrays.c:11
void glopDisableClientState(GLContext *c, GLParam *p)
Definition: arrays.c:97
#define VERTEX_ARRAY
Definition: arrays.c:5
void glopNormalPointer(GLContext *c, GLParam *p)
Definition: arrays.c:171
void glopColorPointer(GLContext *c, GLParam *p)
Definition: arrays.c:150
void glopVertexPointer(GLContext *c, GLParam *p)
Definition: arrays.c:129
@ GL_FLOAT
Definition: gl.h:25
@ GL_VERTEX_ARRAY
Definition: gl.h:45
@ GL_NORMAL_ARRAY
Definition: gl.h:46
@ GL_COLOR_ARRAY
Definition: gl.h:47
@ GL_TEXTURE_COORD_ARRAY
Definition: gl.h:49
int GLenum
Definition: gl.h:662
void GLvoid
Definition: gl.h:663
int GLint
Definition: gl.h:667
int GLsizei
Definition: gl.h:673
void gl_add_op(GLParam *p)
Definition: list.c:137
Definition: zgl.h:159
float * texcoord_array
Definition: zgl.h:255
float * normal_array
Definition: zgl.h:250
int texcoord_array_stride
Definition: zgl.h:257
V4 current_tex_coord
Definition: zgl.h:236
float * vertex_array
Definition: zgl.h:247
int texcoord_array_size
Definition: zgl.h:256
int vertex_array_size
Definition: zgl.h:248
int color_array_stride
Definition: zgl.h:254
V4 current_normal
Definition: zgl.h:235
int normal_array_stride
Definition: zgl.h:251
int vertex_array_stride
Definition: zgl.h:249
float * color_array
Definition: zgl.h:252
int color_array_size
Definition: zgl.h:253
int client_states
Definition: zgl.h:258
Definition: zgl.h:97
void * p
Definition: zgl.h:102
int op
Definition: zgl.h:98
int i
Definition: zgl.h:100
float f
Definition: zgl.h:99
void glopVertex(GLContext *c, GLParam *p)
Definition: vertex.c:206
void glopColor(GLContext *c, GLParam *p)
Definition: vertex.c:30