LibGL: Implement glFogfv

This currently just sets the fog colour in the rasterizer.
This commit is contained in:
Jesse Buhagiar 2021-08-25 01:10:19 +10:00 committed by Ali Mohammad Pur
parent ffa7da0ca5
commit 7f1cd54b80
Notes: sideshowbarker 2024-07-18 05:18:04 +09:00
7 changed files with 45 additions and 0 deletions

View File

@ -7,6 +7,7 @@ set(SOURCES
GLBlend.cpp
GLColor.cpp
GLContext.cpp
GLFog.cpp
GLLights.cpp
GLLists.cpp
GLMat.cpp

View File

@ -374,6 +374,7 @@ GLAPI void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void* i
GLAPI void glDepthRange(GLdouble nearVal, GLdouble farVal);
GLAPI void glDepthFunc(GLenum func);
GLAPI void glPolygonMode(GLenum face, GLenum mode);
GLAPI void glFogfv(GLenum mode, GLfloat* params);
#ifdef __cplusplus
}

View File

@ -77,6 +77,7 @@ public:
virtual void gl_depth_range(GLdouble min, GLdouble max) = 0;
virtual void gl_depth_func(GLenum func) = 0;
virtual void gl_polygon_mode(GLenum face, GLenum mode) = 0;
virtual void gl_fogfv(GLenum pname, GLfloat* params) = 0;
virtual void present() = 0;
};

View File

@ -0,0 +1,15 @@
/*
* Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "GL/gl.h"
#include "GLContext.h"
extern GL::GLContext* g_gl_context;
void glFogfv(GLenum pname, GLfloat* params)
{
g_gl_context->gl_fogfv(pname, params);
}

View File

@ -1745,6 +1745,26 @@ void SoftwareGLContext::gl_polygon_mode(GLenum face, GLenum mode)
m_rasterizer.set_options(options);
}
void SoftwareGLContext::gl_fogfv(GLenum pname, GLfloat* params)
{
RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);
auto options = m_rasterizer.options();
switch (pname) {
case GL_FOG_COLOR:
// Set rasterizer options fog color
// NOTE: We purposefully don't check for `nullptr` here (as with other calls). The spec states nothing
// about us checking for such things. If the programmer does so and hits SIGSEGV, that's on them.
options.fog_color = FloatVector4 { params[0], params[1], params[2], params[3] };
break;
default:
RETURN_WITH_ERROR_IF(true, GL_INVALID_ENUM);
}
m_rasterizer.set_options(options);
}
void SoftwareGLContext::present()
{
m_rasterizer.blit_to(*m_frontbuffer);

View File

@ -87,6 +87,7 @@ public:
virtual void gl_depth_range(GLdouble min, GLdouble max) override;
virtual void gl_depth_func(GLenum func) override;
virtual void gl_polygon_mode(GLenum face, GLenum mode) override;
virtual void gl_fogfv(GLenum pname, GLfloat* params) override;
virtual void present() override;
private:

View File

@ -33,6 +33,12 @@ struct RasterizerOptions {
float depth_max { 1 };
GLenum depth_func { GL_LESS };
GLenum polygon_mode { GL_FILL };
FloatVector4 fog_color {
0.0f,
0.0f,
0.0f,
0.0f,
};
};
class SoftwareRasterizer final {