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.
This commit is contained in:
Stephan Unverwerth 2021-08-11 22:09:18 +02:00 committed by Andreas Kling
parent e0fef60241
commit b9523e15df
Notes: sideshowbarker 2024-07-19 01:59:31 +09:00
6 changed files with 95 additions and 2 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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);
}

View file

@ -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);

View file

@ -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>;

View file

@ -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>