Serenity Operating System
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

LibGL: Immediately dereference vertex attribute data in display lists

According to the spec, pointers to client data need to be dereferenced
immediately when adding calls such as `glDrawElements` or
`glArrayElement` to a display list. We were trying to support display
lists for these calls but since they only invoke _other_ calls that also
support display lists, we can simply defer the display list
functionality to them.

This fixes the rendering of the ClassiCube port by cflip.

authored by

Jelle Raaijmakers and committed by
Linus Groh
0cf3cb62 0ea4d228

+32 -6
+26
Tests/LibGL/TestRender.cpp
··· 252 252 context->present(); 253 253 expect_bitmap_equals_reference(context->frontbuffer(), "0008_test_pop_matrix_regression"sv); 254 254 } 255 + 256 + TEST_CASE(0009_test_draw_elements_in_display_list) 257 + { 258 + auto context = create_testing_context(64, 64); 259 + 260 + glColor3f(0.f, 0.f, 1.f); 261 + glEnableClientState(GL_VERTEX_ARRAY); 262 + 263 + auto const list_index = glGenLists(1); 264 + glNewList(list_index, GL_COMPILE); 265 + float vertices[] = { 0.f, .5f, -.5f, -.5f, .5f, -.5f }; 266 + glVertexPointer(2, GL_FLOAT, 0, &vertices); 267 + u8 indices[] = { 0, 1, 2 }; 268 + glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, &indices); 269 + glEndList(); 270 + 271 + // Modifying an index here should not have an effect 272 + indices[0] = 2; 273 + 274 + glCallList(list_index); 275 + 276 + EXPECT_EQ(glGetError(), 0u); 277 + 278 + context->present(); 279 + expect_bitmap_equals_reference(context->frontbuffer(), "0009_test_draw_elements_in_display_list"sv); 280 + }
Tests/LibGL/reference-images/0009_test_draw_elements_in_display_list.qoi

This is a binary file and will not be displayed.

-3
Userland/Libraries/LibGL/GLContext.h
··· 441 441 decltype(&GLContext::gl_tex_parameter), 442 442 decltype(&GLContext::gl_tex_parameterfv), 443 443 decltype(&GLContext::gl_depth_mask), 444 - decltype(&GLContext::gl_draw_arrays), 445 - decltype(&GLContext::gl_draw_elements), 446 444 decltype(&GLContext::gl_draw_pixels), 447 445 decltype(&GLContext::gl_depth_range), 448 446 decltype(&GLContext::gl_polygon_offset), ··· 473 471 decltype(&GLContext::gl_color_material), 474 472 decltype(&GLContext::gl_get_light), 475 473 decltype(&GLContext::gl_clip_plane), 476 - decltype(&GLContext::gl_array_element), 477 474 decltype(&GLContext::gl_copy_tex_sub_image_2d), 478 475 decltype(&GLContext::gl_point_size)>; 479 476
+6 -3
Userland/Libraries/LibGL/Vertex.cpp
··· 14 14 15 15 void GLContext::gl_array_element(GLint i) 16 16 { 17 - APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_array_element, i); 17 + // NOTE: This always dereferences data; display list support is deferred to the 18 + // individual vertex attribute calls such as `gl_color`, `gl_normal` etc. 18 19 RETURN_WITH_ERROR_IF(i < 0, GL_INVALID_VALUE); 19 20 20 21 // This is effectively the same as `gl_draw_elements`, except we only output a single ··· 79 80 80 81 void GLContext::gl_draw_arrays(GLenum mode, GLint first, GLsizei count) 81 82 { 82 - APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_draw_arrays, mode, first, count); 83 + // NOTE: This always dereferences data; display list support is deferred to the 84 + // individual vertex attribute calls such as `gl_color`, `gl_normal` etc. 83 85 RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION); 84 86 85 87 // FIXME: Some modes are still missing (GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES) ··· 129 131 130 132 void GLContext::gl_draw_elements(GLenum mode, GLsizei count, GLenum type, void const* indices) 131 133 { 132 - APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_draw_elements, mode, count, type, indices); 134 + // NOTE: This always dereferences data; display list support is deferred to the 135 + // individual vertex attribute calls such as `gl_color`, `gl_normal` etc. 133 136 RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION); 134 137 135 138 // FIXME: Some modes are still missing (GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES)