GLContext.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*
  2. * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
  3. * Copyright (c) 2021-2022, Jesse Buhagiar <jooster669@gmail.com>
  4. * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/HashMap.h>
  10. #include <AK/NonnullOwnPtr.h>
  11. #include <AK/Optional.h>
  12. #include <AK/RefPtr.h>
  13. #include <AK/Tuple.h>
  14. #include <AK/Variant.h>
  15. #include <AK/Vector.h>
  16. #include <LibGL/Tex/NameAllocator.h>
  17. #include <LibGL/Tex/Texture.h>
  18. #include <LibGL/Tex/TextureUnit.h>
  19. #include <LibGPU/Device.h>
  20. #include <LibGPU/DeviceInfo.h>
  21. #include <LibGPU/Driver.h>
  22. #include <LibGPU/Light.h>
  23. #include <LibGPU/Vertex.h>
  24. #include <LibGfx/Bitmap.h>
  25. #include <LibGfx/Matrix4x4.h>
  26. #include <LibGfx/Rect.h>
  27. #include <LibGfx/Vector3.h>
  28. namespace GL {
  29. #define APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(name, ...) \
  30. if (should_append_to_listing()) { \
  31. append_to_listing<&GLContext::name>(__VA_ARGS__); \
  32. if (!should_execute_after_appending_to_listing()) \
  33. return; \
  34. }
  35. #define APPEND_TO_CALL_LIST_WITH_ARG_AND_RETURN_IF_NEEDED(name, arg) \
  36. if (should_append_to_listing()) { \
  37. auto ptr = store_in_listing(arg); \
  38. append_to_listing<&GLContext::name>(*ptr); \
  39. if (!should_execute_after_appending_to_listing()) \
  40. return; \
  41. }
  42. #define RETURN_WITH_ERROR_IF(condition, error) \
  43. if (condition) { \
  44. dbgln_if(GL_DEBUG, "{}(): error {:#x}", __func__, error); \
  45. if (m_error == GL_NO_ERROR) \
  46. m_error = error; \
  47. return; \
  48. }
  49. #define RETURN_VALUE_WITH_ERROR_IF(condition, error, return_value) \
  50. if (condition) { \
  51. dbgln_if(GL_DEBUG, "{}(): error {:#x}", __func__, error); \
  52. if (m_error == GL_NO_ERROR) \
  53. m_error = error; \
  54. return return_value; \
  55. }
  56. constexpr size_t MODELVIEW_MATRIX_STACK_LIMIT = 64;
  57. constexpr size_t PROJECTION_MATRIX_STACK_LIMIT = 8;
  58. constexpr size_t TEXTURE_MATRIX_STACK_LIMIT = 8;
  59. struct ContextParameter {
  60. GLenum type;
  61. bool is_capability { false };
  62. u8 count { 1 };
  63. union {
  64. bool boolean_value;
  65. GLint integer_value;
  66. GLint integer_list[4];
  67. GLdouble double_value;
  68. GLdouble double_list[4];
  69. } value;
  70. };
  71. enum Face {
  72. Front = 0,
  73. Back = 1,
  74. };
  75. class GLContext final {
  76. public:
  77. GLContext(RefPtr<GPU::Driver> driver, NonnullOwnPtr<GPU::Device>, Gfx::Bitmap&);
  78. ~GLContext();
  79. NonnullRefPtr<Gfx::Bitmap> frontbuffer() const { return m_frontbuffer; };
  80. void present();
  81. void gl_begin(GLenum mode);
  82. void gl_clear(GLbitfield mask);
  83. void gl_clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
  84. void gl_clear_depth(GLdouble depth);
  85. void gl_clear_stencil(GLint s);
  86. void gl_color(GLdouble r, GLdouble g, GLdouble b, GLdouble a);
  87. void gl_delete_textures(GLsizei n, GLuint const* textures);
  88. void gl_end();
  89. void gl_frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
  90. void gl_gen_textures(GLsizei n, GLuint* textures);
  91. GLenum gl_get_error();
  92. GLubyte* gl_get_string(GLenum name);
  93. void gl_load_identity();
  94. void gl_load_matrix(FloatMatrix4x4 const& matrix);
  95. void gl_matrix_mode(GLenum mode);
  96. void gl_ortho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
  97. void gl_push_matrix();
  98. void gl_pop_matrix();
  99. void gl_mult_matrix(FloatMatrix4x4 const& matrix);
  100. void gl_rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
  101. void gl_scale(GLdouble x, GLdouble y, GLdouble z);
  102. void gl_translate(GLdouble x, GLdouble y, GLdouble z);
  103. void gl_vertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w);
  104. void gl_viewport(GLint x, GLint y, GLsizei width, GLsizei height);
  105. void gl_enable(GLenum);
  106. void gl_disable(GLenum);
  107. GLboolean gl_is_enabled(GLenum);
  108. void gl_front_face(GLenum);
  109. void gl_cull_face(GLenum);
  110. GLuint gl_gen_lists(GLsizei range);
  111. void gl_call_list(GLuint list);
  112. void gl_call_lists(GLsizei n, GLenum type, void const* lists);
  113. void gl_delete_lists(GLuint list, GLsizei range);
  114. void gl_list_base(GLuint base);
  115. void gl_end_list(void);
  116. void gl_new_list(GLuint list, GLenum mode);
  117. GLboolean gl_is_list(GLuint list);
  118. void gl_flush();
  119. void gl_finish();
  120. void gl_blend_func(GLenum src_factor, GLenum dst_factor);
  121. void gl_shade_model(GLenum mode);
  122. void gl_alpha_func(GLenum func, GLclampf ref);
  123. void gl_hint(GLenum target, GLenum mode);
  124. void gl_read_buffer(GLenum mode);
  125. void gl_draw_buffer(GLenum buffer);
  126. void gl_read_pixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels);
  127. void gl_tex_image_2d(GLenum target, GLint level, GLint internal_format, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLvoid const* data);
  128. void gl_tex_sub_image_2d(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid const* data);
  129. void gl_tex_parameter(GLenum target, GLenum pname, GLfloat param);
  130. void gl_tex_parameterfv(GLenum target, GLenum pname, GLfloat const* params);
  131. void gl_tex_coord(GLfloat s, GLfloat t, GLfloat r, GLfloat q);
  132. void gl_multi_tex_coord(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
  133. void gl_tex_env(GLenum target, GLenum pname, GLfloat param);
  134. void gl_bind_texture(GLenum target, GLuint texture);
  135. GLboolean gl_is_texture(GLuint texture);
  136. void gl_active_texture(GLenum texture);
  137. void gl_depth_mask(GLboolean flag);
  138. void gl_enable_client_state(GLenum cap);
  139. void gl_disable_client_state(GLenum cap);
  140. void gl_client_active_texture(GLenum target);
  141. void gl_vertex_pointer(GLint size, GLenum type, GLsizei stride, void const* pointer);
  142. void gl_color_pointer(GLint size, GLenum type, GLsizei stride, void const* pointer);
  143. void gl_tex_coord_pointer(GLint size, GLenum type, GLsizei stride, void const* pointer);
  144. void gl_draw_arrays(GLenum mode, GLint first, GLsizei count);
  145. void gl_draw_elements(GLenum mode, GLsizei count, GLenum type, void const* indices);
  146. void gl_draw_pixels(GLsizei width, GLsizei height, GLenum format, GLenum type, void const* data);
  147. void gl_color_mask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
  148. void gl_get_booleanv(GLenum pname, GLboolean* data);
  149. void gl_get_doublev(GLenum pname, GLdouble* params);
  150. void gl_get_floatv(GLenum pname, GLfloat* params);
  151. void gl_get_integerv(GLenum pname, GLint* data);
  152. void gl_depth_range(GLdouble min, GLdouble max);
  153. void gl_depth_func(GLenum func);
  154. void gl_polygon_mode(GLenum face, GLenum mode);
  155. void gl_polygon_offset(GLfloat factor, GLfloat units);
  156. void gl_fogfv(GLenum pname, GLfloat* params);
  157. void gl_fogf(GLenum pname, GLfloat param);
  158. void gl_fogi(GLenum pname, GLint param);
  159. void gl_pixel_storei(GLenum pname, GLint param);
  160. void gl_scissor(GLint x, GLint y, GLsizei width, GLsizei height);
  161. void gl_stencil_func_separate(GLenum face, GLenum func, GLint ref, GLuint mask);
  162. void gl_stencil_mask_separate(GLenum face, GLuint mask);
  163. void gl_stencil_op_separate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
  164. void gl_normal(GLfloat nx, GLfloat ny, GLfloat nz);
  165. void gl_normal_pointer(GLenum type, GLsizei stride, void const* pointer);
  166. void gl_raster_pos(GLfloat x, GLfloat y, GLfloat z, GLfloat w);
  167. void gl_line_width(GLfloat width);
  168. void gl_push_attrib(GLbitfield mask);
  169. void gl_pop_attrib();
  170. void gl_light_model(GLenum pname, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
  171. void gl_bitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, GLubyte const* bitmap);
  172. void gl_copy_tex_image_2d(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
  173. void gl_get_tex_parameter_integerv(GLenum target, GLint level, GLenum pname, GLint* params);
  174. void gl_rect(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2);
  175. void gl_tex_gen(GLenum coord, GLenum pname, GLint param);
  176. void gl_tex_gen_floatv(GLenum coord, GLenum pname, GLfloat const* params);
  177. void gl_lightf(GLenum light, GLenum pname, GLfloat param);
  178. void gl_lightfv(GLenum light, GLenum pname, GLfloat const* params);
  179. void gl_lightiv(GLenum light, GLenum pname, GLint const* params);
  180. void gl_materialf(GLenum face, GLenum pname, GLfloat param);
  181. void gl_materialfv(GLenum face, GLenum pname, GLfloat const* params);
  182. void gl_materialiv(GLenum face, GLenum pname, GLint const* params);
  183. void gl_color_material(GLenum face, GLenum mode);
  184. void gl_get_light(GLenum light, GLenum pname, void* params, GLenum type);
  185. void gl_get_material(GLenum face, GLenum pname, void* params, GLenum type);
  186. void gl_clip_plane(GLenum plane, GLdouble const* equation);
  187. void gl_get_clip_plane(GLenum plane, GLdouble* equation);
  188. void gl_array_element(GLint i);
  189. void gl_copy_tex_sub_image_2d(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
  190. void gl_point_size(GLfloat size);
  191. private:
  192. void sync_device_config();
  193. void sync_device_sampler_config();
  194. void sync_device_texcoord_config();
  195. void sync_light_state();
  196. void sync_stencil_configuration();
  197. void sync_clip_planes();
  198. void build_extension_string();
  199. template<typename T>
  200. T* store_in_listing(T value)
  201. {
  202. VERIFY(m_current_listing_index.has_value());
  203. auto& listing = m_current_listing_index->listing;
  204. listing.saved_arguments.empend(make<Listing::ExtraSavedArguments>(move(value)));
  205. return listing.saved_arguments.last()->template get_pointer<T>();
  206. }
  207. template<auto member, typename... Args>
  208. void append_to_listing(Args&&... args)
  209. {
  210. VERIFY(m_current_listing_index.has_value());
  211. m_current_listing_index->listing.entries.empend(member, Listing::ArgumentsFor<member> { forward<Args>(args)... });
  212. }
  213. Optional<ContextParameter> get_context_parameter(GLenum pname);
  214. template<typename T>
  215. void get_floating_point(GLenum pname, T* params);
  216. template<typename T>
  217. void get_light_param(GLenum light, GLenum pname, T* params);
  218. template<typename T>
  219. void get_material_param(Face face, GLenum pname, T* params);
  220. void invoke_list(size_t list_index);
  221. [[nodiscard]] bool should_append_to_listing() const { return m_current_listing_index.has_value(); }
  222. [[nodiscard]] bool should_execute_after_appending_to_listing() const { return m_current_listing_index.has_value() && m_current_listing_index->mode == GL_COMPILE_AND_EXECUTE; }
  223. GLenum m_current_draw_mode;
  224. GLenum m_current_matrix_mode { GL_MODELVIEW };
  225. FloatMatrix4x4 m_projection_matrix { FloatMatrix4x4::identity() };
  226. FloatMatrix4x4 m_model_view_matrix { FloatMatrix4x4::identity() };
  227. FloatMatrix4x4 m_texture_matrix { FloatMatrix4x4::identity() };
  228. FloatMatrix4x4* m_current_matrix { &m_model_view_matrix };
  229. Vector<FloatMatrix4x4> m_projection_matrix_stack;
  230. Vector<FloatMatrix4x4> m_model_view_matrix_stack;
  231. // FIXME: implement multi-texturing: the texture matrix stack should live inside a texture unit
  232. Vector<FloatMatrix4x4> m_texture_matrix_stack;
  233. Vector<FloatMatrix4x4>* m_current_matrix_stack { &m_model_view_matrix_stack };
  234. Gfx::IntRect m_viewport;
  235. FloatVector4 m_clear_color { 0.0f, 0.0f, 0.0f, 0.0f };
  236. float m_clear_depth { 1.f };
  237. u8 m_clear_stencil { 0 };
  238. FloatVector4 m_current_vertex_color { 1.0f, 1.0f, 1.0f, 1.0f };
  239. Vector<FloatVector4> m_current_vertex_tex_coord;
  240. FloatVector3 m_current_vertex_normal { 0.0f, 0.0f, 1.0f };
  241. Vector<GPU::Vertex> m_vertex_list;
  242. GLenum m_error = GL_NO_ERROR;
  243. bool m_in_draw_state = false;
  244. bool m_depth_test_enabled { false };
  245. bool m_depth_offset_enabled { false };
  246. bool m_cull_faces = false;
  247. GLenum m_front_face = GL_CCW;
  248. GLenum m_culled_sides = GL_BACK;
  249. bool m_blend_enabled = false;
  250. GLenum m_blend_source_factor = GL_ONE;
  251. GLenum m_blend_destination_factor = GL_ZERO;
  252. bool m_alpha_test_enabled = false;
  253. GLenum m_alpha_test_func = GL_ALWAYS;
  254. GLclampf m_alpha_test_ref_value = 0;
  255. bool m_dither_enabled { true };
  256. bool m_normalize { false };
  257. // Stencil configuration
  258. bool m_stencil_test_enabled { false };
  259. bool m_stencil_configuration_dirty { true };
  260. struct StencilFunctionOptions {
  261. GLenum func { GL_ALWAYS };
  262. GLint reference_value { 0 };
  263. GLuint mask { NumericLimits<GLuint>::max() };
  264. };
  265. Array<StencilFunctionOptions, 2u> m_stencil_function;
  266. struct StencilOperationOptions {
  267. GLenum op_fail { GL_KEEP };
  268. GLenum op_depth_fail { GL_KEEP };
  269. GLenum op_pass { GL_KEEP };
  270. GLuint write_mask { NumericLimits<GLuint>::max() };
  271. };
  272. Array<StencilOperationOptions, 2u> m_stencil_operation;
  273. GLenum m_current_read_buffer = GL_BACK;
  274. GLenum m_current_draw_buffer = GL_BACK;
  275. // User-defined clip planes
  276. struct ClipPlaneAttributes {
  277. Array<FloatVector4, 6> eye_clip_plane; // TODO: Change to use device-defined constant
  278. GLuint enabled { 0 };
  279. } m_clip_plane_attributes;
  280. bool m_clip_planes_dirty { true };
  281. // Client side arrays
  282. bool m_client_side_vertex_array_enabled { false };
  283. bool m_client_side_color_array_enabled { false };
  284. Vector<bool> m_client_side_texture_coord_array_enabled;
  285. size_t m_client_active_texture = 0;
  286. bool m_client_side_normal_array_enabled { false };
  287. NonnullRefPtr<Gfx::Bitmap> m_frontbuffer;
  288. // Texture objects
  289. template<typename T>
  290. RefPtr<T> get_default_texture(GLenum target)
  291. {
  292. auto default_texture = m_default_textures.get(target);
  293. VERIFY(default_texture.has_value());
  294. return static_cast<T*>(default_texture.value());
  295. }
  296. TextureNameAllocator m_name_allocator;
  297. HashMap<GLuint, RefPtr<Texture>> m_allocated_textures;
  298. HashMap<GLenum, RefPtr<Texture>> m_default_textures;
  299. Vector<TextureUnit> m_texture_units;
  300. TextureUnit* m_active_texture_unit;
  301. size_t m_active_texture_unit_index { 0 };
  302. // Texture coordinate generation state
  303. struct TextureCoordinateGeneration {
  304. bool enabled { false };
  305. GLenum generation_mode { GL_EYE_LINEAR };
  306. FloatVector4 object_plane_coefficients { 0.0f, 0.0f, 0.0f, 0.0f };
  307. FloatVector4 eye_plane_coefficients { 0.0f, 0.0f, 0.0f, 0.0f };
  308. };
  309. Vector<Array<TextureCoordinateGeneration, 4>> m_texture_coordinate_generation;
  310. bool m_texcoord_generation_dirty { true };
  311. ALWAYS_INLINE TextureCoordinateGeneration& texture_coordinate_generation(size_t texture_unit, GLenum capability)
  312. {
  313. return m_texture_coordinate_generation[texture_unit][capability - GL_TEXTURE_GEN_S];
  314. }
  315. RefPtr<GPU::Driver> m_driver;
  316. NonnullOwnPtr<GPU::Device> m_rasterizer;
  317. GPU::DeviceInfo const m_device_info;
  318. bool m_sampler_config_is_dirty { true };
  319. bool m_light_state_is_dirty { true };
  320. struct Listing {
  321. template<typename F>
  322. struct TupleTypeForArgumentListOf_;
  323. template<typename Ret, typename C, typename... Args>
  324. struct TupleTypeForArgumentListOf_<Ret (C::*)(Args...)> {
  325. using Type = Tuple<Args...>;
  326. };
  327. template<typename F>
  328. using TupleTypeForArgumentListOf = typename TupleTypeForArgumentListOf_<F>::Type;
  329. template<auto member>
  330. using ArgumentsFor = TupleTypeForArgumentListOf<decltype(member)>;
  331. template<typename... Fns>
  332. struct FunctionAndArgs {
  333. Variant<Fns...> function;
  334. Variant<TupleTypeForArgumentListOf<Fns>...> arguments;
  335. };
  336. using FunctionsAndArgs = FunctionAndArgs<
  337. decltype(&GLContext::gl_begin),
  338. decltype(&GLContext::gl_clear),
  339. decltype(&GLContext::gl_clear_color),
  340. decltype(&GLContext::gl_clear_depth),
  341. decltype(&GLContext::gl_clear_stencil),
  342. decltype(&GLContext::gl_color),
  343. decltype(&GLContext::gl_end),
  344. decltype(&GLContext::gl_frustum),
  345. decltype(&GLContext::gl_load_identity),
  346. decltype(&GLContext::gl_load_matrix),
  347. decltype(&GLContext::gl_matrix_mode),
  348. decltype(&GLContext::gl_ortho),
  349. decltype(&GLContext::gl_push_matrix),
  350. decltype(&GLContext::gl_pop_matrix),
  351. decltype(&GLContext::gl_mult_matrix),
  352. decltype(&GLContext::gl_rotate),
  353. decltype(&GLContext::gl_scale),
  354. decltype(&GLContext::gl_translate),
  355. decltype(&GLContext::gl_vertex),
  356. decltype(&GLContext::gl_viewport),
  357. decltype(&GLContext::gl_enable),
  358. decltype(&GLContext::gl_disable),
  359. decltype(&GLContext::gl_front_face),
  360. decltype(&GLContext::gl_cull_face),
  361. decltype(&GLContext::gl_call_list),
  362. decltype(&GLContext::gl_call_lists),
  363. decltype(&GLContext::gl_blend_func),
  364. decltype(&GLContext::gl_shade_model),
  365. decltype(&GLContext::gl_alpha_func),
  366. decltype(&GLContext::gl_hint),
  367. decltype(&GLContext::gl_read_buffer),
  368. decltype(&GLContext::gl_tex_parameter),
  369. decltype(&GLContext::gl_tex_parameterfv),
  370. decltype(&GLContext::gl_depth_mask),
  371. decltype(&GLContext::gl_draw_arrays),
  372. decltype(&GLContext::gl_draw_elements),
  373. decltype(&GLContext::gl_draw_pixels),
  374. decltype(&GLContext::gl_depth_range),
  375. decltype(&GLContext::gl_polygon_offset),
  376. decltype(&GLContext::gl_scissor),
  377. decltype(&GLContext::gl_stencil_func_separate),
  378. decltype(&GLContext::gl_stencil_mask_separate),
  379. decltype(&GLContext::gl_stencil_op_separate),
  380. decltype(&GLContext::gl_normal),
  381. decltype(&GLContext::gl_raster_pos),
  382. decltype(&GLContext::gl_line_width),
  383. decltype(&GLContext::gl_push_attrib),
  384. decltype(&GLContext::gl_pop_attrib),
  385. decltype(&GLContext::gl_light_model),
  386. decltype(&GLContext::gl_bitmap),
  387. decltype(&GLContext::gl_copy_tex_image_2d),
  388. decltype(&GLContext::gl_rect),
  389. decltype(&GLContext::gl_tex_gen),
  390. decltype(&GLContext::gl_tex_gen_floatv),
  391. decltype(&GLContext::gl_fogf),
  392. decltype(&GLContext::gl_fogfv),
  393. decltype(&GLContext::gl_fogi),
  394. decltype(&GLContext::gl_lightf),
  395. decltype(&GLContext::gl_lightfv),
  396. decltype(&GLContext::gl_lightiv),
  397. decltype(&GLContext::gl_materialf),
  398. decltype(&GLContext::gl_materialfv),
  399. decltype(&GLContext::gl_materialiv),
  400. decltype(&GLContext::gl_color_material),
  401. decltype(&GLContext::gl_get_light),
  402. decltype(&GLContext::gl_clip_plane),
  403. decltype(&GLContext::gl_array_element),
  404. decltype(&GLContext::gl_copy_tex_sub_image_2d),
  405. decltype(&GLContext::gl_point_size)>;
  406. using ExtraSavedArguments = Variant<
  407. FloatMatrix4x4>;
  408. Vector<NonnullOwnPtr<ExtraSavedArguments>> saved_arguments;
  409. Vector<FunctionsAndArgs> entries;
  410. };
  411. static constexpr size_t max_allowed_gl_call_depth { 128 };
  412. size_t m_gl_call_depth { 0 };
  413. Vector<Listing> m_listings;
  414. size_t m_list_base { 0 };
  415. struct CurrentListing {
  416. Listing listing;
  417. size_t index { 0 };
  418. GLenum mode { GL_COMPILE };
  419. };
  420. Optional<CurrentListing> m_current_listing_index;
  421. struct VertexAttribPointer {
  422. GLint size { 4 };
  423. GLenum type { GL_FLOAT };
  424. bool normalize { true };
  425. GLsizei stride { 0 };
  426. void const* pointer { 0 };
  427. };
  428. static void read_from_vertex_attribute_pointer(VertexAttribPointer const&, int index, float* elements);
  429. VertexAttribPointer m_client_vertex_pointer;
  430. VertexAttribPointer m_client_color_pointer;
  431. Vector<VertexAttribPointer> m_client_tex_coord_pointer;
  432. VertexAttribPointer m_client_normal_pointer;
  433. u8 m_pack_alignment { 4 };
  434. GLsizei m_unpack_row_length { 0 };
  435. u8 m_unpack_alignment { 4 };
  436. // Point drawing configuration
  437. bool m_point_smooth { false };
  438. float m_point_size { 1.f };
  439. // Line drawing configuration
  440. bool m_line_smooth { false };
  441. float m_line_width { 1.f };
  442. // Lighting configuration
  443. bool m_lighting_enabled { false };
  444. Vector<GPU::Light> m_light_states;
  445. Array<GPU::Material, 2u> m_material_states;
  446. // Color material
  447. bool m_color_material_enabled { false };
  448. GLenum m_color_material_face { GL_FRONT_AND_BACK };
  449. GLenum m_color_material_mode { GL_AMBIENT_AND_DIFFUSE };
  450. // GL Extension string
  451. String m_extensions;
  452. };
  453. NonnullOwnPtr<GLContext> create_context(Gfx::Bitmap&);
  454. void make_context_current(GLContext*);
  455. void present_context(GLContext*);
  456. }