Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGL: use GL_CLAMP_TO_EDGE with Linear filter #2315

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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