Skip to content

Commit 4eb6295

Browse files
gmtaawesomekling
authored andcommitted
LibGL: Implement glRasterPos2i
1 parent 78d0674 commit 4eb6295

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

Userland/Libraries/LibGL/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(SOURCES
77
GLBlend.cpp
88
GLColor.cpp
99
GLContext.cpp
10+
GLDraw.cpp
1011
GLFog.cpp
1112
GLLights.cpp
1213
GLLists.cpp

Userland/Libraries/LibGL/GL/gl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ GLAPI void glStencilOp(GLenum sfail, GLenum dpfail, GLenum dppass);
451451
GLAPI void glStencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
452452
GLAPI void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz);
453453
GLAPI void glNormal3fv(GLfloat const* v);
454+
GLAPI void glRasterPos2i(GLint x, GLint y);
454455

455456
#ifdef __cplusplus
456457
}

Userland/Libraries/LibGL/GLContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class GLContext {
9494
virtual void gl_stencil_func_separate(GLenum face, GLenum func, GLint ref, GLuint mask) = 0;
9595
virtual void gl_stencil_op_separate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) = 0;
9696
virtual void gl_normal(GLfloat nx, GLfloat ny, GLfloat nz) = 0;
97+
virtual void gl_raster_pos(GLfloat x, GLfloat y, GLfloat z, GLfloat w) = 0;
9798

9899
virtual void present() = 0;
99100
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2021, Jelle Raaijmakers <jelle@gmta.nl>
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
#include "GL/gl.h"
8+
#include "GLContext.h"
9+
10+
extern GL::GLContext* g_gl_context;
11+
12+
void glRasterPos2i(GLint x, GLint y)
13+
{
14+
g_gl_context->gl_raster_pos(static_cast<float>(x), static_cast<float>(y), 0.0f, 1.0f);
15+
}

Userland/Libraries/LibGL/SoftwareGLContext.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,15 @@ void SoftwareGLContext::gl_normal(GLfloat nx, GLfloat ny, GLfloat nz)
22482248
m_current_vertex_normal = { nx, ny, nz };
22492249
}
22502250

2251+
void SoftwareGLContext::gl_raster_pos(GLfloat x, GLfloat y, GLfloat z, GLfloat w)
2252+
{
2253+
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_raster_pos, x, y, z, w);
2254+
RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);
2255+
2256+
m_current_raster_position.window_coordinates = { x, y, z };
2257+
m_current_raster_position.clip_coordinate_value = w;
2258+
}
2259+
22512260
void SoftwareGLContext::present()
22522261
{
22532262
m_rasterizer.blit_to(*m_frontbuffer);

Userland/Libraries/LibGL/SoftwareGLContext.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class SoftwareGLContext : public GLContext {
105105
virtual void gl_stencil_func_separate(GLenum face, GLenum func, GLint ref, GLuint mask) override;
106106
virtual void gl_stencil_op_separate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) override;
107107
virtual void gl_normal(GLfloat nx, GLfloat ny, GLfloat nz) override;
108+
virtual void gl_raster_pos(GLfloat x, GLfloat y, GLfloat z, GLfloat w) override;
108109
virtual void present() override;
109110

110111
private:
@@ -269,7 +270,8 @@ class SoftwareGLContext : public GLContext {
269270
decltype(&SoftwareGLContext::gl_scissor),
270271
decltype(&SoftwareGLContext::gl_stencil_func_separate),
271272
decltype(&SoftwareGLContext::gl_stencil_op_separate),
272-
decltype(&SoftwareGLContext::gl_normal)>;
273+
decltype(&SoftwareGLContext::gl_normal),
274+
decltype(&SoftwareGLContext::gl_raster_pos)>;
273275

274276
using ExtraSavedArguments = Variant<
275277
FloatMatrix4x4>;
@@ -305,6 +307,17 @@ class SoftwareGLContext : public GLContext {
305307
u8 m_pack_alignment { 4 };
306308
GLsizei m_unpack_row_length { 0 };
307309
u8 m_unpack_alignment { 4 };
310+
311+
struct RasterPosition {
312+
FloatVector3 window_coordinates { 0.0f, 0.0f, 0.0f };
313+
float clip_coordinate_value { 1.0f };
314+
float eye_coordinate_distance { 0.0f };
315+
bool valid { true };
316+
FloatVector4 color_rgba { 1.0f, 1.0f, 1.0f, 1.0f };
317+
float color_index { 1.0f };
318+
FloatVector4 texture_coordinates { 0.0f, 0.0f, 0.0f, 1.0f };
319+
};
320+
RasterPosition m_current_raster_position;
308321
};
309322

310323
}

0 commit comments

Comments
 (0)