LibGL: Implement glNormal3f and glNormal3fv

This commit is contained in:
Jelle Raaijmakers 2021-12-01 15:33:23 +01:00 committed by Andreas Kling
parent ea6bcda79c
commit 78d0674228
Notes: sideshowbarker 2024-07-17 22:51:54 +09:00
6 changed files with 27 additions and 1 deletions

View file

@ -449,6 +449,8 @@ GLAPI void glStencilFunc(GLenum func, GLint ref, GLuint mask);
GLAPI void glStencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask);
GLAPI void glStencilOp(GLenum sfail, GLenum dpfail, GLenum dppass);
GLAPI void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
GLAPI void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz);
GLAPI void glNormal3fv(GLfloat const* v);
#ifdef __cplusplus
}

View file

@ -93,6 +93,7 @@ public:
virtual void gl_scissor(GLint x, GLint y, GLsizei width, GLsizei height) = 0;
virtual void gl_stencil_func_separate(GLenum face, GLenum func, GLint ref, GLuint mask) = 0;
virtual void gl_stencil_op_separate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) = 0;
virtual void gl_normal(GLfloat nx, GLfloat ny, GLfloat nz) = 0;
virtual void present() = 0;
};

View file

@ -8,6 +8,7 @@
#include "GL/gl.h"
#include <LibGfx/Vector2.h>
#include <LibGfx/Vector3.h>
#include <LibGfx/Vector4.h>
namespace GL {
@ -20,6 +21,7 @@ struct GLVertex {
FloatVector4 position;
FloatVector4 color;
FloatVector2 tex_coord;
FloatVector3 normal;
};
struct GLTriangle {

View file

@ -169,3 +169,13 @@ void glTranslatef(GLfloat x, GLfloat y, GLfloat z)
{
g_gl_context->gl_translate(x, y, z);
}
void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
{
g_gl_context->gl_normal(nx, ny, nz);
}
void glNormal3fv(GLfloat const* v)
{
g_gl_context->gl_normal(v[0], v[1], v[2]);
}

View file

@ -514,6 +514,7 @@ void SoftwareGLContext::gl_vertex(GLdouble x, GLdouble y, GLdouble z, GLdouble w
vertex.position = { static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), static_cast<float>(w) };
vertex.color = m_current_vertex_color;
vertex.tex_coord = { m_current_vertex_tex_coord.x(), m_current_vertex_tex_coord.y() };
vertex.normal = m_current_vertex_normal;
vertex_list.append(vertex);
}
@ -2240,6 +2241,13 @@ void SoftwareGLContext::gl_stencil_op_separate(GLenum face, GLenum sfail, GLenum
m_stencil_backfacing_op = new_options;
}
void SoftwareGLContext::gl_normal(GLfloat nx, GLfloat ny, GLfloat nz)
{
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_normal, nx, ny, nz);
m_current_vertex_normal = { nx, ny, nz };
}
void SoftwareGLContext::present()
{
m_rasterizer.blit_to(*m_frontbuffer);

View file

@ -104,6 +104,7 @@ public:
virtual void gl_scissor(GLint x, GLint y, GLsizei width, GLsizei height) override;
virtual void gl_stencil_func_separate(GLenum face, GLenum func, GLint ref, GLuint mask) override;
virtual void gl_stencil_op_separate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) override;
virtual void gl_normal(GLfloat nx, GLfloat ny, GLfloat nz) override;
virtual void present() override;
private:
@ -143,6 +144,7 @@ private:
double m_clear_depth = { 1.0 };
FloatVector4 m_current_vertex_color = { 1.0f, 1.0f, 1.0f, 1.0f };
FloatVector4 m_current_vertex_tex_coord = { 0.0f, 0.0f, 0.0f, 0.0f };
FloatVector3 m_current_vertex_normal = { 0.0f, 0.0f, 1.0f };
Vector<GLVertex, 96> vertex_list;
Vector<GLTriangle, 32> triangle_list;
@ -266,7 +268,8 @@ private:
decltype(&SoftwareGLContext::gl_polygon_offset),
decltype(&SoftwareGLContext::gl_scissor),
decltype(&SoftwareGLContext::gl_stencil_func_separate),
decltype(&SoftwareGLContext::gl_stencil_op_separate)>;
decltype(&SoftwareGLContext::gl_stencil_op_separate),
decltype(&SoftwareGLContext::gl_normal)>;
using ExtraSavedArguments = Variant<
FloatMatrix4x4>;