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 227 228 229 230 231 232 233
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This file is based on, or a modified version of code from TinyGL (C) 1997-2022 Fabrice Bellard,
* which is licensed under the MIT license (see LICENSE).
* It also has modifications by the ResidualVM-team, which are covered under the GPLv2 (or later).
*/
#include "graphics/tinygl/zgl.h"
namespace TinyGL {
void GLContext::glopViewport(GLParam *p) {
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) {
xsize_req = xmin + xsize;
ysize_req = ymin + ysize;
if (gl_resize_viewport && gl_resize_viewport(&xsize_req, &ysize_req) != 0) {
error("glViewport: error while resizing display");
}
xsize = xsize_req - xmin;
ysize = ysize_req - ymin;
if (xsize <= 0 || ysize <= 0) {
error("glViewport: size too small");
}
viewport.xmin = xmin;
viewport.ymin = ymin;
viewport.xsize = xsize;
viewport.ysize = ysize;
viewport.updated = 1;
}
}
void GLContext::glopEnableDisable(GLParam *p) {
int code = p[1].i;
int v = p[2].i;
switch (code) {
case TGL_CULL_FACE:
cull_face_enabled = v != 0;
break;
case TGL_LIGHTING:
lighting_enabled = v != 0;
break;
case TGL_COLOR_MATERIAL:
color_material_enabled = v != 0;
break;
case TGL_FOG:
fog_enabled = v != 0;
break;
case TGL_TEXTURE_2D:
texture_2d_enabled = v != 0;
break;
case TGL_NORMALIZE:
normalize_enabled = v != 0;
break;
case TGL_DEPTH_TEST:
depth_test_enabled = v != 0;
break;
case TGL_ALPHA_TEST:
alpha_test_enabled = v != 0;
break;
case TGL_POLYGON_STIPPLE:
polygon_stipple_enabled = v != 0;
break;
case TGL_STENCIL_TEST:
stencil_test_enabled = v != 0;
break;
case TGL_BLEND:
blending_enabled = v != 0;
break;
case TGL_POLYGON_OFFSET_FILL:
if (v)
offset_states |= TGL_OFFSET_FILL;
else
offset_states &= ~TGL_OFFSET_FILL;
break;
case TGL_POLYGON_OFFSET_POINT:
if (v)
offset_states |= TGL_OFFSET_POINT;
else
offset_states &= ~TGL_OFFSET_POINT;
break;
case TGL_POLYGON_OFFSET_LINE:
if (v)
offset_states |= TGL_OFFSET_LINE;
else
offset_states &= ~TGL_OFFSET_LINE;
break;
default:
if (code >= TGL_LIGHT0 && code < TGL_LIGHT0 + T_MAX_LIGHTS) {
gl_enable_disable_light(code - TGL_LIGHT0, v);
} else {
//warning("glEnableDisable: 0x%X not supported.", code);
}
break;
}
}
void GLContext::glopBlendFunc(GLParam *p) {
source_blending_factor = p[1].i;
destination_blending_factor = p[2].i;
}
void GLContext::glopAlphaFunc(GLParam *p) {
alpha_test_func = p[1].i;
alpha_test_ref_val = (int)(p[2].f * 255);
}
void GLContext::glopDepthFunc(GLParam *p) {
depth_func = p[1].i;
}
void GLContext::glopStencilFunc(GLParam *p) {
TGLenum func = p[1].i;
TGLint ref = p[2].i;
TGLuint mask = p[3].ui;
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;
}
void GLContext::glopShadeModel(GLParam *p) {
int code = p[1].i;
current_shade_model = code;
}
void GLContext::glopCullFace(GLParam *p) {
int code = p[1].i;
current_cull_face = code;
}
void GLContext::glopFrontFace(GLParam *p) {
int code = p[1].i;
current_front_face = code;
}
void GLContext::glopPolygonMode(GLParam *p) {
int face = p[1].i;
int mode = p[2].i;
switch (face) {
case TGL_BACK:
polygon_mode_back = mode;
break;
case TGL_FRONT:
polygon_mode_front = mode;
break;
case TGL_FRONT_AND_BACK:
polygon_mode_front = mode;
polygon_mode_back = mode;
break;
default:
assert(0);
}
}
void GLContext::glopHint(GLParam *) {
// do nothing
}
void GLContext::glopPolygonStipple(GLParam *p) {
for (int i = 0; i < 128; i++) {
polygon_stipple_pattern[i] = p[i + 1].ui;
}
}
void GLContext::glopPolygonOffset(GLParam *p) {
offset_factor = p[1].f;
offset_units = p[2].f;
}
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 == TGL_TRUE;
}
void GLContext::glopStencilMask(TinyGL::GLParam *p) {
stencil_write_mask = p[1].ui;
}
} // end of namespace TinyGL
|