1 #ifndef COREGL_FASTPATH_H
2 #define COREGL_FASTPATH_H
4 #include "../coregl_module.h"
6 #ifndef COREGL_USE_MODULE_FASTPATH
7 #error "COREGL_USE_MODULE_FASTPATH must defined!!!"
10 #define MY_MODULE_ID COREGL_MODULE_FASTPATH
11 #define MY_MODULE_TSTATE Fastpath_ThreadState
13 #include "../../coregl_internal.h"
14 #include "../../coregl_export.h"
16 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) extern RET_TYPE (*_orig_fastpath_##FUNC_NAME) PARAM_LIST;
17 # include "../../headers/sym.h"
20 // Symbol definition for fastpath
21 #define _COREGL_SYMBOL(RET_TYPE, FUNC_NAME, PARAM_LIST) extern RET_TYPE (fastpath_##FUNC_NAME) PARAM_LIST;
22 # include "../../headers/sym.h"
25 #define COREGL_FASTPATH_TRACE_ALL
27 #ifdef COREGL_FASTPATH_TRACE_ALL
28 #define COREGL_FASTPATH_TRACE_CONTEXT_INFO // Context state & thread state & Glue-context info
29 #define COREGL_FASTPATH_TRACE_STATE_INFO // Glue-context state info
33 #define _COREGL_FASTPATH_FUNC_BEGIN()
35 #define _COREGL_FASTPATH_FUNC_END()
38 #define FLAG_BIT_0 0x01
39 #define FLAG_BIT_1 0x02
40 #define FLAG_BIT_2 0x04
41 #define FLAG_BIT_3 0x08
42 #define FLAG_BIT_4 0x10
43 #define FLAG_BIT_5 0x20
44 #define FLAG_BIT_6 0x40
45 #define FLAG_BIT_7 0x80
47 #define MAX_TEXTURE_UNITS 32
48 #define MAX_VERTEX_ATTRIBS 64
49 #define MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 64
50 #define MAX_UNIFORM_BUFFER_BINDINGS 64
52 typedef enum _Fastpath_Opt_Flag
59 extern Fastpath_Opt_Flag fp_opt;
60 extern int debug_nofp;
62 typedef struct _GLContextState
70 typedef struct _Fastpath_ThreadState
73 GLContextState *cstate;
74 GLSurface *rsurf_draw;
75 GLSurface *rsurf_read;
76 } Fastpath_ThreadState;
78 typedef struct _GLContext_List
83 GLContextState *cstate;
84 struct _GLContext_List *next;
87 extern GLContext_List *glctx_list;
89 extern Mutex ctx_list_access_mutex;
103 GLboolean normalized;
106 } GL_Vertex_Array_State;
115 #define MAGIC_GLFAST 0x73777770
116 #define GL_OBJECT_HASH_BASE (1 << 10)
118 #define GL_OBJECT_ID_LIMIT 0xFFFFFF
120 #define GL_Object_Type int
121 #define GL_OBJECT_TYPE_QUERY 0x0
122 #define GL_OBJECT_TYPE_TEXTURE 0x1000000
123 #define GL_OBJECT_TYPE_BUFFER 0x2000000
124 #define GL_OBJECT_TYPE_FRAMEBUFFER 0x3000000
125 #define GL_OBJECT_TYPE_RENDERBUFFER 0x4000000
126 #define GL_OBJECT_TYPE_PROGRAM 0x5000000
127 #define GL_OBJECT_TYPE_VERTEXARRAY 0x6000000
128 #define GL_OBJECT_TYPE_SAMPLER 0x7000000
129 #define GL_OBJECT_TYPE_TRANSFORMFEEDBACK 0x8000000
130 #define GL_OBJECT_TYPE_UNKNOWN 0xFFFFFFF
132 typedef struct _GL_Object
139 struct _GL_Shared_Object_State *parent;
142 typedef struct _GL_Object_Hash
146 struct _GL_Object_Hash *next;
149 typedef struct _GL_Object_Hash_Base
155 GL_Object_Hash **hash_field;
156 } GL_Object_Hash_Base;
158 typedef struct _GL_Shared_Object_State
161 Mutex real_access_mutex;
163 General_Trace_List *using_gctxs;
165 GL_Object_Hash_Base texture;
166 GL_Object_Hash_Base buffer;
167 GL_Object_Hash_Base renderbuffer;
168 GL_Object_Hash_Base program;
169 GL_Object_Hash_Base sampler;
171 GL_Object_Hash_Base texture_real;
172 GL_Object_Hash_Base buffer_real;
173 GL_Object_Hash_Base renderbuffer_real;
174 GL_Object_Hash_Base program_real;
175 GL_Object_Hash_Base sampler_real;
176 } GL_Shared_Object_State;
178 typedef struct _GL_Object_State
180 GL_Shared_Object_State *shared;
182 GL_Object_Hash_Base query;
183 GL_Object_Hash_Base framebuffer;
184 GL_Object_Hash_Base vertexarray;
185 GL_Object_Hash_Base transformfeedback;
187 GL_Object_Hash_Base query_real;
188 GL_Object_Hash_Base framebuffer_real;
189 GL_Object_Hash_Base vertexarray_real;
190 GL_Object_Hash_Base transformfeedback_real;
193 typedef struct _GLGlueContext
197 int surface_attached;
207 GLContextState *cstate;
210 void *real_ctx_option;
211 int real_ctx_option_len;
213 void *real_ctx_sharable_option;
214 int real_ctx_sharable_option_len;
219 unsigned char _bind_flag1;
220 #define _BIND_FLAG1_BIT_gl_array_buffer_binding FLAG_BIT_0
221 #define _BIND_FLAG1_BIT_gl_element_array_buffer_binding FLAG_BIT_1
222 #define _BIND_FLAG1_BIT_gl_framebuffer_binding FLAG_BIT_2
223 #define _BIND_FLAG1_BIT_gl_renderbuffer_binding FLAG_BIT_3
224 #define _BIND_FLAG1_BIT_gl_framebuffer_binding_read FLAG_BIT_4
225 #define _BIND_FLAG1_BIT_gl_framebuffer_binding_draw FLAG_BIT_5
227 unsigned char _bind_flag2;
228 #define _BIND_FLAG2_BIT_gl_copy_read_buffer_binding FLAG_BIT_0
229 #define _BIND_FLAG2_BIT_gl_copy_write_buffer_binding FLAG_BIT_1
230 #define _BIND_FLAG2_BIT_gl_pixel_pack_buffer_binding FLAG_BIT_2
231 #define _BIND_FLAG2_BIT_gl_pixel_unpack_buffer_binding FLAG_BIT_3
232 #define _BIND_FLAG2_BIT_gl_transform_feedback_buffer_binding FLAG_BIT_4
233 #define _BIND_FLAG2_BIT_gl_uniform_buffer_binding FLAG_BIT_5
235 unsigned char _enable_flag1;
236 #define _ENABLE_FLAG1_BIT_gl_blend FLAG_BIT_0
237 #define _ENABLE_FLAG1_BIT_gl_cull_face FLAG_BIT_1
238 #define _ENABLE_FLAG1_BIT_gl_depth_test FLAG_BIT_2
239 #define _ENABLE_FLAG1_BIT_gl_dither FLAG_BIT_3
241 unsigned char _enable_flag2;
242 #define _ENABLE_FLAG2_BIT_gl_polygon_offset_fill FLAG_BIT_0
243 #define _ENABLE_FLAG2_BIT_gl_sample_alpha_to_coverage FLAG_BIT_1
244 #define _ENABLE_FLAG2_BIT_gl_sample_coverage FLAG_BIT_2
245 #define _ENABLE_FLAG2_BIT_gl_scissor_test FLAG_BIT_3
246 #define _ENABLE_FLAG2_BIT_gl_stencil_test FLAG_BIT_4
248 unsigned char _enable_flag3;
249 #define _ENABLE_FLAG3_BIT_gl_primitive_restart_fixed_index FLAG_BIT_0
250 #define _ENABLE_FLAG3_BIT_gl_rasterizer_discard FLAG_BIT_1
252 unsigned char _clear_flag1;
253 #define _CLEAR_FLAG1_BIT_gl_viewport FLAG_BIT_0
254 #define _CLEAR_FLAG1_BIT_gl_current_program FLAG_BIT_1
255 #define _CLEAR_FLAG1_BIT_gl_color_clear_value FLAG_BIT_2
257 unsigned char _clear_flag2;
258 #define _CLEAR_FLAG2_BIT_gl_color_writemask FLAG_BIT_0
259 #define _CLEAR_FLAG2_BIT_gl_depth_range FLAG_BIT_1
260 #define _CLEAR_FLAG2_BIT_gl_depth_clear_value FLAG_BIT_2
261 #define _CLEAR_FLAG2_BIT_gl_depth_func FLAG_BIT_3
262 #define _CLEAR_FLAG2_BIT_gl_depth_writemask FLAG_BIT_4
263 #define _CLEAR_FLAG2_BIT_gl_cull_face_mode FLAG_BIT_5
265 unsigned char _tex_flag1;
266 #define _TEX_FLAG1_BIT_gl_active_texture FLAG_BIT_0
267 #define _TEX_FLAG1_BIT_gl_generate_mipmap_hint FLAG_BIT_1
268 #define _TEX_FLAG1_BIT_gl_tex_2d_state FLAG_BIT_2
269 #define _TEX_FLAG1_BIT_gl_tex_3d_state FLAG_BIT_3
270 #define _TEX_FLAG1_BIT_gl_tex_2d_array_state FLAG_BIT_4
271 #define _TEX_FLAG1_BIT_gl_tex_cube_state FLAG_BIT_5
272 #define _TEX_FLAG1_BIT_gl_tex_external_oes_state FLAG_BIT_6
274 unsigned char _blend_flag;
275 #define _BLEND_FLAG_BIT_gl_blend_color FLAG_BIT_0
276 #define _BLEND_FLAG_BIT_gl_blend_src_rgb FLAG_BIT_1
277 #define _BLEND_FLAG_BIT_gl_blend_src_alpha FLAG_BIT_2
278 #define _BLEND_FLAG_BIT_gl_blend_dst_rgb FLAG_BIT_3
279 #define _BLEND_FLAG_BIT_gl_blend_dst_alpha FLAG_BIT_4
280 #define _BLEND_FLAG_BIT_gl_blend_equation_rgb FLAG_BIT_5
281 #define _BLEND_FLAG_BIT_gl_blend_equation_alpha FLAG_BIT_6
283 unsigned char _stencil_flag1;
284 #define _STENCIL_FLAG1_BIT_gl_stencil_func FLAG_BIT_0
285 #define _STENCIL_FLAG1_BIT_gl_stencil_ref FLAG_BIT_1
286 #define _STENCIL_FLAG1_BIT_gl_stencil_value_mask FLAG_BIT_2
287 #define _STENCIL_FLAG1_BIT_gl_stencil_fail FLAG_BIT_3
288 #define _STENCIL_FLAG1_BIT_gl_stencil_pass_depth_fail FLAG_BIT_4
289 #define _STENCIL_FLAG1_BIT_gl_stencil_pass_depth_pass FLAG_BIT_5
290 #define _STENCIL_FLAG1_BIT_gl_stencil_writemask FLAG_BIT_6
292 unsigned char _stencil_flag2;
293 #define _STENCIL_FLAG2_BIT_gl_stencil_back_func FLAG_BIT_0
294 #define _STENCIL_FLAG2_BIT_gl_stencil_back_ref FLAG_BIT_1
295 #define _STENCIL_FLAG2_BIT_gl_stencil_back_value_mask FLAG_BIT_2
296 #define _STENCIL_FLAG2_BIT_gl_stencil_back_fail FLAG_BIT_3
297 #define _STENCIL_FLAG2_BIT_gl_stencil_back_pass_depth_fail FLAG_BIT_4
298 #define _STENCIL_FLAG2_BIT_gl_stencil_back_pass_depth_pass FLAG_BIT_5
299 #define _STENCIL_FLAG2_BIT_gl_stencil_back_writemask FLAG_BIT_6
300 #define _STENCIL_FLAG2_BIT_gl_stencil_clear_value FLAG_BIT_7
302 unsigned char _pixel_flag1;
303 #define _PIXEL_FLAG1_BIT_gl_pack_row_length FLAG_BIT_0
304 #define _PIXEL_FLAG1_BIT_gl_pack_skip_rows FLAG_BIT_1
305 #define _PIXEL_FLAG1_BIT_gl_pack_skip_pixels FLAG_BIT_2
306 #define _PIXEL_FLAG1_BIT_gl_pack_alignment FLAG_BIT_3
308 unsigned char _pixel_flag2;
309 #define _PIXEL_FLAG2_BIT_gl_unpack_row_length FLAG_BIT_0
310 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_rows FLAG_BIT_1
311 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_pixels FLAG_BIT_2
312 #define _PIXEL_FLAG2_BIT_gl_unpack_alignment FLAG_BIT_3
313 #define _PIXEL_FLAG2_BIT_gl_unpack_image_height FLAG_BIT_4
314 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_images FLAG_BIT_5
316 unsigned char _misc_flag1;
317 #define _MISC_FLAG1_BIT_gl_front_face FLAG_BIT_0
318 #define _MISC_FLAG1_BIT_gl_line_width FLAG_BIT_1
319 #define _MISC_FLAG1_BIT_gl_polygon_offset_factor FLAG_BIT_2
320 #define _MISC_FLAG1_BIT_gl_polygon_offset_units FLAG_BIT_3
321 #define _MISC_FLAG1_BIT_gl_sample_coverage_value FLAG_BIT_4
322 #define _MISC_FLAG1_BIT_gl_sample_coverage_invert FLAG_BIT_5
323 #define _MISC_FLAG1_BIT_gl_fragment_shader_derivative_hint FLAG_BIT_6
325 unsigned char _misc_flag2;
326 #define _MISC_FLAG2_BIT_gl_scissor_box FLAG_BIT_0
328 unsigned char _misc_flag3;
329 #define _MISC_FLAG3_BIT_gl_read_buffer FLAG_BIT_0
330 #define _MISC_FLAG3_BIT_gl_draw_buffers FLAG_BIT_1
331 #define _MISC_FLAG3_BIT_gl_vertex_array_binding FLAG_BIT_2
332 #define _MISC_FLAG3_BIT_gl_transform_feedback_binding FLAG_BIT_3
333 #define _MISC_FLAG3_BIT_gl_transform_feedback FLAG_BIT_4
335 unsigned char _vattrib_flag;
336 #define _VATTRIB_FLAG_BIT_gl_vertex_attrib_value FLAG_BIT_0
337 #define _VATTRIB_FLAG_BIT_gl_vertex_array FLAG_BIT_1
339 GL_Object_State ostate;
344 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) TYPE NAME[ARRAY_SIZE];
345 # include "coregl_fastpath_state.h"
347 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) unsigned char NAME##_used;
348 # include "coregl_fastpath_state.h"
353 typedef struct _GLGlueContext_List
356 struct _GLGlueContext_List *prev;
357 struct _GLGlueContext_List *next;
358 } GLGlueContext_List;
360 extern GLGlueContext_List *gctx_list;
362 extern GLGlueContext *initial_ctx;
364 extern void init_modules_fastpath();
365 extern void deinit_modules_fastpath();
366 extern void init_modules_tstate_fastpath(GLThreadState *tstate);
367 extern void deinit_modules_tstate_fastpath(GLThreadState *tstate);
369 extern void fastpath_apply_overrides();
370 extern void fastpath_apply_overrides_egl(int enable);
371 extern void fastpath_apply_overrides_gl(int enable);
373 extern int fastpath_init_context_states(GLGlueContext *ctx);
374 extern int fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx);
376 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
377 extern void fastpath_dump_context_states(GLGlueContext *ctx, int force_output);
378 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
380 // Context state functions
381 extern int fastpath_add_context_state_to_list(const void *data, const int datalen, GLContextState *cstate, Mutex *mtx);
382 extern int fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx);
383 extern GLContextState *fastpath_get_context_state_from_list(const void *data, const int datalen, Mutex *mtx);
385 // Shared object state functions
386 extern void fastpath_ostate_init(GL_Object_State *ostate);
387 extern void fastpath_sostate_init(GL_Shared_Object_State *ostate);
388 extern void fastpath_ostate_deinit(GL_Object_State *ostate);
389 extern void fastpath_sostate_deinit(GL_Shared_Object_State *ostate);
390 extern GLuint fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type, GLuint name);
391 extern GLuint fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
392 extern GLuint fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type, GLuint name);
393 extern GLuint fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type, GLuint real_name);
394 extern GLint fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
395 extern GLint fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name, GLvoid *tag);
396 extern GLvoid *fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
398 // GL context management functions
399 extern void fastpath_release_gl_context(GLGlueContext *gctx);
401 // State query functions
402 extern void fastpath_state_get_draw_buffers(GLenum *params);
404 #endif // COREGL_FASTPATH_H