ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

arrays.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 /*
00024  * This file is based on, or a modified version of code from TinyGL (C) 1997-1998 Fabrice Bellard,
00025  * which is licensed under the zlib-license (see LICENSE).
00026  * It also has modifications by the ResidualVM-team, which are covered under the GPLv2 (or later).
00027  */
00028 
00029 #include "graphics/tinygl/zgl.h"
00030 
00031 #define VERTEX_ARRAY    0x0001
00032 #define COLOR_ARRAY     0x0002
00033 #define NORMAL_ARRAY    0x0004
00034 #define TEXCOORD_ARRAY  0x0008
00035 
00036 namespace TinyGL {
00037 
00038 void glopArrayElement(GLContext *c, GLParam *param) {
00039     int i;
00040     int states = c->client_states;
00041     int idx = param[1].i;
00042 
00043     if (states & COLOR_ARRAY) {
00044         GLParam p[5];
00045         int size = c->color_array_size;
00046         i = idx * (size + c->color_array_stride);
00047         p[1].f = c->color_array[i];
00048         p[2].f = c->color_array[i + 1];
00049         p[3].f = c->color_array[i + 2];
00050         p[4].f = size > 3 ? c->color_array[i + 3] : 1.0f;
00051         glopColor(c, p);
00052     }
00053     if (states & NORMAL_ARRAY) {
00054         i = idx * (3 + c->normal_array_stride);
00055         c->current_normal.X = c->normal_array[i];
00056         c->current_normal.Y = c->normal_array[i + 1];
00057         c->current_normal.Z = c->normal_array[i + 2];
00058         c->current_normal.W = 0.0f; // NOTE: this used to be Z but assigning Z again seemed like a bug...
00059     }
00060     if (states & TEXCOORD_ARRAY) {
00061         int size = c->texcoord_array_size;
00062         i = idx * (size + c->texcoord_array_stride);
00063         c->current_tex_coord.X = c->texcoord_array[i];
00064         c->current_tex_coord.Y = c->texcoord_array[i + 1];
00065         c->current_tex_coord.Z = size > 2 ? c->texcoord_array[i + 2] : 0.0f;
00066         c->current_tex_coord.W = size > 3 ? c->texcoord_array[i + 3] : 1.0f;
00067     }
00068     if (states & VERTEX_ARRAY) {
00069         GLParam p[5];
00070         int size = c->vertex_array_size;
00071         i = idx * (size + c->vertex_array_stride);
00072         p[1].f = c->vertex_array[i];
00073         p[2].f = c->vertex_array[i + 1];
00074         p[3].f = size > 2 ? c->vertex_array[i + 2] : 0.0f;
00075         p[4].f = size > 3 ? c->vertex_array[i + 3] : 1.0f;
00076         glopVertex(c, p);
00077     }
00078 }
00079 
00080 void glopDrawArrays(GLContext *c, GLParam *p) {
00081     GLParam array_element[2];
00082     GLParam begin[2];
00083     begin[1].i = p[1].i;
00084     glopBegin(c, begin);
00085     for (int i=0; i < p[3].i; i++) {
00086         array_element[1].i = p[2].i + i;
00087         glopArrayElement(c, array_element);
00088     }
00089     glopEnd(c, NULL);
00090 }
00091 
00092 void glopEnableClientState(GLContext *c, GLParam *p) {
00093     c->client_states |= p[1].i;
00094 }
00095 
00096 void glopDisableClientState(GLContext *c, GLParam *p) {
00097     c->client_states &= p[1].i;
00098 }
00099 
00100 void glopVertexPointer(GLContext *c, GLParam *p) {
00101     c->vertex_array_size = p[1].i;
00102     c->vertex_array_stride = p[2].i;
00103     c->vertex_array = (float *)p[3].p;
00104 }
00105 
00106 void glopColorPointer(GLContext *c, GLParam *p) {
00107     c->color_array_size = p[1].i;
00108     c->color_array_stride = p[2].i;
00109     c->color_array = (float *)p[3].p;
00110 }
00111 
00112 void glopNormalPointer(GLContext *c, GLParam *p) {
00113     c->normal_array_stride = p[1].i;
00114     c->normal_array = (float *)p[2].p;
00115 }
00116 
00117 void glopTexCoordPointer(GLContext *c, GLParam *p) {
00118     c->texcoord_array_size = p[1].i;
00119     c->texcoord_array_stride = p[2].i;
00120     c->texcoord_array = (float *)p[3].p;
00121 }
00122 
00123 } // end of namespace TinyGL
00124 
00125 void tglArrayElement(TGLint i) {
00126     TinyGL::GLParam p[2];
00127     p[0].op = TinyGL::OP_ArrayElement;
00128     p[1].i = i;
00129     gl_add_op(p);
00130 }
00131 
00132 void tglDrawArrays(TGLenum mode, TGLint first, TGLsizei count) {
00133     TinyGL::GLParam p[4];
00134     p[0].op = TinyGL::OP_DrawArrays;
00135     p[1].i = mode;
00136     p[2].i = first;
00137     p[3].i = count;
00138     gl_add_op(p);
00139 }
00140 
00141 void tglEnableClientState(TGLenum array) {
00142     TinyGL::GLParam p[2];
00143     p[0].op = TinyGL::OP_EnableClientState;
00144 
00145     switch (array) {
00146     case TGL_VERTEX_ARRAY:
00147         p[1].i = VERTEX_ARRAY;
00148         break;
00149     case TGL_NORMAL_ARRAY:
00150         p[1].i = NORMAL_ARRAY;
00151         break;
00152     case TGL_COLOR_ARRAY:
00153         p[1].i = COLOR_ARRAY;
00154         break;
00155     case TGL_TEXTURE_COORD_ARRAY:
00156         p[1].i = TEXCOORD_ARRAY;
00157         break;
00158     default:
00159         assert(0);
00160         break;
00161     }
00162     gl_add_op(p);
00163 }
00164 
00165 void tglDisableClientState(TGLenum array) {
00166     TinyGL::GLParam p[2];
00167     p[0].op = TinyGL::OP_DisableClientState;
00168 
00169     switch (array) {
00170     case TGL_VERTEX_ARRAY:
00171         p[1].i = ~VERTEX_ARRAY;
00172         break;
00173     case TGL_NORMAL_ARRAY:
00174         p[1].i = ~NORMAL_ARRAY;
00175         break;
00176     case TGL_COLOR_ARRAY:
00177         p[1].i = ~COLOR_ARRAY;
00178         break;
00179     case TGL_TEXTURE_COORD_ARRAY:
00180         p[1].i = ~TEXCOORD_ARRAY;
00181         break;
00182     default:
00183         assert(0);
00184         break;
00185     }
00186     gl_add_op(p);
00187 }
00188 
00189 void tglVertexPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
00190     TinyGL::GLParam p[4];
00191     assert(type == TGL_FLOAT);
00192     p[0].op = TinyGL::OP_VertexPointer;
00193     p[1].i = size;
00194     p[2].i = stride;
00195     p[3].p = const_cast<void *>(pointer);
00196     gl_add_op(p);
00197 }
00198 
00199 void tglColorPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
00200     TinyGL::GLParam p[4];
00201     assert(type == TGL_FLOAT);
00202     p[0].op = TinyGL::OP_ColorPointer;
00203     p[1].i = size;
00204     p[2].i = stride;
00205     p[3].p = const_cast<void *>(pointer);
00206     gl_add_op(p);
00207 }
00208 
00209 void tglNormalPointer(TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
00210     TinyGL::GLParam p[3];
00211     assert(type == TGL_FLOAT);
00212     p[0].op = TinyGL::OP_NormalPointer;
00213     p[1].i = stride;
00214     p[2].p = const_cast<void *>(pointer);
00215     gl_add_op(p);
00216 }
00217 
00218 void tglTexCoordPointer(TGLint size, TGLenum type, TGLsizei stride, const TGLvoid *pointer) {
00219     TinyGL::GLParam p[4];
00220     assert(type == TGL_FLOAT);
00221     p[0].op = TinyGL::OP_TexCoordPointer;
00222     p[1].i = size;
00223     p[2].i = stride;
00224     p[3].p = const_cast<void *>(pointer);
00225     gl_add_op(p);
00226 }


Generated on Sat Nov 30 2019 05:00:31 for ResidualVM by doxygen 1.7.1
curved edge   curved edge