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

misc.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 namespace TinyGL {
00032 
00033 void glopViewport(GLContext *c, GLParam *p) {
00034     int xsize, ysize, xmin, ymin, xsize_req, ysize_req;
00035 
00036     xmin = p[1].i;
00037     ymin = p[2].i;
00038     xsize = p[3].i;
00039     ysize = p[4].i;
00040 
00041     // we may need to resize the zbuffer
00042 
00043     if (c->viewport.xmin != xmin || c->viewport.ymin != ymin ||
00044             c->viewport.xsize != xsize || c->viewport.ysize != ysize) {
00045 
00046         xsize_req = xmin + xsize;
00047         ysize_req = ymin + ysize;
00048 
00049         if (c->gl_resize_viewport && c->gl_resize_viewport(c, &xsize_req, &ysize_req) != 0) {
00050             error("glViewport: error while resizing display");
00051         }
00052 
00053         xsize = xsize_req - xmin;
00054         ysize = ysize_req - ymin;
00055         if (xsize <= 0 || ysize <= 0) {
00056             error("glViewport: size too small");
00057         }
00058 
00059         c->viewport.xmin = xmin;
00060         c->viewport.ymin = ymin;
00061         c->viewport.xsize = xsize;
00062         c->viewport.ysize = ysize;
00063 
00064         c->viewport.updated = 1;
00065     }
00066 }
00067 
00068 void glopEnableDisable(GLContext *c, GLParam *p) {
00069     int code = p[1].i;
00070     int v = p[2].i;
00071 
00072     switch (code) {
00073     case TGL_CULL_FACE:
00074         c->cull_face_enabled = v;
00075         break;
00076     case TGL_LIGHTING:
00077         c->lighting_enabled = v;
00078         break;
00079     case TGL_COLOR_MATERIAL:
00080         c->color_material_enabled = v;
00081         break;
00082     case TGL_TEXTURE_2D:
00083         c->texture_2d_enabled = v;
00084         break;
00085     case TGL_NORMALIZE:
00086         c->normalize_enabled = v;
00087         break;
00088     case TGL_DEPTH_TEST:
00089         c->depth_test = v;
00090         c->fb->enableDepthTest(v);
00091         break;
00092     case TGL_ALPHA_TEST:
00093         c->fb->enableAlphaTest(v);
00094         break;
00095     case TGL_BLEND:
00096         c->fb->enableBlending(v);
00097         break;
00098     case TGL_POLYGON_OFFSET_FILL:
00099         if (v)
00100             c->offset_states |= TGL_OFFSET_FILL;
00101         else
00102             c->offset_states &= ~TGL_OFFSET_FILL;
00103         break;
00104     case TGL_POLYGON_OFFSET_POINT:
00105         if (v)
00106             c->offset_states |= TGL_OFFSET_POINT;
00107         else
00108             c->offset_states &= ~TGL_OFFSET_POINT;
00109         break;
00110     case TGL_POLYGON_OFFSET_LINE:
00111         if (v)
00112             c->offset_states |= TGL_OFFSET_LINE;
00113         else
00114             c->offset_states &= ~TGL_OFFSET_LINE;
00115         break;
00116     case TGL_SHADOW_MASK_MODE:
00117         if (v)
00118             c->shadow_mode |= 1;
00119         else
00120             c->shadow_mode &= ~1;
00121         break;
00122     case TGL_SHADOW_MODE:
00123         if (v)
00124             c->shadow_mode |= 2;
00125         else
00126             c->shadow_mode &= ~2;
00127         break;
00128     default:
00129         if (code >= TGL_LIGHT0 && code < TGL_LIGHT0 + T_MAX_LIGHTS) {
00130             gl_enable_disable_light(c, code - TGL_LIGHT0, v);
00131         } else {
00132             //warning("glEnableDisable: 0x%X not supported.", code);
00133         }
00134         break;
00135     }
00136 }
00137 
00138 void glopBlendFunc(GLContext *c, GLParam *p) {
00139     TGLenum sfactor = p[1].i;
00140     TGLenum dfactor = p[2].i;
00141     c->fb->setBlendingFactors(sfactor, dfactor);
00142 }
00143 
00144 void glopAlphaFunc(GLContext *c, GLParam *p) {
00145     TGLenum func = p[1].i;
00146     float ref = p[2].f;
00147     c->fb->setAlphaTestFunc(func, (int)(ref * 255));
00148 }
00149 
00150 void glopDepthFunc(GLContext *c, GLParam *p) {
00151     TGLenum func = p[1].i;
00152     c->fb->setDepthFunc(func);
00153 }
00154 
00155 void glopShadeModel(GLContext *c, GLParam *p) {
00156     int code = p[1].i;
00157     c->current_shade_model = code;
00158 }
00159 
00160 void glopCullFace(GLContext *c, GLParam *p) {
00161     int code = p[1].i;
00162     c->current_cull_face = code;
00163 }
00164 
00165 void glopFrontFace(GLContext *c, GLParam *p) {
00166     int code = p[1].i;
00167     c->current_front_face = code;
00168 }
00169 
00170 void glopPolygonMode(GLContext *c, GLParam *p) {
00171     int face = p[1].i;
00172     int mode = p[2].i;
00173 
00174     switch (face) {
00175     case TGL_BACK:
00176         c->polygon_mode_back = mode;
00177         break;
00178     case TGL_FRONT:
00179         c->polygon_mode_front = mode;
00180         break;
00181     case TGL_FRONT_AND_BACK:
00182         c->polygon_mode_front = mode;
00183         c->polygon_mode_back = mode;
00184         break;
00185     default:
00186         assert(0);
00187     }
00188 }
00189 
00190 void glopHint(GLContext *, GLParam *) {
00191     // do nothing
00192 }
00193 
00194 void glopPolygonOffset(GLContext *c, GLParam *p) {
00195     c->offset_factor = p[1].f;
00196     c->offset_units = p[2].f;
00197 }
00198 
00199 void glopColorMask(GLContext *c, TinyGL::GLParam *p) {
00200     c->color_mask = p[1].i;
00201 }
00202 
00203 void glopDepthMask(GLContext *c, TinyGL::GLParam *p) {
00204     c->fb->enableDepthWrite(p[1].i);
00205 }
00206 
00207 } // end of namespace TinyGL


Generated on Sat Mar 16 2019 05:01:46 for ResidualVM by doxygen 1.7.1
curved edge   curved edge