Skip to content

Commit

Permalink
LibGL: Implement glPolygonMode
Browse files Browse the repository at this point in the history
Currently just sets the renderer option for what polygon mode we
want the rasterizer to draw in. GLQuake only uses `GL_FRONT_AND_BACK`
with `GL_FILL` )which implies both back and front facing triangles
are to be filled completely by the rasterizer), so keeping this as
a small stub is perfectly fine for now.
  • Loading branch information
Quaker762 authored and alimpfard committed Aug 20, 2021
1 parent f58e235 commit 89eddb5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Userland/Libraries/LibGL/GL/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ extern "C" {
#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004

// Polygon modes
#define GL_POINT 0x1B00
#define GL_LINE 0x1B01
#define GL_FILL 0x1B02

// Pixel formats
Expand Down Expand Up @@ -371,6 +373,7 @@ GLAPI void glDrawArrays(GLenum mode, GLint first, GLsizei count);
GLAPI void glDrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices);
GLAPI void glDepthRange(GLdouble nearVal, GLdouble farVal);
GLAPI void glDepthFunc(GLenum func);
GLAPI void glPolygonMode(GLenum face, GLenum mode);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibGL/GLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class GLContext {
virtual void gl_get_integerv(GLenum pname, GLint* data) = 0;
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 present() = 0;
};
Expand Down
5 changes: 5 additions & 0 deletions Userland/Libraries/LibGL/GLUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,8 @@ void glDepthFunc(GLenum func)
{
g_gl_context->gl_depth_func(func);
}

void glPolygonMode(GLenum face, GLenum mode)
{
g_gl_context->gl_polygon_mode(face, mode);
}
12 changes: 12 additions & 0 deletions Userland/Libraries/LibGL/SoftwareGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,18 @@ void SoftwareGLContext::gl_color_mask(GLboolean red, GLboolean green, GLboolean
m_rasterizer.set_options(options);
}

void SoftwareGLContext::gl_polygon_mode(GLenum face, GLenum mode)
{
RETURN_WITH_ERROR_IF(!(face == GL_BACK || face == GL_FRONT || face == GL_FRONT_AND_BACK), GL_INVALID_ENUM);
RETURN_WITH_ERROR_IF(!(mode == GL_POINT || mode == GL_LINE || mode == GL_FILL), GL_INVALID_ENUM);
RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);

auto options = m_rasterizer.options();
options.polygon_mode = mode;

m_rasterizer.set_options(options);
}

void SoftwareGLContext::present()
{
m_rasterizer.blit_to(*m_frontbuffer);
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibGL/SoftwareGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class SoftwareGLContext : public GLContext {
virtual void gl_get_integerv(GLenum pname, GLint* data) override;
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 present() override;

private:
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibGL/SoftwareRasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct RasterizerOptions {
float depth_min { 0 };
float depth_max { 1 };
GLenum depth_func { GL_LESS };
GLenum polygon_mode { GL_FILL };
};

class SoftwareRasterizer final {
Expand Down

0 comments on commit 89eddb5

Please sign in to comment.