Skip to content

Commit

Permalink
LibGL: Implement glActiveTexture
Browse files Browse the repository at this point in the history
  • Loading branch information
Quaker762 authored and linusg committed May 31, 2021
1 parent 52e5d3c commit 573c1c8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Userland/Libraries/LibGL/GL/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,40 @@ extern "C" {
// Texture targets
#define GL_TEXTURE_2D 0x0DE1

// Texture Unit indices
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1
#define GL_TEXTURE2 0x84C2
#define GL_TEXTURE3 0x84C3
#define GL_TEXTURE4 0x84C4
#define GL_TEXTURE5 0x84C5
#define GL_TEXTURE6 0x84C6
#define GL_TEXTURE7 0x84C7
#define GL_TEXTURE8 0x84C8
#define GL_TEXTURE9 0x84C9
#define GL_TEXTURE10 0x84CA
#define GL_TEXTURE11 0x84CB
#define GL_TEXTURE12 0x84CC
#define GL_TEXTURE13 0x84CD
#define GL_TEXTURE14 0x84CE
#define GL_TEXTURE15 0x84CF
#define GL_TEXTURE16 0x84D0
#define GL_TEXTURE17 0x84D1
#define GL_TEXTURE18 0x84D2
#define GL_TEXTURE19 0x84D3
#define GL_TEXTURE20 0x84D4
#define GL_TEXTURE21 0x84D5
#define GL_TEXTURE22 0x84D6
#define GL_TEXTURE23 0x84D7
#define GL_TEXTURE24 0x84D8
#define GL_TEXTURE25 0x84D9
#define GL_TEXTURE26 0x84DA
#define GL_TEXTURE27 0x84DB
#define GL_TEXTURE28 0x84DC
#define GL_TEXTURE29 0x84DD
#define GL_TEXTURE30 0x84DE
#define GL_TEXTURE31 0x84DF

// Texture Environment and Parameters
#define GL_NEAREST 0x2600
#define GL_LINEAR 0x2601
Expand Down Expand Up @@ -259,6 +293,7 @@ GLAPI void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
GLAPI void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* data);
GLAPI void glTexCoord2f(GLfloat s, GLfloat t);
GLAPI void glBindTexture(GLenum target, GLuint texture);
GLAPI void glActiveTexture(GLenum texture);

#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 @@ -60,6 +60,7 @@ class GLContext {
virtual void gl_tex_image_2d(GLenum target, GLint level, GLint internal_format, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* data) = 0;
virtual void gl_tex_coord(GLfloat s, GLfloat t, GLfloat r, GLfloat q) = 0;
virtual void gl_bind_texture(GLenum target, GLuint texture) = 0;
virtual void gl_active_texture(GLenum texture) = 0;

virtual void present() = 0;
};
Expand Down
7 changes: 7 additions & 0 deletions Userland/Libraries/LibGL/GLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ void glBindTexture(GLenum target, GLuint texture)
{
g_gl_context->gl_bind_texture(target, texture);
}

// Note: This is an _extremely_ misleading API name. This sets the active
// texture unit, NOT the active texture itself...
void glActiveTexture(GLenum texture)
{
g_gl_context->gl_active_texture(texture);
}
7 changes: 7 additions & 0 deletions Userland/Libraries/LibGL/SoftwareGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,13 @@ void SoftwareGLContext::gl_bind_texture(GLenum target, GLuint texture)
}
}

void SoftwareGLContext::gl_active_texture(GLenum texture)
{
RETURN_WITH_ERROR_IF(texture < GL_TEXTURE0 || texture > GL_TEXTURE31, GL_INVALID_ENUM);

m_active_texture_unit = &m_texture_units.at(texture - GL_TEXTURE0);
}

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 @@ -70,6 +70,7 @@ class SoftwareGLContext : public GLContext {
virtual void gl_tex_image_2d(GLenum target, GLint level, GLint internal_format, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* data) override;
virtual void gl_tex_coord(GLfloat s, GLfloat t, GLfloat r, GLfloat q) override;
virtual void gl_bind_texture(GLenum target, GLuint texture) override;
virtual void gl_active_texture(GLenum texture) override;

virtual void present() override;

Expand Down

0 comments on commit 573c1c8

Please sign in to comment.