[Add] Check for shaders (not used yet).

This commit is contained in:
Allanis 2013-05-15 23:01:16 +01:00
parent 2f3cae5b6b
commit c4ede9fcce
2 changed files with 42 additions and 6 deletions

View File

@ -38,6 +38,8 @@ static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh);
// PNG.
int write_png(const char* file_name, png_bytep* rows, int w, int h,
int colourtype, int bitdepth);
// Global.
static GLboolean gl_hasExt(char* name);
// ================
// MISC!
@ -536,6 +538,32 @@ void gl_drawCircleInRect(const double cx, const double cy, const double r,
// GLOBAL.
// ================
// Check for extensions.
static GLboolean gl_hasExt(char* name) {
// ======================================================
// Search for name in the extensions string. Use of strstr()
// is not sufficient because extensions names can be prefixes of
// other extension names. Could use strtol() but the constant
// string returned by glGetString can be in read-only memory.
// ======================================================
char* p, *end;
size_t len, n;
p = (char*) glGetString(GL_EXTENSIONS);
len = strlen(name);
end = p + strlen(p);
while(p < end) {
n = strcspn(p, " ");
if((len == n) && (strncmp(name, p, n)==0))
return GL_TRUE;
p += (n+1);
}
return GL_FALSE;
}
// Initialize SDL/OpenGL etc.
int gl_init(void) {
int doublebuf, depth, i, j, off, toff, supported;
@ -621,6 +649,12 @@ int gl_init(void) {
if(doublebuf) gl_screen.flags |= OPENGL_DOUBLEBUF;
gl_screen.depth = gl_screen.r + gl_screen.g + gl_screen.b + gl_screen.a;
// Get info about some extensions.
if(gl_hasExt("GL_ARB_vertex_shader")==GL_TRUE)
gl_screen.flags |= OPENGL_VERT_SHADER;
if(gl_hasExt("GL_ARB_fragment_shader")==GL_TRUE)
gl_screen.flags |= OPENGL_FRAG_SHADER;
// Debug heaven.
DEBUG("OpenGL Window Created: %dx%d@%dbpp %s", gl_screen.w, gl_screen.h,
gl_screen.depth, (gl_has(OPENGL_FULLSCREEN)) ? "fullscreen" : "window");

View File

@ -24,6 +24,8 @@
#define OPENGL_AA_POINT (1<<2)
#define OPENGL_AA_LINE (1<<3)
#define OPENGL_AA_POLYGON (1<<4)
#define OPENGL_FRAG_SHADER (1<<5)
#define OPENGL_VERT_SHADER (1<<6)
#define gl_has(f) (gl_screen.flags & (f)) // Check for the flag.
typedef struct glInfo_ {
int w, h; // Window dimensions.