31 #include "common/util.h" 32 #include "common/textconsole.h" 33 #include "common/array.h" 34 #include "common/list.h" 35 #include "common/scummsys.h" 37 #include "graphics/pixelformat.h" 38 #include "graphics/surface.h" 39 #include "graphics/tinygl/gl.h" 40 #include "graphics/tinygl/zbuffer.h" 41 #include "graphics/tinygl/zmath.h" 42 #include "graphics/tinygl/zblit.h" 43 #include "graphics/tinygl/zdirtyrect.h" 44 #include "graphics/tinygl/texelbuffer.h" 50 #define ADD_OP(a,b,c) OP_ ## a , 52 #include "graphics/tinygl/opinfo.h" 58 #define POLYGON_MAX_VERTEX 16 61 #define MAX_SPECULAR_BUFFERS 8 63 #define SPECULAR_BUFFER_SIZE 1024 65 #define SPECULAR_BUFFER_RESOLUTION 1024 67 #define MAX_MODELVIEW_STACK_DEPTH 35 68 #define MAX_PROJECTION_STACK_DEPTH 8 69 #define MAX_TEXTURE_STACK_DEPTH 8 70 #define MAX_NAME_STACK_DEPTH 64 71 #define MAX_TEXTURE_LEVELS 11 72 #define T_MAX_LIGHTS 32 74 #define VERTEX_HASH_SIZE 1031 76 #define MAX_DISPLAY_LISTS 1024 77 #define OP_BUFFER_MAX_SIZE 512 79 #define TGL_OFFSET_FILL 0x1 80 #define TGL_OFFSET_LINE 0x2 81 #define TGL_OFFSET_POINT 0x4 99 TGLfloat _float16[16];
105 float buf[SPECULAR_BUFFER_SIZE + 1];
118 float attenuation[3];
120 float cos_spot_cutoff;
141 int xmin, ymin, xsize, ysize;
156 GLParam ops[OP_BUFFER_MAX_SIZE];
179 bool operator==(
const GLVertex &other)
const {
181 edge_flag == other.edge_flag &&
182 normal == other.normal &&
183 coord == other.coord &&
184 tex_coord == other.tex_coord &&
185 color == other.color &&
188 clip_code == other.clip_code &&
192 bool operator!=(
const GLVertex &other)
const {
193 return !(*
this == other);
204 #define TEXTURE_HASH_TABLE_SIZE 256 207 GLImage images[MAX_TEXTURE_LEVELS];
238 _memoryBuffer =
nullptr;
243 void initialize(
size_t newSize) {
244 assert(_memoryBuffer ==
nullptr);
245 void *newBuffer = gl_malloc(newSize);
246 if (newBuffer ==
nullptr) {
247 error(
"Couldn't allocate memory for linear allocator.");
249 _memoryBuffer = newBuffer;
250 _memorySize = newSize;
254 if (_memoryBuffer !=
nullptr) {
255 gl_free(_memoryBuffer);
259 void *allocate(
size_t size) {
260 if (_memoryPosition + size >= _memorySize) {
261 error(
"Allocator out of memory: couldn't allocate more memory from linear allocator.");
263 size_t returnPos = _memoryPosition;
264 _memoryPosition += size;
265 return ((byte *)_memoryBuffer) + returnPos;
274 size_t _memoryPosition;
289 bool blending_enabled;
290 int source_blending_factor;
291 int destination_blending_factor;
294 bool alpha_test_enabled;
296 int alpha_test_ref_val;
305 int local_light_model;
306 bool lighting_enabled;
307 int light_model_two_side;
311 bool color_material_enabled;
312 int current_color_material_mode;
313 int current_color_material_type;
316 GLTexture *current_texture, *default_texture;
318 bool texture_2d_enabled;
319 int texture_mag_filter;
320 int texture_min_filter;
330 int current_op_buffer_index;
331 int exec_flag, compile_flag, print_flag;
337 int matrix_stack_depth_max[3];
340 Matrix4 matrix_model_projection;
341 int matrix_model_projection_updated;
342 int matrix_model_projection_no_w_transform;
343 int apply_texture_matrix;
349 int polygon_mode_back;
350 int polygon_mode_front;
352 int current_front_face;
353 int current_shade_model;
354 int current_cull_face;
355 bool cull_face_enabled;
356 bool normalize_enabled;
357 gl_draw_triangle_func draw_triangle_front, draw_triangle_back;
363 uint *select_ptr, *select_hit;
368 uint name_stack[MAX_NAME_STACK_DEPTH];
380 int current_edge_flag;
385 int vertex_n, vertex_cnt;
390 TGLvoid *vertex_array;
391 int vertex_array_size;
392 int vertex_array_stride;
393 int vertex_array_type;
394 TGLvoid *normal_array;
395 int normal_array_stride;
396 int normal_array_type;
397 TGLvoid *color_array;
398 int color_array_size;
399 int color_array_stride;
400 int color_array_type;
401 TGLvoid *texcoord_array;
402 int texcoord_array_size;
403 int texcoord_array_stride;
404 int texcoord_array_type;
415 int specbuf_used_counter;
416 int specbuf_num_buffers;
421 int (*gl_resize_viewport)(
int *xsize,
int *ysize);
424 bool depth_test_enabled;
426 bool depth_write_mask;
429 bool stencil_buffer_supported;
430 bool stencil_test_enabled;
431 int stencil_test_func;
434 uint stencil_write_mask;
440 bool color_mask_green;
441 bool color_mask_blue;
442 bool color_mask_alpha;
453 bool _enableDirtyRectangles;
456 bool polygon_stipple_enabled;
457 byte polygon_stipple_pattern[128];
465 int _currentAllocatorIndex;
467 bool _debugRectsEnabled;
468 bool _profilingEnabled;
470 void gl_vertex_transform(
GLVertex *v);
471 void gl_calc_fog_factor(
GLVertex *v);
473 void gl_get_pname(TGLenum pname,
union uglValue *data, eDataType &dataType);
478 #define ADD_OP(a, b, d) void glop ## a (GLParam *p); 479 #include "graphics/tinygl/opinfo.h" 482 void gl_compile_op(
GLParam *p);
484 void gl_eval_viewport();
485 void gl_transform_to_viewport(
GLVertex *v);
496 void gl_add_select(uint zmin, uint zmax);
497 void gl_add_select1(
int z1,
int z2,
int z3);
498 void gl_enable_disable_light(
int light,
int v);
501 void gl_GetIntegerv(TGLenum pname, TGLint *data);
502 void gl_GetFloatv(TGLenum pname, TGLfloat *data);
503 void gl_GetDoublev(TGLenum pname, TGLdouble *data);
504 void gl_GetBooleanv(TGLenum pname, TGLboolean *data);
506 void gl_EnableClientState(
GLParam *p);
507 void gl_DisableClientState(
GLParam *p);
508 void gl_VertexPointer(
GLParam *p);
509 void gl_ColorPointer(
GLParam *p);
510 void gl_NormalPointer(
GLParam *p);
511 void gl_TexCoordPointer(
GLParam *p);
516 void gl_GenTextures(TGLsizei n, TGLuint *textures);
517 void gl_DeleteTextures(TGLsizei n,
const TGLuint *textures);
518 void gl_PixelStore(TGLenum pname, TGLint param);
520 void issueDrawCall(
DrawCall *drawCall);
521 void disposeResources();
522 void disposeDrawCallLists();
527 void debugDrawRectangle(
Common::Rect rect,
int r,
int g,
int b);
529 GLSpecBuf *specbuf_get_buffer(
const int shininess_i,
const float shininess);
530 void specbuf_cleanup();
532 TGLint gl_RenderMode(TGLenum mode);
533 void gl_SelectBuffer(TGLsizei size, TGLuint *buffer);
535 GLList *alloc_list(
int list);
536 GLList *find_list(uint list);
537 void delete_list(
int list);
538 void gl_NewList(TGLuint list, TGLenum mode);
540 TGLboolean gl_IsList(TGLuint list);
541 TGLuint gl_GenLists(TGLsizei range);
543 void initSharedState();
544 void endSharedState();
547 bool enableStencilBuffer,
bool dirtyRectsEnable, uint32 drawCallMemorySize);
550 void gl_print_matrix(
const float *m);
551 void gl_debug(
int mode) {
559 #define VERTEX_ARRAY 0x0001 560 #define COLOR_ARRAY 0x0002 561 #define NORMAL_ARRAY 0x0004 562 #define TEXCOORD_ARRAY 0x0008 567 #define CLIP_EPSILON (1E-5) 569 static inline int gl_clipcode(
float x,
float y,
float z,
float w1) {
572 w = (float)(w1 * (1.0 + CLIP_EPSILON));
573 return (x < -w) | ((x > w) << 1) | ((y < -w) << 2) | ((y > w) << 3) | ((z < -w) << 4) | ((z > w) << 5);
576 static inline float clampf(
float a,
float min,
float max) {
Definition: zdirtyrect.h:41
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: colormasks.h:27
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: texelbuffer.h:29
Definition: zbuffer.h:106