From c4ede9fcceae854e34bc2e86d9c2a28016269f20 Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 15 May 2013 23:01:16 +0100 Subject: [PATCH] [Add] Check for shaders (not used yet). --- src/opengl.c | 34 ++++++++++++++++++++++++++++++++++ src/opengl.h | 14 ++++++++------ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/opengl.c b/src/opengl.c index a3d908b..9fb8fb0 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -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"); diff --git a/src/opengl.h b/src/opengl.h index 169a5a3..720df0f 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -19,12 +19,14 @@ #define RGBMASK RMASK,GMASK,BMASK,AMASK // Info about opengl screen. -#define OPENGL_FULLSCREEN (1<<0) -#define OPENGL_DOUBLEBUF (1<<1) -#define OPENGL_AA_POINT (1<<2) -#define OPENGL_AA_LINE (1<<3) -#define OPENGL_AA_POLYGON (1<<4) -#define gl_has(f) (gl_screen.flags & (f)) // Check for the flag. +#define OPENGL_FULLSCREEN (1<<0) +#define OPENGL_DOUBLEBUF (1<<1) +#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. int depth; // Depth in bpp.