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 scissor_test_enabled;
293 bool blending_enabled;
294 int source_blending_factor;
295 int destination_blending_factor;
298 bool alpha_test_enabled;
300 int alpha_test_ref_val;
309 int local_light_model;
310 bool lighting_enabled;
311 int light_model_two_side;
315 bool color_material_enabled;
316 int current_color_material_mode;
317 int current_color_material_type;
320 GLTexture *current_texture, *default_texture;
322 bool texture_2d_enabled;
323 int texture_mag_filter;
324 int texture_min_filter;
335 int current_op_buffer_index;
336 int exec_flag, compile_flag, print_flag;
342 int matrix_stack_depth_max[3];
345 Matrix4 matrix_model_projection;
346 int matrix_model_projection_updated;
347 int matrix_model_projection_no_w_transform;
348 int apply_texture_matrix;
354 int polygon_mode_back;
355 int polygon_mode_front;
357 int current_front_face;
358 int current_shade_model;
359 int current_cull_face;
360 bool cull_face_enabled;
361 bool normalize_enabled;
362 gl_draw_triangle_func draw_triangle_front, draw_triangle_back;
368 uint *select_ptr, *select_hit;
373 uint name_stack[MAX_NAME_STACK_DEPTH];
385 int current_edge_flag;
390 int vertex_n, vertex_cnt;
395 TGLvoid *vertex_array;
396 int vertex_array_size;
397 int vertex_array_stride;
398 int vertex_array_type;
399 TGLvoid *normal_array;
400 int normal_array_stride;
401 int normal_array_type;
402 TGLvoid *color_array;
403 int color_array_size;
404 int color_array_stride;
405 int color_array_type;
406 TGLvoid *texcoord_array;
407 int texcoord_array_size;
408 int texcoord_array_stride;
409 int texcoord_array_type;
420 int specbuf_used_counter;
421 int specbuf_num_buffers;
426 int (*gl_resize_viewport)(
int *xsize,
int *ysize);
429 bool depth_test_enabled;
431 bool depth_write_mask;
434 bool stencil_buffer_supported;
435 bool stencil_test_enabled;
436 int stencil_test_func;
437 byte stencil_ref_val;
439 byte stencil_write_mask;
445 bool color_mask_green;
446 bool color_mask_blue;
447 bool color_mask_alpha;
456 bool _enableDirtyRectangles;
459 bool polygon_stipple_enabled;
460 byte polygon_stipple_pattern[128];
462 bool two_color_stipple_enabled;
470 int _currentAllocatorIndex;
472 bool _debugRectsEnabled;
473 bool _profilingEnabled;
475 void gl_vertex_transform(
GLVertex *v);
476 void gl_calc_fog_factor(
GLVertex *v);
478 void gl_get_pname(TGLenum pname,
union uglValue *data, eDataType &dataType);
483 #define ADD_OP(a, b, d) void glop ## a (GLParam *p); 484 #include "graphics/tinygl/opinfo.h" 487 void gl_compile_op(
GLParam *p);
489 void gl_eval_viewport();
490 void gl_transform_to_viewport(
GLVertex *v);
501 void gl_add_select(uint zmin, uint zmax);
502 void gl_add_select1(
int z1,
int z2,
int z3);
503 void gl_enable_disable_light(
int light,
int v);
506 void gl_GetIntegerv(TGLenum pname, TGLint *data);
507 void gl_GetFloatv(TGLenum pname, TGLfloat *data);
508 void gl_GetDoublev(TGLenum pname, TGLdouble *data);
509 void gl_GetBooleanv(TGLenum pname, TGLboolean *data);
511 void gl_EnableClientState(
GLParam *p);
512 void gl_DisableClientState(
GLParam *p);
513 void gl_VertexPointer(
GLParam *p);
514 void gl_ColorPointer(
GLParam *p);
515 void gl_NormalPointer(
GLParam *p);
516 void gl_TexCoordPointer(
GLParam *p);
521 void gl_GenTextures(TGLsizei n, TGLuint *textures);
522 void gl_DeleteTextures(TGLsizei n,
const TGLuint *textures);
523 void gl_PixelStore(TGLenum pname, TGLint param);
525 void issueDrawCall(
DrawCall *drawCall);
526 void disposeResources();
527 void disposeDrawCallLists();
532 void debugDrawRectangle(
Common::Rect rect,
int r,
int g,
int b);
534 GLSpecBuf *specbuf_get_buffer(
const int shininess_i,
const float shininess);
535 void specbuf_cleanup();
537 TGLint gl_RenderMode(TGLenum mode);
538 void gl_SelectBuffer(TGLsizei size, TGLuint *buffer);
540 GLList *alloc_list(
int list);
541 GLList *find_list(uint list);
542 void delete_list(
int list);
543 void gl_NewList(TGLuint list, TGLenum mode);
545 TGLboolean gl_IsList(TGLuint list);
546 TGLuint gl_GenLists(TGLsizei range);
548 void initSharedState();
549 void endSharedState();
552 bool enableStencilBuffer,
bool dirtyRectsEnable, uint32 drawCallMemorySize);
555 void gl_print_matrix(
const float *m);
556 void gl_debug(
int mode) {
564 #define VERTEX_ARRAY 0x0001 565 #define COLOR_ARRAY 0x0002 566 #define NORMAL_ARRAY 0x0004 567 #define TEXCOORD_ARRAY 0x0008 572 #define CLIP_EPSILON (1E-5) 574 static inline int gl_clipcode(
float x,
float y,
float z,
float w1) {
577 w = (float)(w1 * (1.0 + CLIP_EPSILON));
578 return (x < -w) | ((x > w) << 1) | ((y < -w) << 2) | ((y > w) << 3) | ((z < -w) << 4) | ((z > w) << 5);
581 static inline float clampf(
float a,
float min,
float max) {
Definition: zdirtyrect.h:60
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:108
Definition: zdirtyrect.h:51