unsigned int ShaderProgramGL::createShader(unsigned int type, const char* data, const char* prepend, const char* append) { GLuint shader = oxglCreateShader(type); const char* sources[16]; const char** ptr = &sources[0]; bool gles = false; #ifdef __S3E__ gles = true; #elif OXYGINE_SDL int profile = 0; SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile); gles = profile == SDL_GL_CONTEXT_PROFILE_ES; #else #endif #ifndef EMSCRIPTEN if (!gles) { log::messageln("not gles version"); static const char nonGLES[] = "#define lowp\n" "#define mediump\n" "#define highp\n"; *ptr = nonGLES; ptr++; } #endif if (prepend) { *ptr = prepend; ptr++; } *ptr = data; ptr++; if (append) { *ptr = append; ptr++; } int num = (int)(ptr - sources); oxglShaderSource(shader, num, sources, 0); oxglCompileShader(shader); printShaderInfoLog(shader); CHECKGL(); return shader; }
unsigned int ShaderProgramGL::createShader(unsigned int type, const char* data, const char *prepend, const char *append) { GLuint shader = oxglCreateShader(type); const char *sources[16]; const char **ptr = &sources[0]; char nonGLES[] = "#define lowp\n" "#define mediump\n" "#define highp\n"; #if SDL_VIDEO_OPENGL log::messageln("not gles version"); *ptr = nonGLES; ptr++; #endif #ifdef EMSCRIPTEN *ptr = "precision float mediump;"; #endif if (prepend) { *ptr = prepend; ptr++; } *ptr = data; ptr++; if (append) { *ptr = append; ptr++; } int num = (int)(ptr - sources); oxglShaderSource(shader, num, sources, 0); oxglCompileShader(shader); printShaderInfoLog(shader); CHECKGL(); return shader; }
unsigned int ShaderProgramGL::createShader(unsigned int type, const char* data, const char* prepend, const char* append, error_policy ep) { GLuint shader = oxglCreateShader(type); const char* sources[16]; const char** ptr = &sources[0]; bool gles = false; #ifdef __S3E__ gles = true; #elif OXYGINE_SDL int profile = 0; SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile); gles = profile == SDL_GL_CONTEXT_PROFILE_ES; #else #endif #ifndef EMSCRIPTEN if (!gles) { //log::messageln("not gles version"); static const char nonGLES[] = "#define lowp\n" "#define mediump\n" "#define highp\n"; *ptr = nonGLES; ptr++; } #endif #ifdef __ANDROID__ *ptr = "#define ANDROID 1\n"; ptr++; #endif if (prepend) { *ptr = prepend; ptr++; } *ptr = data; ptr++; if (append) { *ptr = append; ptr++; } int num = (int)(ptr - sources); oxglShaderSource(shader, num, sources, 0); oxglCompileShader(shader); std::string log; bool success = getShaderBuildLog(shader, log); if (success) { log::messageln("compiled shader: %s", log.c_str()); } else { handleErrorPolicy(ep, "can't compile shader: %s", log.c_str()); } checkGLError(); return shader; }