diff options
author | Stephan Unverwerth <s.unverwerth@gmx.de> | 2021-05-15 22:45:05 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-16 00:44:31 +0100 |
commit | 279737642c8299f49e7eb74232884534b1b14412 (patch) | |
tree | ec505a098d690354e95903cb5881c4effc3d6bac /Userland/Libraries | |
parent | 1b358d3b947aa3c9026f248945ecd7bb923e8836 (diff) | |
download | serenity-279737642c8299f49e7eb74232884534b1b14412.zip |
LibGL: Add defines and stubs for glBlendFunc()
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGL/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GL/gl.h | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLBlend.cpp | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.cpp | 51 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/SoftwareGLContext.h | 4 |
6 files changed, 92 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGL/CMakeLists.txt b/Userland/Libraries/LibGL/CMakeLists.txt index 4a86aba3e6..8214a8a6e5 100644 --- a/Userland/Libraries/LibGL/CMakeLists.txt +++ b/Userland/Libraries/LibGL/CMakeLists.txt @@ -1,5 +1,6 @@ set(SOURCES Clipper.cpp + GLBlend.cpp GLColor.cpp GLContext.cpp GLLists.cpp diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index fa0f0a03f7..f06158f713 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -42,6 +42,19 @@ extern "C" { #define GL_RENDERER 0x1F01 #define GL_VERSION 0x1F02 +/* Blend factors */ +#define GL_ZERO 0 +#define GL_ONE 1 +#define GL_SRC_COLOR 0x0300 +#define GL_ONE_MINUS_SRC_COLOR 0x0301 +#define GL_SRC_ALPHA 0x0302 +#define GL_ONE_MINUS_SRC_ALPHA 0x0303 +#define GL_DST_ALPHA 0x0304 +#define GL_ONE_MINUS_DST_ALPHA 0x0305 +#define GL_DST_COLOR 0x0306 +#define GL_ONE_MINUS_DST_COLOR 0x0307 +#define GL_SRC_ALPHA_SATURATE 0x0308 + // Culled face side #define GL_FRONT 0x0404 #define GL_BACK 0x0405 @@ -65,6 +78,12 @@ extern "C" { #define GL_COMPILE 0x1300 #define GL_COMPILE_AND_EXECUTE 0x1301 +// More blend factors +#define GL_CONSTANT_COLOR 0x8001 +#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002 +#define GL_CONSTANT_ALPHA 0x8003 +#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004 + // // OpenGL typedefs // @@ -126,6 +145,7 @@ GLAPI void glEndList(void); GLAPI void glNewList(GLuint list, GLenum mode); GLAPI void glFlush(); GLAPI void glFinish(); +GLAPI void glBlendFunc(GLenum sfactor, GLenum dfactor); #ifdef __cplusplus } diff --git a/Userland/Libraries/LibGL/GLBlend.cpp b/Userland/Libraries/LibGL/GLBlend.cpp new file mode 100644 index 0000000000..91bc27952a --- /dev/null +++ b/Userland/Libraries/LibGL/GLBlend.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@gmx.de> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "GL/gl.h" +#include "GLContext.h" + +extern GL::GLContext* g_gl_context; + +void glBlendFunc(GLenum sfactor, GLenum dfactor) +{ + return g_gl_context->gl_blend_func(sfactor, dfactor); +} diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index dffa8073ed..6074454c41 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -49,6 +49,7 @@ public: virtual void gl_new_list(GLuint list, GLenum mode) = 0; virtual void gl_flush() = 0; virtual void gl_finish() = 0; + virtual void gl_blend_func(GLenum src_factor, GLenum dst_factor) = 0; virtual void present() = 0; }; diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp index 1d531dbd53..738b5810a1 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp +++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp @@ -859,6 +859,57 @@ void SoftwareGLContext::gl_finish() // No-op since SoftwareGLContext is completely synchronous at the moment } +void SoftwareGLContext::gl_blend_func(GLenum src_factor, GLenum dst_factor) +{ + if (m_in_draw_state) { + m_error = GL_INVALID_OPERATION; + return; + } + + // FIXME: The list of allowed enums differs between API versions + // This was taken from the 2.0 spec on https://docs.gl/gl2/glBlendFunc + + if (!(src_factor == GL_ZERO + || src_factor == GL_ONE + || src_factor == GL_SRC_COLOR + || src_factor == GL_ONE_MINUS_SRC_COLOR + || src_factor == GL_DST_COLOR + || src_factor == GL_ONE_MINUS_DST_COLOR + || src_factor == GL_SRC_ALPHA + || src_factor == GL_ONE_MINUS_SRC_ALPHA + || src_factor == GL_DST_ALPHA + || src_factor == GL_ONE_MINUS_DST_ALPHA + || src_factor == GL_CONSTANT_COLOR + || src_factor == GL_ONE_MINUS_CONSTANT_COLOR + || src_factor == GL_CONSTANT_ALPHA + || src_factor == GL_ONE_MINUS_CONSTANT_ALPHA + || src_factor == GL_SRC_ALPHA_SATURATE)) { + m_error = GL_INVALID_ENUM; + return; + } + + if (!(dst_factor == GL_ZERO + || dst_factor == GL_ONE + || dst_factor == GL_SRC_COLOR + || dst_factor == GL_ONE_MINUS_SRC_COLOR + || dst_factor == GL_DST_COLOR + || dst_factor == GL_ONE_MINUS_DST_COLOR + || dst_factor == GL_SRC_ALPHA + || dst_factor == GL_ONE_MINUS_SRC_ALPHA + || dst_factor == GL_DST_ALPHA + || dst_factor == GL_ONE_MINUS_DST_ALPHA + || dst_factor == GL_CONSTANT_COLOR + || dst_factor == GL_ONE_MINUS_CONSTANT_COLOR + || dst_factor == GL_CONSTANT_ALPHA + || dst_factor == GL_ONE_MINUS_CONSTANT_ALPHA)) { + m_error = GL_INVALID_ENUM; + return; + } + + m_blend_source_factor = src_factor; + m_blend_destination_factor = dst_factor; +} + void SoftwareGLContext::present() { m_rasterizer.blit_to(*m_frontbuffer); diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h index a1d84e00c6..9dfa0b943b 100644 --- a/Userland/Libraries/LibGL/SoftwareGLContext.h +++ b/Userland/Libraries/LibGL/SoftwareGLContext.h @@ -55,6 +55,7 @@ public: virtual void gl_new_list(GLuint list, GLenum mode) override; virtual void gl_flush() override; virtual void gl_finish() override; + virtual void gl_blend_func(GLenum src_factor, GLenum dst_factor) override; virtual void present() override; @@ -105,6 +106,9 @@ private: GLenum m_front_face = GL_CCW; GLenum m_culled_sides = GL_BACK; + GLenum m_blend_source_factor = GL_ONE; + GLenum m_blend_destination_factor = GL_ZERO; + NonnullRefPtr<Gfx::Bitmap> m_frontbuffer; Clipper m_clipper; |