-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable trilinear filtering for OpenGL
Improve downscaling quality if mipmapping is available. Suggested-by: Giumo Clanjor (哆啦比猫/兰威举) <[email protected]> Fixes #40 <#40> Ref: <#40 (comment)>
- Loading branch information
Showing
5 changed files
with
155 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "opengl.h" | ||
|
||
#include <assert.h> | ||
#include <stdio.h> | ||
#include "SDL2/SDL.h" | ||
|
||
void | ||
sc_opengl_init(struct sc_opengl *gl) { | ||
gl->GetString = SDL_GL_GetProcAddress("glGetString"); | ||
assert(gl->GetString); | ||
|
||
gl->TexParameterf = SDL_GL_GetProcAddress("glTexParameterf"); | ||
assert(gl->TexParameterf); | ||
|
||
gl->TexParameteri = SDL_GL_GetProcAddress("glTexParameteri"); | ||
assert(gl->TexParameteri); | ||
|
||
// optional | ||
gl->GenerateMipmap = SDL_GL_GetProcAddress("glGenerateMipmap"); | ||
|
||
const char *version = (const char *) gl->GetString(GL_VERSION); | ||
assert(version); | ||
gl->version = version; | ||
|
||
#define OPENGL_ES_PREFIX "OpenGL ES " | ||
/* starts with "OpenGL ES " */ | ||
gl->is_opengles = !strncmp(gl->version, OPENGL_ES_PREFIX, | ||
sizeof(OPENGL_ES_PREFIX) - 1); | ||
if (gl->is_opengles) { | ||
/* skip the prefix */ | ||
version += sizeof(PREFIX) - 1; | ||
} | ||
|
||
int r = sscanf(version, "%d.%d", &gl->version_major, &gl->version_minor); | ||
if (r != 2) { | ||
// failed to parse the version | ||
gl->version_major = 0; | ||
gl->version_minor = 0; | ||
} | ||
} | ||
|
||
bool | ||
sc_opengl_version_at_least(struct sc_opengl *gl, | ||
int minver_major, int minver_minor, | ||
int minver_es_major, int minver_es_minor) | ||
{ | ||
if (gl->is_opengles) { | ||
return gl->version_major > minver_es_major | ||
|| (gl->version_major == minver_es_major | ||
&& gl->version_minor >= minver_es_minor); | ||
} | ||
|
||
return gl->version_major > minver_major | ||
|| (gl->version_major == minver_major | ||
&& gl->version_minor >= minver_minor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef SC_OPENGL_H | ||
#define SC_OPENGL_H | ||
|
||
#include <stdbool.h> | ||
#include <SDL2/SDL_opengl.h> | ||
|
||
#include "config.h" | ||
|
||
struct sc_opengl { | ||
const char *version; | ||
bool is_opengles; | ||
int version_major; | ||
int version_minor; | ||
|
||
const GLubyte * | ||
(*GetString)(GLenum name); | ||
|
||
void | ||
(*TexParameterf)(GLenum target, GLenum pname, GLfloat param); | ||
|
||
void | ||
(*TexParameteri)(GLenum target, GLenum pname, GLint param); | ||
|
||
void | ||
(*GenerateMipmap)(GLenum target); | ||
}; | ||
|
||
void | ||
sc_opengl_init(struct sc_opengl *gl); | ||
|
||
bool | ||
sc_opengl_version_at_least(struct sc_opengl *gl, | ||
int minver_major, int minver_minor, | ||
int minver_es_major, int minver_es_minor); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters