Serenity Operating System
at master 56 lines 2.1 kB view raw
1/* 2 * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com> 3 * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org> 4 * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl> 5 * Copyright (c) 2022, Ryan Bethke <ryanbethke11@gmail.com> 6 * 7 * SPDX-License-Identifier: BSD-2-Clause 8 */ 9 10#include <LibGL/GLContext.h> 11 12namespace GL { 13 14void GLContext::gl_clip_plane(GLenum plane, GLdouble const* equation) 15{ 16 APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_clip_plane, plane, equation); 17 18 RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION); 19 RETURN_WITH_ERROR_IF((plane < GL_CLIP_PLANE0) || (plane > GL_CLIP_PLANE5), GL_INVALID_ENUM); 20 21 auto plane_idx = static_cast<size_t>(plane) - GL_CLIP_PLANE0; 22 23 auto eqn = FloatVector4(equation[0], equation[1], equation[2], equation[3]); 24 m_clip_plane_attributes.eye_clip_plane[plane_idx] = model_view_matrix() * eqn; 25 m_clip_planes_dirty = true; 26} 27 28void GLContext::gl_get_clip_plane(GLenum plane, GLdouble* equation) 29{ 30 RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION); 31 RETURN_WITH_ERROR_IF((plane < GL_CLIP_PLANE0) || (plane > GL_CLIP_PLANE5), GL_INVALID_ENUM); 32 33 auto plane_idx = static_cast<size_t>(plane) - GL_CLIP_PLANE0; 34 equation[0] = static_cast<GLdouble>(m_clip_plane_attributes.eye_clip_plane[plane_idx][0]); 35 equation[1] = static_cast<GLdouble>(m_clip_plane_attributes.eye_clip_plane[plane_idx][1]); 36 equation[2] = static_cast<GLdouble>(m_clip_plane_attributes.eye_clip_plane[plane_idx][2]); 37 equation[3] = static_cast<GLdouble>(m_clip_plane_attributes.eye_clip_plane[plane_idx][3]); 38} 39 40void GLContext::sync_clip_planes() 41{ 42 if (!m_clip_planes_dirty) 43 return; 44 m_clip_planes_dirty = false; 45 46 // TODO: Replace magic number 6 with device-dependent constant 47 Vector<FloatVector4, 6> user_clip_planes; 48 for (size_t plane_idx = 0; plane_idx < 6; ++plane_idx) { 49 if ((m_clip_plane_attributes.enabled & (1 << plane_idx)) != 0u) { 50 user_clip_planes.append(m_clip_plane_attributes.eye_clip_plane[plane_idx]); 51 } 52 } 53 m_rasterizer->set_clip_planes(user_clip_planes); 54} 55 56}