scummvm/graphics/tinygl/misc.cpp

223 lines
5.1 KiB
C++
Raw Normal View History

2014-08-13 18:52:52 +02:00
/* 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).
*/
2006-05-16 14:52:36 +00:00
2009-05-08 07:32:33 +00:00
#include "graphics/tinygl/zgl.h"
namespace TinyGL {
2021-12-07 09:54:19 +01:00
void GLContext::glopViewport(GLParam *p) {
2006-05-16 14:52:36 +00:00
int xsize, ysize, xmin, ymin, xsize_req, ysize_req;
xmin = p[1].i;
ymin = p[2].i;
xsize = p[3].i;
ysize = p[4].i;
// we may need to resize the zbuffer
if (viewport.xmin != xmin || viewport.ymin != ymin ||
viewport.xsize != xsize || viewport.ysize != ysize) {
2006-05-16 14:52:36 +00:00
xsize_req = xmin + xsize;
ysize_req = ymin + ysize;
2021-12-07 09:54:19 +01:00
if (gl_resize_viewport && gl_resize_viewport(&xsize_req, &ysize_req) != 0) {
error("glViewport: error while resizing display");
2006-05-16 14:52:36 +00:00
}
xsize = xsize_req - xmin;
ysize = ysize_req - ymin;
if (xsize <= 0 || ysize <= 0) {
error("glViewport: size too small");
2006-05-16 14:52:36 +00:00
}
viewport.xmin = xmin;
viewport.ymin = ymin;
viewport.xsize = xsize;
viewport.ysize = ysize;
2006-05-16 14:52:36 +00:00
viewport.updated = 1;
2006-05-16 14:52:36 +00:00
}
}
2021-12-07 09:54:19 +01:00
void GLContext::glopEnableDisable(GLParam *p) {
2006-05-16 14:52:36 +00:00
int code = p[1].i;
int v = p[2].i;
switch (code) {
case TGL_CULL_FACE:
cull_face_enabled = v;
2006-05-16 14:52:36 +00:00
break;
case TGL_LIGHTING:
lighting_enabled = v;
2006-05-16 14:52:36 +00:00
break;
case TGL_COLOR_MATERIAL:
color_material_enabled = v;
2006-05-16 14:52:36 +00:00
break;
case TGL_TEXTURE_2D:
texture_2d_enabled = v;
2006-05-16 14:52:36 +00:00
break;
case TGL_NORMALIZE:
normalize_enabled = v;
2006-05-16 14:52:36 +00:00
break;
case TGL_DEPTH_TEST:
depth_test_enabled = v;
2006-05-16 14:52:36 +00:00
break;
2014-07-04 08:43:19 +02:00
case TGL_ALPHA_TEST:
alpha_test_enabled = v;
2014-07-04 08:43:19 +02:00
break;
case TGL_STENCIL_TEST:
stencil_test_enabled = v;
break;
case TGL_BLEND:
blending_enabled = v;
break;
2006-05-16 14:52:36 +00:00
case TGL_POLYGON_OFFSET_FILL:
if (v)
offset_states |= TGL_OFFSET_FILL;
2006-05-16 14:52:36 +00:00
else
offset_states &= ~TGL_OFFSET_FILL;
break;
2006-05-16 14:52:36 +00:00
case TGL_POLYGON_OFFSET_POINT:
if (v)
offset_states |= TGL_OFFSET_POINT;
2006-05-16 14:52:36 +00:00
else
offset_states &= ~TGL_OFFSET_POINT;
break;
2006-05-16 14:52:36 +00:00
case TGL_POLYGON_OFFSET_LINE:
if (v)
offset_states |= TGL_OFFSET_LINE;
2006-05-16 14:52:36 +00:00
else
offset_states &= ~TGL_OFFSET_LINE;
break;
2006-05-16 14:52:36 +00:00
default:
2008-07-29 19:28:19 +00:00
if (code >= TGL_LIGHT0 && code < TGL_LIGHT0 + T_MAX_LIGHTS) {
gl_enable_disable_light(code - TGL_LIGHT0, v);
2006-05-16 14:52:36 +00:00
} else {
2008-09-28 18:08:09 +00:00
//warning("glEnableDisable: 0x%X not supported.", code);
2006-05-16 14:52:36 +00:00
}
break;
}
}
2021-12-07 09:54:19 +01:00
void GLContext::glopBlendFunc(GLParam *p) {
source_blending_factor = p[1].i;
destination_blending_factor = p[2].i;
}
2014-07-04 08:43:19 +02:00
2021-12-07 09:54:19 +01:00
void GLContext::glopAlphaFunc(GLParam *p) {
alpha_test_func = p[1].i;
alpha_test_ref_val = (int)(p[2].f * 255);
2014-07-04 08:43:19 +02:00
}
2014-07-04 23:14:44 +02:00
2021-12-07 09:54:19 +01:00
void GLContext::glopDepthFunc(GLParam *p) {
depth_func = p[1].i;
2014-07-04 23:14:44 +02:00
}
void GLContext::glopStencilFunc(GLParam *p) {
TGLenum func = p[1].i;
TGLint ref = p[2].i;
TGLuint mask = p[3].i;
if (func < TGL_NEVER || func > TGL_ALWAYS)
return;
if (ref < 0)
ref = 0;
else if (ref > 255)
ref = 255;
stencil_test_func = func;
stencil_ref_val = ref;
stencil_mask = mask;
}
void GLContext::glopStencilOp(GLParam *p) {
stencil_sfail = p[1].i;
stencil_dpfail = p[2].i;
stencil_dppass = p[3].i;
}
2021-12-07 09:54:19 +01:00
void GLContext::glopShadeModel(GLParam *p) {
2006-05-16 14:52:36 +00:00
int code = p[1].i;
current_shade_model = code;
}
2021-12-07 09:54:19 +01:00
void GLContext::glopCullFace(GLParam *p) {
2006-05-16 14:52:36 +00:00
int code = p[1].i;
current_cull_face = code;
}
2021-12-07 09:54:19 +01:00
void GLContext::glopFrontFace(GLParam *p) {
2006-05-16 14:52:36 +00:00
int code = p[1].i;
current_front_face = code;
}
2021-12-07 09:54:19 +01:00
void GLContext::glopPolygonMode(GLParam *p) {
2006-05-16 14:52:36 +00:00
int face = p[1].i;
int mode = p[2].i;
switch (face) {
2006-05-16 14:52:36 +00:00
case TGL_BACK:
polygon_mode_back = mode;
2006-05-16 14:52:36 +00:00
break;
case TGL_FRONT:
polygon_mode_front = mode;
2006-05-16 14:52:36 +00:00
break;
case TGL_FRONT_AND_BACK:
polygon_mode_front = mode;
polygon_mode_back = mode;
2006-05-16 14:52:36 +00:00
break;
default:
assert(0);
}
}
2021-12-07 09:54:19 +01:00
void GLContext::glopHint(GLParam *) {
2006-05-16 14:52:36 +00:00
// do nothing
}
2021-12-07 09:54:19 +01:00
void GLContext::glopPolygonOffset(GLParam *p) {
offset_factor = p[1].f;
offset_units = p[2].f;
}
2021-12-07 09:54:19 +01:00
void GLContext::glopColorMask(GLParam *p) {
color_mask_red = p[1].i == TGL_TRUE;
color_mask_green = p[2].i == TGL_TRUE;
color_mask_blue = p[3].i == TGL_TRUE;
color_mask_alpha = p[4].i == TGL_TRUE;
}
void GLContext::glopDepthMask(GLParam *p) {
depth_write_mask = p[1].i;
}
void GLContext::glopStencilMask(TinyGL::GLParam *p) {
stencil_write_mask = p[1].i;
}
} // end of namespace TinyGL