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_flag;
220 #define _BIND_FLAG_BIT_gl_array_buffer_binding FLAG_BIT_0
221 #define _BIND_FLAG_BIT_gl_copy_read_buffer_binding FLAG_BIT_1
222 #define _BIND_FLAG_BIT_gl_copy_write_buffer_binding FLAG_BIT_1
223 #define _BIND_FLAG_BIT_gl_element_array_buffer_binding FLAG_BIT_1
224 #define _BIND_FLAG_BIT_gl_pixel_pack_buffer_binding FLAG_BIT_1
225 #define _BIND_FLAG_BIT_gl_pixel_unpack_buffer_binding FLAG_BIT_1
226 #define _BIND_FLAG_BIT_gl_transform_feedback_buffer_binding FLAG_BIT_1
227 #define _BIND_FLAG_BIT_gl_uniform_buffer_binding FLAG_BIT_1
228 #define _BIND_FLAG_BIT_gl_framebuffer_binding FLAG_BIT_2
229 #define _BIND_FLAG_BIT_gl_renderbuffer_binding FLAG_BIT_3
230 #define _BIND_FLAG_BIT_gl_framebuffer_binding_read FLAG_BIT_4
231 #define _BIND_FLAG_BIT_gl_framebuffer_binding_draw FLAG_BIT_5
233 unsigned char _enable_flag1;
234 #define _ENABLE_FLAG1_BIT_gl_blend FLAG_BIT_0
235 #define _ENABLE_FLAG1_BIT_gl_cull_face FLAG_BIT_1
236 #define _ENABLE_FLAG1_BIT_gl_depth_test FLAG_BIT_2
237 #define _ENABLE_FLAG1_BIT_gl_dither FLAG_BIT_3
239 unsigned char _enable_flag2;
240 #define _ENABLE_FLAG2_BIT_gl_polygon_offset_fill FLAG_BIT_0
241 #define _ENABLE_FLAG2_BIT_gl_sample_alpha_to_coverage FLAG_BIT_1
242 #define _ENABLE_FLAG2_BIT_gl_sample_coverage FLAG_BIT_2
243 #define _ENABLE_FLAG2_BIT_gl_scissor_test FLAG_BIT_3
244 #define _ENABLE_FLAG2_BIT_gl_stencil_test FLAG_BIT_4
246 unsigned char _enable_flag3;
247 #define _ENABLE_FLAG3_BIT_gl_primitive_restart_fixed_index FLAG_BIT_0
248 #define _ENABLE_FLAG3_BIT_gl_rasterizer_discard FLAG_BIT_1
250 unsigned char _clear_flag1;
251 #define _CLEAR_FLAG1_BIT_gl_viewport FLAG_BIT_0
252 #define _CLEAR_FLAG1_BIT_gl_current_program FLAG_BIT_1
253 #define _CLEAR_FLAG1_BIT_gl_color_clear_value FLAG_BIT_2
255 unsigned char _clear_flag2;
256 #define _CLEAR_FLAG2_BIT_gl_color_writemask FLAG_BIT_0
257 #define _CLEAR_FLAG2_BIT_gl_depth_range FLAG_BIT_1
258 #define _CLEAR_FLAG2_BIT_gl_depth_clear_value FLAG_BIT_2
259 #define _CLEAR_FLAG2_BIT_gl_depth_func FLAG_BIT_3
260 #define _CLEAR_FLAG2_BIT_gl_depth_writemask FLAG_BIT_4
261 #define _CLEAR_FLAG2_BIT_gl_cull_face_mode FLAG_BIT_5
263 unsigned char _tex_flag1;
264 #define _TEX_FLAG1_BIT_gl_active_texture FLAG_BIT_0
265 #define _TEX_FLAG1_BIT_gl_generate_mipmap_hint FLAG_BIT_1
266 #define _TEX_FLAG1_BIT_gl_tex_2d_state FLAG_BIT_2
267 #define _TEX_FLAG1_BIT_gl_tex_3d_state FLAG_BIT_3
268 #define _TEX_FLAG1_BIT_gl_tex_2d_array_state FLAG_BIT_4
269 #define _TEX_FLAG1_BIT_gl_tex_cube_state FLAG_BIT_5
271 unsigned char _blend_flag;
272 #define _BLEND_FLAG_BIT_gl_blend_color FLAG_BIT_0
273 #define _BLEND_FLAG_BIT_gl_blend_src_rgb FLAG_BIT_1
274 #define _BLEND_FLAG_BIT_gl_blend_src_alpha FLAG_BIT_2
275 #define _BLEND_FLAG_BIT_gl_blend_dst_rgb FLAG_BIT_3
276 #define _BLEND_FLAG_BIT_gl_blend_dst_alpha FLAG_BIT_4
277 #define _BLEND_FLAG_BIT_gl_blend_equation_rgb FLAG_BIT_5
278 #define _BLEND_FLAG_BIT_gl_blend_equation_alpha FLAG_BIT_6
280 unsigned char _stencil_flag1;
281 #define _STENCIL_FLAG1_BIT_gl_stencil_func FLAG_BIT_0
282 #define _STENCIL_FLAG1_BIT_gl_stencil_ref FLAG_BIT_1
283 #define _STENCIL_FLAG1_BIT_gl_stencil_value_mask FLAG_BIT_2
284 #define _STENCIL_FLAG1_BIT_gl_stencil_fail FLAG_BIT_3
285 #define _STENCIL_FLAG1_BIT_gl_stencil_pass_depth_fail FLAG_BIT_4
286 #define _STENCIL_FLAG1_BIT_gl_stencil_pass_depth_pass FLAG_BIT_5
287 #define _STENCIL_FLAG1_BIT_gl_stencil_writemask FLAG_BIT_6
289 unsigned char _stencil_flag2;
290 #define _STENCIL_FLAG2_BIT_gl_stencil_back_func FLAG_BIT_0
291 #define _STENCIL_FLAG2_BIT_gl_stencil_back_ref FLAG_BIT_1
292 #define _STENCIL_FLAG2_BIT_gl_stencil_back_value_mask FLAG_BIT_2
293 #define _STENCIL_FLAG2_BIT_gl_stencil_back_fail FLAG_BIT_3
294 #define _STENCIL_FLAG2_BIT_gl_stencil_back_pass_depth_fail FLAG_BIT_4
295 #define _STENCIL_FLAG2_BIT_gl_stencil_back_pass_depth_pass FLAG_BIT_5
296 #define _STENCIL_FLAG2_BIT_gl_stencil_back_writemask FLAG_BIT_6
297 #define _STENCIL_FLAG2_BIT_gl_stencil_clear_value FLAG_BIT_7
299 unsigned char _pixel_flag1;
300 #define _PIXEL_FLAG1_BIT_gl_pack_row_length FLAG_BIT_0
301 #define _PIXEL_FLAG1_BIT_gl_pack_skip_rows FLAG_BIT_1
302 #define _PIXEL_FLAG1_BIT_gl_pack_skip_pixels FLAG_BIT_2
303 #define _PIXEL_FLAG1_BIT_gl_pack_alignment FLAG_BIT_3
305 unsigned char _pixel_flag2;
306 #define _PIXEL_FLAG2_BIT_gl_unpack_row_length FLAG_BIT_0
307 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_rows FLAG_BIT_1
308 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_pixels FLAG_BIT_2
309 #define _PIXEL_FLAG2_BIT_gl_unpack_alignment FLAG_BIT_3
310 #define _PIXEL_FLAG2_BIT_gl_unpack_image_height FLAG_BIT_4
311 #define _PIXEL_FLAG2_BIT_gl_unpack_skip_images FLAG_BIT_5
313 unsigned char _misc_flag1;
314 #define _MISC_FLAG1_BIT_gl_front_face FLAG_BIT_0
315 #define _MISC_FLAG1_BIT_gl_line_width FLAG_BIT_1
316 #define _MISC_FLAG1_BIT_gl_polygon_offset_factor FLAG_BIT_2
317 #define _MISC_FLAG1_BIT_gl_polygon_offset_units FLAG_BIT_3
318 #define _MISC_FLAG1_BIT_gl_sample_coverage_value FLAG_BIT_4
319 #define _MISC_FLAG1_BIT_gl_sample_coverage_invert FLAG_BIT_5
320 #define _MISC_FLAG1_BIT_gl_fragment_shader_derivative_hint FLAG_BIT_6
322 unsigned char _misc_flag2;
323 #define _MISC_FLAG2_BIT_gl_scissor_box FLAG_BIT_0
325 unsigned char _misc_flag3;
326 #define _MISC_FLAG3_BIT_gl_read_buffer FLAG_BIT_0
327 #define _MISC_FLAG3_BIT_gl_draw_buffers FLAG_BIT_1
328 #define _MISC_FLAG3_BIT_gl_vertex_array_binding FLAG_BIT_2
329 #define _MISC_FLAG3_BIT_gl_transform_feedback_binding FLAG_BIT_3
330 #define _MISC_FLAG3_BIT_gl_transform_feedback FLAG_BIT_4
332 unsigned char _vattrib_flag;
333 #define _VATTRIB_FLAG_BIT_gl_vertex_attrib_value FLAG_BIT_0
334 #define _VATTRIB_FLAG_BIT_gl_vertex_array FLAG_BIT_1
336 GL_Object_State ostate;
341 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) TYPE NAME[ARRAY_SIZE];
342 # include "coregl_fastpath_state.h"
344 #define GLUE_STATE(TYPE, NAME, SIZE, ARRAY_SIZE, DEFAULT_STMT, GET_STMT) unsigned char NAME##_used;
345 # include "coregl_fastpath_state.h"
350 typedef struct _GLGlueContext_List
353 struct _GLGlueContext_List *prev;
354 struct _GLGlueContext_List *next;
355 } GLGlueContext_List;
357 extern GLGlueContext_List *gctx_list;
359 extern GLGlueContext *initial_ctx;
361 extern void init_modules_fastpath();
362 extern void deinit_modules_fastpath();
363 extern void init_modules_tstate_fastpath(GLThreadState *tstate);
364 extern void deinit_modules_tstate_fastpath(GLThreadState *tstate);
366 extern void fastpath_apply_overrides();
367 extern void fastpath_apply_overrides_egl(int enable);
368 extern void fastpath_apply_overrides_gl(int enable);
370 extern int fastpath_init_context_states(GLGlueContext *ctx);
371 extern int fastpath_make_context_current(GLGlueContext *oldctx, GLGlueContext *newctx);
373 #ifdef COREGL_FASTPATH_TRACE_STATE_INFO
374 extern void fastpath_dump_context_states(GLGlueContext *ctx, int force_output);
375 #endif // COREGL_FASTPATH_TRACE_STATE_INFO
377 // Context state functions
378 extern int fastpath_add_context_state_to_list(const void *data, const int datalen, GLContextState *cstate, Mutex *mtx);
379 extern int fastpath_remove_context_states_from_list(GLContextState *cstate, Mutex *mtx);
380 extern GLContextState *fastpath_get_context_state_from_list(const void *data, const int datalen, Mutex *mtx);
382 // Shared object state functions
383 extern void fastpath_ostate_init(GL_Object_State *ostate);
384 extern void fastpath_sostate_init(GL_Shared_Object_State *ostate);
385 extern void fastpath_ostate_deinit(GL_Object_State *ostate);
386 extern void fastpath_sostate_deinit(GL_Shared_Object_State *ostate);
387 extern GLuint fastpath_ostate_create_object(GL_Object_State *ostate, GL_Object_Type type, GLuint name);
388 extern GLuint fastpath_ostate_remove_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
389 extern GLuint fastpath_ostate_get_object(GL_Object_State *ostate, GL_Object_Type type, GLuint name);
390 extern GLuint fastpath_ostate_find_object(GL_Object_State *ostate, GL_Object_Type type, GLuint real_name);
391 extern GLint fastpath_ostate_use_object(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
392 extern GLint fastpath_ostate_set_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name, GLvoid *tag);
393 extern GLvoid *fastpath_ostate_get_object_tag(GL_Object_State *ostate, GL_Object_Type type, GLuint glue_name);
395 // GL context management functions
396 extern void fastpath_release_gl_context(GLGlueContext *gctx);
398 // State query functions
399 extern void fastpath_state_get_draw_buffers(GLenum *params);
401 #endif // COREGL_FASTPATH_H