Skip to content

Commit

Permalink
Merge pull request #2315 from ivan-mogilko/361--fix-gl-linear-clamp
Browse files Browse the repository at this point in the history
OpenGL: use GL_CLAMP_TO_EDGE with Linear filter
  • Loading branch information
ivan-mogilko committed Jan 30, 2024
2 parents b148832 + 5ef509d commit 12b7f62
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Engine/gfx/ali3dogl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

#if AGS_OPENGL_ES2

#define GL_CLAMP GL_CLAMP_TO_EDGE

const char* fbo_extension_string = "GL_OES_framebuffer_object";

#define glGenFramebuffersEXT glGenFramebuffers
Expand Down Expand Up @@ -1130,18 +1128,20 @@ void OGLGraphicsDriver::_renderSprite(const OGLDrawListEntry *drawListEntry,
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
else if (_do_render_to_texture)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
}
else
{
_filter->SetFilteringForStandardSprite();
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

if (txdata->_vertex != nullptr)
{
Expand Down Expand Up @@ -1639,8 +1639,12 @@ void OGLGraphicsDriver::UpdateTextureRegion(OGLTextureTile *tile, Bitmap *bitmap
else
BitmapToVideoMem(bitmap, has_alpha, &fixedTile, memPtr, pitch, usingLinearFiltering);

// Mimic the behaviour of GL_CLAMP_EDGE for the tile edges
// NOTE: on some platforms GL_CLAMP_EDGE does not work with the version of OpenGL we're using.
// Mimic the behaviour of GL_CLAMP_TO_EDGE for the tile edges
// NOTE: on some platforms GL_CLAMP_TO_EDGE does not work with the version of OpenGL we're using.
// TODO: test the GL version to see if this is even necessary?!
// Info on CLAMP types:
// https://docs.gl/gl2/glTexParameter
// https://stackoverflow.com/questions/56823126/how-is-gl-clamp-in-opengl-different-from-gl-clamp-to-edge
if (tile->width < tileWidth)
{
if (tilex > 0)
Expand Down
4 changes: 4 additions & 0 deletions Engine/gfx/gfxfilter_aaogl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ void AAOGLGfxFilter::SetFilteringForStandardSprite()
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// Prevent sprite pixels mixing with "texture border" pixels sometimes
// See: https://stackoverflow.com/questions/56823126/how-is-gl-clamp-in-opengl-different-from-gl-clamp-to-edge
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}

const GfxFilterInfo &AAOGLGfxFilter::GetInfo() const
Expand Down
2 changes: 2 additions & 0 deletions Engine/gfx/gfxfilter_ogl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ void OGLGfxFilter::SetFilteringForStandardSprite()
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
}

const GfxFilterInfo &OGLGfxFilter::GetInfo() const
Expand Down
6 changes: 6 additions & 0 deletions Engine/gfx/ogl_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@
#ifndef GLAPI
#define GLAD_GL_VERSION_2_0 (0)
#endif

#if AGS_OPENGL_ES2
#ifndef GL_CLAMP
#define GL_CLAMP GL_CLAMP_TO_EDGE
#endif
#endif // AGS_OPENGL_ES2

0 comments on commit 12b7f62

Please sign in to comment.