diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2021-08-31 20:23:29 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-09-02 21:00:24 +0430 |
commit | 7cbaaf8366d1baa824392c63bb9a92d3ff5842ae (patch) | |
tree | 28b49d52c8c9ee2a07010981c037226754aa914c /Userland/Libraries/LibGL | |
parent | b069c1306c132b72609160fb1011a58b17135136 (diff) | |
download | serenity-7cbaaf8366d1baa824392c63bb9a92d3ff5842ae.zip |
LibGL: Implement glDrawBuffer
Diffstat (limited to 'Userland/Libraries/LibGL')
-rw-r--r-- | Userland/Libraries/LibGL/GL/gl.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLUtils.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.cpp | 40 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareRasterizer.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareRasterizer.h | 1 |
7 files changed, 52 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index a1acd0c044..5f88037f27 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -25,6 +25,7 @@ extern "C" { // OpenGL related `defines` #define GL_TRUE 1 #define GL_FALSE 0 +#define GL_NONE 0 // Matrix Modes #define GL_MODELVIEW 0x0050 @@ -352,6 +353,7 @@ GLAPI void glShadeModel(GLenum mode); GLAPI void glAlphaFunc(GLenum func, GLclampf ref); GLAPI void glHint(GLenum target, GLenum mode); GLAPI void glReadBuffer(GLenum mode); +GLAPI void glDrawBuffer(GLenum buffer); GLAPI void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels); GLAPI void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* data); GLAPI void glTexCoord2f(GLfloat s, GLfloat t); diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index 6dd6f37a16..c5f3d28679 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -56,6 +56,7 @@ public: virtual void gl_alpha_func(GLenum func, GLclampf ref) = 0; virtual void gl_hint(GLenum target, GLenum mode) = 0; virtual void gl_read_buffer(GLenum mode) = 0; + virtual void gl_draw_buffer(GLenum buffer) = 0; virtual void gl_read_pixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels) = 0; virtual void gl_tex_image_2d(GLenum target, GLint level, GLint internal_format, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* data) = 0; virtual void gl_tex_parameter(GLenum target, GLenum pname, GLfloat param) = 0; diff --git a/Userland/Libraries/LibGL/GLUtils.cpp b/Userland/Libraries/LibGL/GLUtils.cpp index 0722dfa072..7098a47b5c 100644 --- a/Userland/Libraries/LibGL/GLUtils.cpp +++ b/Userland/Libraries/LibGL/GLUtils.cpp @@ -85,6 +85,11 @@ void glReadBuffer(GLenum mode) g_gl_context->gl_read_buffer(mode); } +void glDrawBuffer(GLenum buffer) +{ + g_gl_context->gl_draw_buffer(buffer); +} + void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels) { g_gl_context->gl_read_pixels(x, y, width, height, format, type, pixels); diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index e068bb0edd..920ca5ea9a 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -960,6 +960,46 @@ void SoftwareGLContext::gl_read_buffer(GLenum mode) m_current_read_buffer = mode; } +void SoftwareGLContext::gl_draw_buffer(GLenum buffer) +{ + APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_draw_buffer, buffer); + + RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION); + + // FIXME: Also allow aux buffers GL_AUX0 through GL_AUX3 here + // plus any aux buffer between 0 and GL_AUX_BUFFERS + RETURN_WITH_ERROR_IF(buffer != GL_NONE + && buffer != GL_FRONT_LEFT + && buffer != GL_FRONT_RIGHT + && buffer != GL_BACK_LEFT + && buffer != GL_BACK_RIGHT + && buffer != GL_FRONT + && buffer != GL_BACK + && buffer != GL_LEFT + && buffer != GL_RIGHT, + GL_INVALID_ENUM); + + // FIXME: We do not currently have aux buffers, so make it an invalid + // operation to select anything but front or back buffers. Also we do + // not allow selecting the stereoscopic RIGHT buffers since we do not + // have them configured. + RETURN_WITH_ERROR_IF(buffer != GL_NONE + && buffer != GL_FRONT_LEFT + && buffer != GL_FRONT + && buffer != GL_BACK_LEFT + && buffer != GL_BACK + && buffer != GL_FRONT + && buffer != GL_BACK + && buffer != GL_LEFT, + GL_INVALID_OPERATION); + + m_current_draw_buffer = buffer; + + auto rasterizer_options = m_rasterizer.options(); + rasterizer_options.draw_buffer = m_current_draw_buffer; + m_rasterizer.set_options(rasterizer_options); +} + void SoftwareGLContext::gl_read_pixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels) { RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION); diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index 92fa1242f8..cb026ac363 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -66,6 +66,7 @@ public: virtual void gl_alpha_func(GLenum func, GLclampf ref) override; virtual void gl_hint(GLenum target, GLenum mode) override; virtual void gl_read_buffer(GLenum mode) override; + virtual void gl_draw_buffer(GLenum buffer) override; virtual void gl_read_pixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels) override; virtual void gl_tex_image_2d(GLenum target, GLint level, GLint internal_format, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* data) override; virtual void gl_tex_parameter(GLenum target, GLenum pname, GLfloat param) override; @@ -152,6 +153,7 @@ private: GLclampf m_alpha_test_ref_value = 0; GLenum m_current_read_buffer = GL_BACK; + GLenum m_current_draw_buffer = GL_BACK; // Client side arrays bool m_client_side_vertex_array_enabled = false; diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp index 9c5341f517..3b968196bd 100644 --- a/Userland/Libraries/LibGL/SoftwareRasterizer.cpp +++ b/Userland/Libraries/LibGL/SoftwareRasterizer.cpp @@ -334,7 +334,7 @@ static void rasterize_triangle(const RasterizerOptions& options, Gfx::Bitmap& re } // We will not update the color buffer at all - if (!options.color_mask) + if (!options.color_mask || options.draw_buffer == GL_NONE) continue; // Draw the pixels according to the previously generated mask diff --git a/Userland/Libraries/LibGL/SoftwareRasterizer.h b/Userland/Libraries/LibGL/SoftwareRasterizer.h index 8a1a8d8166..8d178116ff 100644 --- a/Userland/Libraries/LibGL/SoftwareRasterizer.h +++ b/Userland/Libraries/LibGL/SoftwareRasterizer.h @@ -44,6 +44,7 @@ struct RasterizerOptions { GLboolean fog_enabled { false }; GLfloat fog_start { 0.0f }; GLfloat fog_end { 1.0f }; + GLenum draw_buffer { GL_BACK }; }; class SoftwareRasterizer final { |