diff options
author | Stephan Unverwerth <s.unverwerth@serenityos.org> | 2022-08-28 15:39:44 +0200 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-17 22:39:09 -0700 |
commit | 69171e7a05a4cc44a3cd7d2ba8404f95eaef18ca (patch) | |
tree | 7759100986e70e589f87e79160ba3c544020bade | |
parent | 1812a169b89749cc3fe585b0f97b0b06ae6cbda1 (diff) | |
download | serenity-69171e7a05a4cc44a3cd7d2ba8404f95eaef18ca.zip |
LibGL: Implement glUseProgram
-rw-r--r-- | Userland/Libraries/LibGL/GL/gl.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLAPI.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/GLContext.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGL/Shader.cpp | 17 |
4 files changed, 25 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h index 5740f79e83..b5c1039bd5 100644 --- a/Userland/Libraries/LibGL/GL/gl.h +++ b/Userland/Libraries/LibGL/GL/gl.h @@ -825,6 +825,7 @@ GLAPI GLuint glCreateProgram(); GLAPI void glDeleteProgram(GLuint program); GLAPI void glAttachShader(GLuint program, GLuint shader); GLAPI void glLinkProgram(GLuint program); +GLAPI void glUseProgram(GLuint program); #ifdef __cplusplus } diff --git a/Userland/Libraries/LibGL/GLAPI.cpp b/Userland/Libraries/LibGL/GLAPI.cpp index 7ded1b0023..8d41f1f8fc 100644 --- a/Userland/Libraries/LibGL/GLAPI.cpp +++ b/Userland/Libraries/LibGL/GLAPI.cpp @@ -1043,6 +1043,11 @@ void glTranslatef(GLfloat x, GLfloat y, GLfloat z) g_gl_context->gl_translate(x, y, z); } +void glUseProgram(GLuint program) +{ + g_gl_context->gl_use_program(program); +} + void glVertex2d(GLdouble x, GLdouble y) { g_gl_context->gl_vertex(x, y, 0.0, 1.0); diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h index 9b30b44b1b..b773078a34 100644 --- a/Userland/Libraries/LibGL/GLContext.h +++ b/Userland/Libraries/LibGL/GLContext.h @@ -239,6 +239,7 @@ public: void gl_delete_program(GLuint program); void gl_attach_shader(GLuint program, GLuint shader); void gl_link_program(GLuint program); + void gl_use_program(GLuint program); private: void sync_device_config(); @@ -414,6 +415,7 @@ private: NameAllocator m_program_name_allocator; HashMap<GLuint, RefPtr<Shader>> m_allocated_shaders; HashMap<GLuint, RefPtr<Program>> m_allocated_programs; + RefPtr<Program> m_current_program; struct Listing { diff --git a/Userland/Libraries/LibGL/Shader.cpp b/Userland/Libraries/LibGL/Shader.cpp index eea40ae53b..014c558ce0 100644 --- a/Userland/Libraries/LibGL/Shader.cpp +++ b/Userland/Libraries/LibGL/Shader.cpp @@ -118,4 +118,21 @@ void GLContext::gl_link_program(GLuint program) (void)program_it->value->link(); } +void GLContext::gl_use_program(GLuint program) +{ + if (program == 0) { + m_current_program = nullptr; + return; + } + + auto it = m_allocated_programs.find(program); + + // FIXME: implement check "GL_INVALID_VALUE is generated if program is not a value generated by OpenGL." + RETURN_WITH_ERROR_IF(it == m_allocated_programs.end(), GL_INVALID_OPERATION); + // FIXME: implement check "GL_INVALID_OPERATION is generated if transform feedback mode is active." + RETURN_WITH_ERROR_IF(it->value->link_status() != true, GL_INVALID_OPERATION); + + m_current_program = it->value; +} + } |