Преглед на файлове

LibGL: Add support for GL_BLEND in glEnable() and glDisable()

Stephan Unverwerth преди 4 години
родител
ревизия
d6e9b433cf

+ 1 - 0
Userland/Libraries/LibGL/GL/gl.h

@@ -36,6 +36,7 @@ extern "C" {
 // Enable capabilities
 #define GL_CULL_FACE 0x0B44
 #define GL_DEPTH_TEST 0x0B71
+#define GL_BLEND 0x0BE2
 
 // Utility
 #define GL_VENDOR 0x1F00

+ 15 - 0
Userland/Libraries/LibGL/SoftwareGLContext.cpp

@@ -683,6 +683,11 @@ void SoftwareGLContext::gl_enable(GLenum capability)
         rasterizer_options.enable_depth_test = true;
         update_rasterizer_options = true;
         break;
+    case GL_BLEND:
+        m_blend_enabled = true;
+        rasterizer_options.enable_blending = true;
+        update_rasterizer_options = true;
+        break;
     default:
         m_error = GL_INVALID_ENUM;
         break;
@@ -713,6 +718,11 @@ void SoftwareGLContext::gl_disable(GLenum capability)
         rasterizer_options.enable_depth_test = false;
         update_rasterizer_options = true;
         break;
+    case GL_BLEND:
+        m_blend_enabled = false;
+        rasterizer_options.enable_blending = false;
+        update_rasterizer_options = false;
+        break;
     default:
         m_error = GL_INVALID_ENUM;
         break;
@@ -908,6 +918,11 @@ void SoftwareGLContext::gl_blend_func(GLenum src_factor, GLenum dst_factor)
 
     m_blend_source_factor = src_factor;
     m_blend_destination_factor = dst_factor;
+
+    auto options = m_rasterizer.options();
+    options.blend_source_factor = m_blend_source_factor;
+    options.blend_destination_factor = m_blend_destination_factor;
+    m_rasterizer.set_options(options);
 }
 
 void SoftwareGLContext::present()

+ 1 - 0
Userland/Libraries/LibGL/SoftwareGLContext.h

@@ -106,6 +106,7 @@ private:
     GLenum m_front_face = GL_CCW;
     GLenum m_culled_sides = GL_BACK;
 
+    bool m_blend_enabled = false;
     GLenum m_blend_source_factor = GL_ONE;
     GLenum m_blend_destination_factor = GL_ZERO;
 

+ 5 - 1
Userland/Libraries/LibGL/SoftwareRasterizer.h

@@ -7,6 +7,7 @@
 #pragma once
 
 #include "DepthBuffer.h"
+#include "GL/gl.h"
 #include "GLStruct.h"
 #include <AK/OwnPtr.h>
 #include <LibGfx/Bitmap.h>
@@ -15,8 +16,11 @@
 namespace GL {
 
 struct RasterizerOptions {
-    bool shade_smooth { false };
+    bool shade_smooth { true };
     bool enable_depth_test { false };
+    bool enable_blending { false };
+    GLenum blend_source_factor { GL_ONE };
+    GLenum blend_destination_factor { GL_ONE };
 };
 
 class SoftwareRasterizer final {