1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
/* ResidualVM - A 3D game interpreter
*
* ResidualVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/*
* This file is based on, or a modified version of code from TinyGL (C) 1997-1998 Fabrice Bellard,
* which is licensed under the zlib-license (see LICENSE).
* It also has modifications by the ResidualVM-team, which are covered under the GPLv2 (or later).
*/
#include "graphics/tinygl/zgl.h"
#define VERTEX_ARRAY 0x0001
#define COLOR_ARRAY 0x0002
#define NORMAL_ARRAY 0x0004
#define TEXCOORD_ARRAY 0x0008
namespace TinyGL {
void glopArrayElement(GLContext *c, GLParam *param) {
int i;
int states = c->client_states;
int idx = param[1].i;
if (states & COLOR_ARRAY) {
GLParam p[5];
int size = c->color_array_size;
i = idx * (size + c->color_array_stride);
p[1].f = c->color_array[i];
p[2].f = c->color_array[i + 1];
p[3].f = c->color_array[i + 2];
p[4].f = size > 3 ? c->color_array[i + 3] : 1.0f;
glopColor(c, p);
}
if (states & NORMAL_ARRAY) {
i = idx * (3 + c->normal_array_stride);
c->current_normal.X = c->normal_array[i];
c->current_normal.Y = c->normal_array[i + 1];
c->current_normal.Z = c->normal_array[i + 2];
c->current_normal.W = 0.0f; // NOTE: this used to be Z but assigning Z again seemed like a bug...
}
if (states & TEXCOORD_ARRAY) {
int size = c->texcoord_array_size;
i = idx * (size + c->texcoord_array_stride);
c->current_tex_coord.X = c->texcoord_array[i];
c->current_tex_coord.Y = c->texcoord_array[i + 1];
c->current_tex_coord.Z = size > 2 ? c->texcoord_array[i + 2] : 0.0f;
c->current_tex_coord.W = size > 3 ? c->texcoord_array[i + 3] : 1.0f;
}
if (states & VERTEX_ARRAY) {
GLParam p[5];
int size = c->vertex_array_size;
i = idx * (size + c->vertex_array_stride);
p[1].f = c->vertex_array[i];
p[2].f = c->vertex_array[i + 1];
p[3].f = size > 2 ? c->vertex_array[i + 2] : 0.0f;
p[4].f = size > 3 ? c->vertex_array[i + 3] : 1.0f;
glopVertex(c, p);
}
}
void glopDrawArrays(GLContext *c, GLParam *p) {
GLParam array_element[2];
GLParam begin[2];
begin[1].i = p[1].i;
glopBegin(c, begin);
for (int i=0; i < p[3].i; i++) {
array_element[1].i = p[2].i + i;
glopArrayElement(c, array_element);
}
glopEnd(c, NULL);
}
void glopEnableClientState(GLContext *c, GLParam *p) {
c->client_states |= p[1].i;
}
void glopDisableClientState(GLContext *c, GLParam *p) {
c->client_states &= p[1].i;
}
void glopVertexPointer(GLContext *c, GLParam *p) {
c->vertex_array_size = p[1].i;
c->vertex_array_stride = p[2].i;
c->vertex_array = (float *)p[3].p;
}
void glopColorPointer(GLContext *c, GLParam *p) {
c->color_array_size = p[1].i;
c->color_array_stride = p[2].i;
c->color_array = (float *)p[3].p;
}
void glopNormalPointer(GLContext *c, GLParam *p) {
c->normal_array_stride = p[1].i;
c->normal_array = (float *)p[2].p;
}
void glopTexCoordPointer(GLContext *c, GLParam *p) {
c->texcoord_array_size = p[1].i;
c->texcoord_array_stride = p[2].i;
c->texcoord_array = (float *)p[3].p;
}
} // end of namespace TinyGL
void tglArrayElement(TGLint i) {
TinyGL::GLParam p[2];
p[0].op = TinyGL::OP_ArrayElement;
p[1].i = i;
gl_add_op(p);
}
void tglDrawArrays(TGLenum mode, TGLint first, TGLsizei count) {
TinyGL::GLParam p[4];
p[0].op = TinyGL::OP_DrawArrays;
p[1].i = mode;
p[2].i = first;
p[3].i = count;
gl_add_op(p);
}
void tglEnableClientState(TGLenum array) {
TinyGL::GLParam p[2];
p[0].op = TinyGL::OP_EnableClientState;
switch (array) {
case TGL_VERTEX_ARRAY:
p[1].i = VERTEX_ARRAY;
break;
case TGL_NORMAL_ARRAY:
p[1].i = NORMAL_ARRAY;
break;
case TGL_COLOR_ARRAY:
p[1].i = COLOR_ARRAY;
break;
case TGL_TEXTURE_COORD_ARRAY:
p[1].i = TEXCOORD_ARRAY;
break;
default:
assert(0);
break;
}
gl_add_op(p);
}
void tglDisableClientState(TGLenum array) {
TinyGL::GLParam p[2];
p[0].op = TinyGL::OP_DisableClientState;
switch (array) {
case TGL_VERTEX_ARRAY:
p[1].i = ~VERTEX_ARRAY;
break;
case TGL_NORMAL_ARRAY:
p[1].i = ~NORMAL_ARRAY;
break;
case TGL_COLOR_ARRAY:
p[1].i = ~COLOR_ARRAY;
break;
case TGL_TEXTURE_COORD_ARRAY:
p[1].i = ~TEXCOORD_ARRAY;
break;
default:
assert(0);
break;
}
gl_add_op(p);
}
void tglVertexPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
TinyGL::GLParam p[4];
assert(type == TGL_FLOAT);
p[0].op = TinyGL::OP_VertexPointer;
p[1].i = size;
p[2].i = stride;
p[3].p = const_cast<void *>(pointer);
gl_add_op(p);
}
void tglColorPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
TinyGL::GLParam p[4];
assert(type == TGL_FLOAT);
p[0].op = TinyGL::OP_ColorPointer;
p[1].i = size;
p[2].i = stride;
p[3].p = const_cast<void *>(pointer);
gl_add_op(p);
}
void tglNormalPointer(TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
TinyGL::GLParam p[3];
assert(type == TGL_FLOAT);
p[0].op = TinyGL::OP_NormalPointer;
p[1].i = stride;
p[2].p = const_cast<void *>(pointer);
gl_add_op(p);
}
void tglTexCoordPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
TinyGL::GLParam p[4];
assert(type == TGL_FLOAT);
p[0].op = TinyGL::OP_TexCoordPointer;
p[1].i = size;
p[2].i = stride;
p[3].p = const_cast<void *>(pointer);
gl_add_op(p);
}
|