summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorStephan Unverwerth <s.unverwerth@serenityos.org>2021-08-11 22:09:18 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-12 18:58:41 +0200
commitb9523e15dfc6510b9c2978b1645ad61c690811ee (patch)
treeaa40746eec0b948bb1f9944769963f2545c3ee6f /Userland
parente0fef60241397ce12be4ce311382060fe6db707d (diff)
downloadserenity-b9523e15dfc6510b9c2978b1645ad61c690811ee.zip
LibGL: Implement glTexParameter{i,f}
This currently only implements a subset of this function. Namely setting wrap, mag and min modes for the GL_TETXURE_2D target.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGL/GL/gl.h11
-rw-r--r--Userland/Libraries/LibGL/GLContext.h1
-rw-r--r--Userland/Libraries/LibGL/GLTexture.cpp10
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.cpp70
-rw-r--r--Userland/Libraries/LibGL/SoftwareGLContext.h4
-rw-r--r--Userland/Libraries/LibGL/Tex/Texture2D.h1
6 files changed, 95 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGL/GL/gl.h b/Userland/Libraries/LibGL/GL/gl.h
index 84f60d96c3..5215b6ad71 100644
--- a/Userland/Libraries/LibGL/GL/gl.h
+++ b/Userland/Libraries/LibGL/GL/gl.h
@@ -198,7 +198,14 @@ extern "C" {
// Texture Environment and Parameters
#define GL_NEAREST 0x2600
#define GL_LINEAR 0x2601
-#define GL_NEAREST_MIPMAP_LINEAR 0x2602
+#define GL_NEAREST_MIPMAP_NEAREST 0x2700
+#define GL_LINEAR_MIPMAP_NEAREST 0x2701
+#define GL_NEAREST_MIPMAP_LINEAR 0x2702
+#define GL_LINEAR_MIPMAP_LINEAR 0x2703
+#define GL_TEXTURE_MAG_FILTER 0x2800
+#define GL_TEXTURE_MIN_FILTER 0x2801
+#define GL_TEXTURE_WRAP_S 0x2802
+#define GL_TEXTURE_WRAP_T 0x2803
#define GL_CLAMP 0x2900
#define GL_REPEAT 0x2901
#define GL_MIRRORED_REPEAT 0x8370
@@ -299,6 +306,8 @@ GLAPI void glReadBuffer(GLenum mode);
GLAPI void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels);
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 glTexParameteri(GLenum target, GLenum pname, GLint param);
+GLAPI void glTexParameterf(GLenum target, GLenum pname, GLfloat param);
GLAPI void glBindTexture(GLenum target, GLuint texture);
GLAPI void glActiveTexture(GLenum texture);
GLAPI void glGetFloatv(GLenum pname, GLfloat* params);
diff --git a/Userland/Libraries/LibGL/GLContext.h b/Userland/Libraries/LibGL/GLContext.h
index a352ef8596..cf4966a4f0 100644
--- a/Userland/Libraries/LibGL/GLContext.h
+++ b/Userland/Libraries/LibGL/GLContext.h
@@ -58,6 +58,7 @@ public:
virtual void gl_read_buffer(GLenum mode) = 0;
virtual void gl_read_pixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels) = 0;
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_parameter(GLenum target, GLenum pname, GLfloat param) = 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;
diff --git a/Userland/Libraries/LibGL/GLTexture.cpp b/Userland/Libraries/LibGL/GLTexture.cpp
index a8dfc6cb2a..97364df1bf 100644
--- a/Userland/Libraries/LibGL/GLTexture.cpp
+++ b/Userland/Libraries/LibGL/GLTexture.cpp
@@ -36,3 +36,13 @@ void glActiveTexture(GLenum texture)
{
g_gl_context->gl_active_texture(texture);
}
+
+void glTexParameteri(GLenum target, GLenum pname, GLint param)
+{
+ g_gl_context->gl_tex_parameter(target, pname, param);
+}
+
+void glTexParameterf(GLenum target, GLenum pname, GLfloat param)
+{
+ g_gl_context->gl_tex_parameter(target, pname, param);
+}
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.cpp b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
index 168876e944..d1b5bc4c5d 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.cpp
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.cpp
@@ -714,6 +714,76 @@ void SoftwareGLContext::gl_tex_image_2d(GLenum target, GLint level, GLint intern
m_active_texture_unit->bound_texture_2d()->upload_texture_data(target, level, internal_format, width, height, border, format, type, data);
}
+void SoftwareGLContext::gl_tex_parameter(GLenum target, GLenum pname, GLfloat param)
+{
+ APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_tex_parameter, target, pname, param);
+
+ RETURN_WITH_ERROR_IF(m_in_draw_state, GL_INVALID_OPERATION);
+
+ // FIXME: We currently only support GL_TETXURE_2D targets. 1D, 3D and CUBE should also be supported (https://docs.gl/gl2/glTexParameter)
+ RETURN_WITH_ERROR_IF(target != GL_TEXTURE_2D, GL_INVALID_ENUM);
+
+ // FIXME: implement the remaining parameters. (https://docs.gl/gl2/glTexParameter)
+ RETURN_WITH_ERROR_IF(!(pname == GL_TEXTURE_MIN_FILTER
+ || pname == GL_TEXTURE_MAG_FILTER
+ || pname == GL_TEXTURE_WRAP_S
+ || pname == GL_TEXTURE_WRAP_T),
+ GL_INVALID_ENUM);
+
+ if (target == GL_TEXTURE_2D) {
+ auto texture2d = m_active_texture_unit->bound_texture_2d();
+ if (texture2d.is_null())
+ return;
+
+ switch (pname) {
+ case GL_TEXTURE_MIN_FILTER:
+ RETURN_WITH_ERROR_IF(!(param == GL_NEAREST
+ || param == GL_LINEAR
+ || param == GL_NEAREST_MIPMAP_NEAREST
+ || param == GL_LINEAR_MIPMAP_NEAREST
+ || param == GL_NEAREST_MIPMAP_LINEAR
+ || param == GL_LINEAR_MIPMAP_LINEAR),
+ GL_INVALID_ENUM);
+
+ texture2d->sampler().set_min_filter(param);
+ break;
+
+ case GL_TEXTURE_MAG_FILTER:
+ RETURN_WITH_ERROR_IF(!(param == GL_NEAREST
+ || param == GL_LINEAR),
+ GL_INVALID_ENUM);
+
+ texture2d->sampler().set_mag_filter(param);
+ break;
+
+ case GL_TEXTURE_WRAP_S:
+ RETURN_WITH_ERROR_IF(!(param == GL_CLAMP
+ || param == GL_CLAMP_TO_BORDER
+ || param == GL_CLAMP_TO_EDGE
+ || param == GL_MIRRORED_REPEAT
+ || param == GL_REPEAT),
+ GL_INVALID_ENUM);
+
+ texture2d->sampler().set_wrap_s_mode(param);
+ break;
+
+ case GL_TEXTURE_WRAP_T:
+ RETURN_WITH_ERROR_IF(!(param == GL_CLAMP
+ || param == GL_CLAMP_TO_BORDER
+ || param == GL_CLAMP_TO_EDGE
+ || param == GL_MIRRORED_REPEAT
+ || param == GL_REPEAT),
+ GL_INVALID_ENUM);
+
+ texture2d->sampler().set_wrap_t_mode(param);
+ break;
+
+ default:
+ VERIFY_NOT_REACHED();
+ }
+ }
+}
+
void SoftwareGLContext::gl_front_face(GLenum face)
{
APPEND_TO_CALL_LIST_AND_RETURN_IF_NEEDED(gl_front_face, face);
diff --git a/Userland/Libraries/LibGL/SoftwareGLContext.h b/Userland/Libraries/LibGL/SoftwareGLContext.h
index d41d92fbd7..4192fa8cde 100644
--- a/Userland/Libraries/LibGL/SoftwareGLContext.h
+++ b/Userland/Libraries/LibGL/SoftwareGLContext.h
@@ -68,6 +68,7 @@ public:
virtual void gl_read_buffer(GLenum mode) override;
virtual void gl_read_pixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels) override;
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_parameter(GLenum target, GLenum pname, GLfloat param) 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;
@@ -194,7 +195,8 @@ private:
decltype(&SoftwareGLContext::gl_shade_model),
decltype(&SoftwareGLContext::gl_alpha_func),
decltype(&SoftwareGLContext::gl_hint),
- decltype(&SoftwareGLContext::gl_read_buffer)>;
+ decltype(&SoftwareGLContext::gl_read_buffer),
+ decltype(&SoftwareGLContext::gl_tex_parameter)>;
using ExtraSavedArguments = Variant<
FloatMatrix4x4>;
diff --git a/Userland/Libraries/LibGL/Tex/Texture2D.h b/Userland/Libraries/LibGL/Tex/Texture2D.h
index c1d3022dcf..a281f06be1 100644
--- a/Userland/Libraries/LibGL/Tex/Texture2D.h
+++ b/Userland/Libraries/LibGL/Tex/Texture2D.h
@@ -42,6 +42,7 @@ public:
GLenum internal_format() const { return m_internal_format; }
Sampler2D const& sampler() const { return m_sampler; }
+ Sampler2D& sampler() { return m_sampler; }
private:
template<typename TCallback>