[1] | 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 | |
---|
| 10 | void |
---|
| 11 | glopArrayElement(GLContext *c, GLParam *param) |
---|
| 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); |
---|
| 37 | c->current_tex_coord.X = c->texcoord_array[i]; |
---|
| 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 | |
---|
| 54 | void |
---|
| 55 | glArrayElement(GLint i) |
---|
| 56 | { |
---|
| 57 | GLParam p[2]; |
---|
| 58 | p[0].op = OP_ArrayElement; |
---|
| 59 | p[1].i = i; |
---|
| 60 | gl_add_op(p); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | void |
---|
| 65 | glopEnableClientState(GLContext *c, GLParam *p) |
---|
| 66 | { |
---|
| 67 | c->client_states |= p[1].i; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | void |
---|
| 71 | glEnableClientState(GLenum array) |
---|
| 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; |
---|
| 86 | case GL_TEXTURE_COORD_ARRAY: |
---|
| 87 | p[1].i = TEXCOORD_ARRAY; |
---|
| 88 | break; |
---|
| 89 | default: |
---|
| 90 | assert(0); |
---|
| 91 | break; |
---|
| 92 | } |
---|
| 93 | gl_add_op(p); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | void |
---|
| 97 | glopDisableClientState(GLContext *c, GLParam *p) |
---|
| 98 | { |
---|
| 99 | c->client_states &= p[1].i; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | void |
---|
| 103 | glDisableClientState(GLenum array) |
---|
| 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; |
---|
| 118 | case GL_TEXTURE_COORD_ARRAY: |
---|
| 119 | p[1].i = ~TEXCOORD_ARRAY; |
---|
| 120 | break; |
---|
| 121 | default: |
---|
| 122 | assert(0); |
---|
| 123 | break; |
---|
| 124 | } |
---|
| 125 | gl_add_op(p); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | void |
---|
| 129 | glopVertexPointer(GLContext *c, GLParam *p) |
---|
| 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 | |
---|
| 136 | void |
---|
| 137 | glVertexPointer(GLint size, GLenum type, GLsizei stride, |
---|
| 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 | |
---|
| 149 | void |
---|
| 150 | glopColorPointer(GLContext *c, GLParam *p) |
---|
| 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 | |
---|
| 157 | void |
---|
| 158 | glColorPointer(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 | |
---|
| 170 | void |
---|
| 171 | glopNormalPointer(GLContext *c, GLParam *p) |
---|
| 172 | { |
---|
| 173 | c->normal_array_stride = p[1].i; |
---|
| 174 | c->normal_array = p[2].p; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | void |
---|
| 178 | glNormalPointer(GLenum type, GLsizei stride, |
---|
| 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 | } |
---|
| 187 | |
---|
| 188 | void |
---|
| 189 | glopTexCoordPointer(GLContext *c, GLParam *p) |
---|
| 190 | { |
---|
| 191 | c->texcoord_array_size = p[1].i; |
---|
| 192 | c->texcoord_array_stride = p[2].i; |
---|
| 193 | c->texcoord_array = p[3].p; |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | void |
---|
| 197 | glTexCoordPointer(GLint size, GLenum type, GLsizei stride, |
---|
| 198 | const GLvoid *pointer) |
---|
| 199 | { |
---|
| 200 | GLParam p[4]; |
---|
| 201 | assert(type == GL_FLOAT); |
---|
| 202 | p[0].op = OP_TexCoordPointer; |
---|
| 203 | p[1].i = size; |
---|
| 204 | p[2].i = stride; |
---|
| 205 | p[3].p = (void*)pointer; |
---|
| 206 | } |
---|