Eliminate GLEW dependency

GL entrypoint resolution is now done manually. This has a couple
immediate benefits, such as not having to retrieve hundreds of
functions pointers that we'll never use. It's also nice to have
an exact overview of all the entrypoints used by mkxp.

This change allows mkxp to run fine with core contexts, not sure
how relevant that is going to be in the future.

What's noteworthy is that  _all_ entrypoints, even the ones core
in 1.1 and guaranteed to be in every libGL, are resolved
dynamically.
This has the added benefit of not having to link directly against
libGL anymore, which also cleans up the output of `ldd` quite
a bit (SDL2 loads most system deps dynamically at runtime).

GL headers are still required at build time.
This commit is contained in:
Jonas Kulla 2014-05-30 23:01:35 +02:00
parent 640b01e518
commit 6c481e5eb8
16 changed files with 470 additions and 272 deletions

View File

@ -84,10 +84,8 @@ pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf)
pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image)
pkg_check_modules(SDL_SOUND REQUIRED SDL_sound)
find_package(GLEW 1.9.0 REQUIRED)
find_package(Boost 1.49 COMPONENTS program_options REQUIRED)
find_package(OpenAL REQUIRED)
find_package(OpenGL REQUIRED)
find_package(ZLIB REQUIRED)
## Setup main source ##
@ -135,6 +133,7 @@ set(MAIN_HEADERS
src/al-util.h
src/boost-hash.h
src/debugwriter.h
src/gl-fun.h
)
set(MAIN_SOURCE
@ -164,6 +163,7 @@ set(MAIN_SOURCE
src/tileatlas.cpp
src/perftimer.cpp
src/sharedstate.cpp
src/gl-fun.cpp
)
source_group("MKXP Source" FILES ${MAIN_SOURCE} ${MAIN_HEADERS})
@ -352,7 +352,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE
${PHYSFS_INCLUDE_DIRS}
${SDL2_INCLUDE_DIRS} # Blindly assume other SDL bits are in same directory
${Boost_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}/GL
${MRI_INCLUDE_DIRS}
${OPENAL_INCLUDE_DIR}
)
@ -368,8 +367,6 @@ target_link_libraries(${PROJECT_NAME}
${Boost_LIBRARIES}
${MRI_LIBRARIES}
${OPENAL_LIBRARY}
${OPENGL_gl_LIBRARY}
${GLEW_LIBRARY}
${ZLIB_LIBRARY}
${PLATFORM_LIBRARIES}

View File

@ -35,7 +35,6 @@ This binding only exists for testing purposes and does nothing (the engine quits
* Boost.Program_options
* libsigc++ 2.0
* PhysFS (latest hg)
* GLEW >= 1.7
* OpenAL
* SDL2
* SDL2_image

View File

@ -50,7 +50,7 @@ RGSS3 {
unix {
CONFIG += link_pkgconfig
PKGCONFIG += sigc++-2.0 glew pixman-1 zlib physfs \
PKGCONFIG += sigc++-2.0 pixman-1 zlib physfs \
sdl2 SDL2_image SDL2_ttf SDL_sound openal
RGSS2 {
@ -124,7 +124,8 @@ HEADERS += \
src/sharedstate.h \
src/al-util.h \
src/boost-hash.h \
src/debugwriter.h
src/debugwriter.h \
src/gl-fun.h
SOURCES += \
src/main.cpp \
@ -152,7 +153,8 @@ SOURCES += \
src/config.cpp \
src/tileatlas.cpp \
src/perftimer.cpp \
src/sharedstate.cpp
src/sharedstate.cpp \
src/gl-fun.cpp
EMBED = \
shader/transSimple.frag \

View File

@ -655,7 +655,7 @@ Color Bitmap::getPixel(int x, int y) const
glState.viewport.pushSet(IntRect(0, 0, width(), height()));
uint8_t pixel[4];
glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
gl.ReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
glState.viewport.pop();

View File

@ -22,9 +22,10 @@
#include "debuglogger.h"
#include "debugwriter.h"
#include <glew.h>
#include <iostream>
#include "gl-fun.h"
struct DebugLoggerPrivate
{
std::ostream *stream;
@ -53,25 +54,7 @@ struct DebugLoggerPrivate
}
};
static void amdDebugFunc(GLuint id,
GLenum category,
GLenum severity,
GLsizei length,
const GLchar* message,
GLvoid* userParam)
{
DebugLoggerPrivate *p = static_cast<DebugLoggerPrivate*>(userParam);
(void) id;
(void) category;
(void) severity;
(void) length;
p->writeTimestamp();
p->writeLine(message);
}
static void arbDebugFunc(GLenum source,
static void APIENTRY arbDebugFunc(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
@ -95,12 +78,8 @@ DebugLogger::DebugLogger(const char *filename)
{
p = new DebugLoggerPrivate(filename);
if (GLEW_KHR_debug)
glDebugMessageCallback(arbDebugFunc, p);
else if (GLEW_ARB_debug_output)
glDebugMessageCallbackARB(arbDebugFunc, p);
else if (GLEW_AMD_debug_output)
glDebugMessageCallbackAMD(amdDebugFunc, p);
if (gl.DebugMessageCallback)
gl.DebugMessageCallback(arbDebugFunc, p);
else
Debug() << "DebugLogger: no debug extensions found";
}

144
src/gl-fun.cpp Normal file
View File

@ -0,0 +1,144 @@
#include "gl-fun.h"
#include "boost-hash.h"
#include "exception.h"
#include <SDL_video.h>
#include <string>
GLFunctions gl;
typedef const GLubyte* (APIENTRYP PFNGLGETSTRINGIPROC) (GLenum, GLuint);
static void parseExtensionsCore(PFNGLGETINTEGERVPROC GetIntegerv, BoostSet<std::string> &out)
{
PFNGLGETSTRINGIPROC GetStringi =
(PFNGLGETSTRINGIPROC) SDL_GL_GetProcAddress("glGetStringi");
GLint extCount = 0;
GetIntegerv(GL_NUM_EXTENSIONS, &extCount);
for (GLint i = 0; i < extCount; ++i)
out.insert((const char*) GetStringi(GL_EXTENSIONS, i));
}
static void parseExtensionsCompat(PFNGLGETSTRINGPROC GetString, BoostSet<std::string> &out)
{
const char *ext = (const char*) GetString(GL_EXTENSIONS);
if (!ext)
return;
char buffer[0x100];
size_t bufferI;
while (*ext)
{
bufferI = 0;
while (*ext && *ext != ' ')
buffer[bufferI++] = *ext++;
buffer[bufferI] = '\0';
out.insert(buffer);
if (*ext == ' ')
++ext;
}
}
#define GL_FUN(name, type) \
gl.name = (type) SDL_GL_GetProcAddress("gl" #name EXT_SUFFIX);
#define EXC(msg) \
Exception(Exception::MKXPError, "%s", msg)
void initGLFunctions()
{
#define EXT_SUFFIX ""
GL_20_FUN;
/* Determine GL version */
const char *ver = (const char*) gl.GetString(GL_VERSION);
/* Assume single digit */
int glMajor = *ver - '0';
if (glMajor < 2)
throw EXC("At least OpenGL 2.0 is required");
BoostSet<std::string> ext;
if (glMajor >= 3)
parseExtensionsCore(gl.GetIntegerv, ext);
else
parseExtensionsCompat(gl.GetString, ext);
#define HAVE_EXT(_ext) ext.contains("GL_" #_ext)
if (!HAVE_EXT(ARB_framebuffer_object))
{
if (!(HAVE_EXT(EXT_framebuffer_object) && HAVE_EXT(EXT_framebuffer_blit)))
throw EXC("No FBO extensions available");
#undef EXT_SUFFIX
#define EXT_SUFFIX "EXT"
GL_FBO_FUN;
}
else
{
#undef EXT_SUFFIX
#define EXT_SUFFIX ""
GL_FBO_FUN;
}
if (!HAVE_EXT(ARB_vertex_array_object))
{
if (!HAVE_EXT(APPLE_vertex_array_object))
throw EXC("No VAO extensions available");
#undef EXT_SUFFIX
#define EXT_SUFFIX "APPLE"
GL_VAO_FUN;
}
else
{
#undef EXT_SUFFIX
#define EXT_SUFFIX ""
GL_VAO_FUN;
}
if (HAVE_EXT(ARB_timer_query))
{
gl.timerQuery = true;
#undef EXT_SUFFIX
#define EXT_SUFFIX ""
GL_TIMER_QUERY_FUN;
}
else if (HAVE_EXT(EXT_timer_query))
{
gl.timerQuery = true;
#undef EXT_SUFFIX
#define EXT_SUFFIX "EXT"
GL_TIMER_QUERY_FUN;
}
else
{
gl.timerQuery = false;
}
if (HAVE_EXT(KHR_debug))
{
#undef EXT_SUFFIX
#define EXT_SUFFIX ""
GL_DEBUG_KHR_FUN;
}
else if (HAVE_EXT(ARB_debug_output))
{
#undef EXT_SUFFIX
#define EXT_SUFFIX "ARB"
GL_DEBUG_KHR_FUN;
}
}

148
src/gl-fun.h Normal file
View File

@ -0,0 +1,148 @@
#ifndef GLFUN_H
#define GLFUN_H
#include <SDL_opengl.h>
/* Etc */
typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
typedef const GLubyte * (APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params);
typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
typedef void (APIENTRYP PFNGLBLENDFUNCPROC) (GLenum sfactor, GLenum dfactor);
typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
/* Texture */
typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
typedef void (APIENTRYP PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
/* Debug callback */
typedef void (APIENTRY * GLDEBUGPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, GLvoid* userParam);
typedef void (APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const GLvoid *userParam);
#define GL_20_FUN \
/* Etc */ \
GL_FUN(GetError, PFNGLGETERRORPROC) \
GL_FUN(ClearColor, PFNGLCLEARCOLORPROC) \
GL_FUN(Clear, PFNGLCLEARPROC) \
GL_FUN(GetString, PFNGLGETSTRINGPROC) \
GL_FUN(GetIntegerv, PFNGLGETINTEGERVPROC) \
GL_FUN(PixelStorei, PFNGLPIXELSTOREIPROC) \
GL_FUN(ReadPixels, PFNGLREADPIXELSPROC) \
GL_FUN(Enable, PFNGLENABLEPROC) \
GL_FUN(Disable, PFNGLDISABLEPROC) \
GL_FUN(Scissor, PFNGLSCISSORPROC) \
GL_FUN(Viewport, PFNGLVIEWPORTPROC) \
GL_FUN(BlendFunc, PFNGLBLENDFUNCPROC) \
GL_FUN(BlendFuncSeparate, PFNGLBLENDFUNCSEPARATEPROC) \
GL_FUN(BlendEquation, PFNGLBLENDEQUATIONPROC) \
GL_FUN(DrawElements, PFNGLDRAWELEMENTSPROC) \
/* Texture */ \
GL_FUN(GenTextures, PFNGLGENTEXTURESPROC) \
GL_FUN(DeleteTextures, PFNGLDELETETEXTURESPROC) \
GL_FUN(BindTexture, PFNGLBINDTEXTUREPROC) \
GL_FUN(TexImage2D, PFNGLTEXIMAGE2DPROC) \
GL_FUN(TexSubImage2D, PFNGLTEXSUBIMAGE2DPROC) \
GL_FUN(TexParameteri, PFNGLTEXPARAMETERIPROC) \
GL_FUN(ActiveTexture, PFNGLACTIVETEXTUREPROC) \
/* Buffer objcet */ \
GL_FUN(GenBuffers, PFNGLGENBUFFERSPROC) \
GL_FUN(DeleteBuffers, PFNGLDELETEBUFFERSPROC) \
GL_FUN(BindBuffer, PFNGLBINDBUFFERPROC) \
GL_FUN(BufferData, PFNGLBUFFERDATAPROC) \
GL_FUN(BufferSubData, PFNGLBUFFERSUBDATAPROC) \
/* Shader */ \
GL_FUN(CreateShader, PFNGLCREATESHADERPROC) \
GL_FUN(DeleteShader, PFNGLDELETESHADERPROC) \
GL_FUN(ShaderSource, PFNGLSHADERSOURCEPROC) \
GL_FUN(CompileShader, PFNGLCOMPILESHADERPROC) \
GL_FUN(AttachShader, PFNGLATTACHSHADERPROC) \
GL_FUN(GetObjectParameterivARB, PFNGLGETOBJECTPARAMETERIVARBPROC) \
GL_FUN(GetShaderiv, PFNGLGETSHADERIVPROC) \
GL_FUN(GetShaderInfoLog, PFNGLGETSHADERINFOLOGPROC) \
/* Program */ \
GL_FUN(CreateProgram, PFNGLCREATEPROGRAMPROC) \
GL_FUN(DeleteProgram, PFNGLDELETEPROGRAMPROC) \
GL_FUN(UseProgram, PFNGLUSEPROGRAMPROC) \
GL_FUN(LinkProgram, PFNGLLINKPROGRAMPROC) \
GL_FUN(GetProgramiv, PFNGLGETPROGRAMIVPROC) \
GL_FUN(GetProgramInfoLog, PFNGLGETPROGRAMINFOLOGPROC) \
/* Uniform */ \
GL_FUN(GetUniformLocation, PFNGLGETUNIFORMLOCATIONPROC) \
GL_FUN(Uniform1f, PFNGLUNIFORM1FPROC) \
GL_FUN(Uniform2f, PFNGLUNIFORM2FPROC) \
GL_FUN(Uniform4f, PFNGLUNIFORM4FPROC) \
GL_FUN(Uniform1i, PFNGLUNIFORM1IPROC) \
GL_FUN(UniformMatrix4fv, PFNGLUNIFORMMATRIX4FVPROC) \
/* Vertex attribute */ \
GL_FUN(BindAttribLocation, PFNGLBINDATTRIBLOCATIONPROC) \
GL_FUN(EnableVertexAttribArray, PFNGLENABLEVERTEXATTRIBARRAYPROC) \
GL_FUN(VertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC) \
/* Queries */ \
GL_FUN(GenQueries, PFNGLGENQUERIESPROC) \
GL_FUN(DeleteQueries, PFNGLDELETEQUERIESPROC) \
GL_FUN(BeginQuery, PFNGLBEGINQUERYPROC) \
GL_FUN(EndQuery, PFNGLENDQUERYPROC) \
GL_FUN(GetQueryObjectiv, PFNGLGETQUERYOBJECTIVPROC)
#define GL_FBO_FUN \
/* Framebuffer object */ \
GL_FUN(GenFramebuffers, PFNGLGENFRAMEBUFFERSPROC) \
GL_FUN(DeleteFramebuffers, PFNGLDELETEFRAMEBUFFERSPROC) \
GL_FUN(BindFramebuffer, PFNGLBINDFRAMEBUFFERPROC) \
GL_FUN(FramebufferTexture2D, PFNGLFRAMEBUFFERTEXTURE2DPROC) \
GL_FUN(FramebufferRenderbuffer, PFNGLFRAMEBUFFERRENDERBUFFERPROC) \
GL_FUN(BlitFramebuffer, PFNGLBLITFRAMEBUFFERPROC) \
/* Renderbuffer object */ \
GL_FUN(GenRenderbuffers, PFNGLGENRENDERBUFFERSPROC) \
GL_FUN(DeleteRenderbuffers, PFNGLDELETERENDERBUFFERSPROC) \
GL_FUN(BindRenderbuffer, PFNGLBINDRENDERBUFFERPROC) \
GL_FUN(RenderbufferStorage, PFNGLRENDERBUFFERSTORAGEPROC)
#define GL_VAO_FUN \
/* Vertex array object */ \
GL_FUN(GenVertexArrays, PFNGLGENVERTEXARRAYSPROC) \
GL_FUN(DeleteVertexArrays, PFNGLDELETEVERTEXARRAYSPROC) \
GL_FUN(BindVertexArray, PFNGLBINDVERTEXARRAYPROC)
#define GL_TIMER_QUERY_FUN \
GL_FUN(GetQueryObjecti64v, PFNGLGETQUERYOBJECTI64VPROC) \
GL_FUN(GetQueryObjectui64v, PFNGLGETQUERYOBJECTUI64VPROC)
#define GL_DEBUG_KHR_FUN \
GL_FUN(DebugMessageCallback, PFNGLDEBUGMESSAGECALLBACKPROC)
struct GLFunctions
{
#define GL_FUN(name, type) type name;
GL_20_FUN
GL_FBO_FUN
GL_VAO_FUN
bool timerQuery;
GL_TIMER_QUERY_FUN
GL_DEBUG_KHR_FUN
#undef GL_FUN
};
extern GLFunctions gl;
void initGLFunctions();
#endif // GLFUN_H

View File

@ -22,8 +22,7 @@
#ifndef GLUTIL_H
#define GLUTIL_H
#include <glew.h>
#include "gl-fun.h"
#include "etc-internal.h"
/* Struct wrapping GLuint for some light type safety */
@ -53,19 +52,19 @@ namespace TEX
inline ID gen()
{
ID id;
glGenTextures(1, &id.gl);
gl.GenTextures(1, &id.gl);
return id;
}
inline void del(ID id)
{
glDeleteTextures(1, &id.gl);
gl.DeleteTextures(1, &id.gl);
}
inline void bind(ID id)
{
glBindTexture(GL_TEXTURE_2D, id.gl);
gl.BindTexture(GL_TEXTURE_2D, id.gl);
}
inline void unbind()
@ -75,29 +74,29 @@ namespace TEX
inline void uploadImage(GLsizei width, GLsizei height, const void *data, GLenum format)
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, format, GL_UNSIGNED_BYTE, data);
gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, format, GL_UNSIGNED_BYTE, data);
}
inline void uploadSubImage(GLint x, GLint y, GLsizei width, GLsizei height, const void *data, GLenum format)
{
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, format, GL_UNSIGNED_BYTE, data);
gl.TexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, format, GL_UNSIGNED_BYTE, data);
}
inline void allocEmpty(GLsizei width, GLsizei height)
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
gl.TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
}
inline void setRepeat(bool mode)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode ? GL_REPEAT : GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode ? GL_REPEAT : GL_CLAMP_TO_EDGE);
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode ? GL_REPEAT : GL_CLAMP_TO_EDGE);
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode ? GL_REPEAT : GL_CLAMP_TO_EDGE);
}
inline void setSmooth(bool mode)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mode ? GL_LINEAR : GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mode ? GL_LINEAR : GL_NEAREST);
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mode ? GL_LINEAR : GL_NEAREST);
gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mode ? GL_LINEAR : GL_NEAREST);
}
}
@ -109,19 +108,19 @@ namespace RBO
inline ID gen()
{
ID id;
glGenRenderbuffers(1, &id.gl);
gl.GenRenderbuffers(1, &id.gl);
return id;
}
inline void del(ID id)
{
glDeleteRenderbuffers(1, &id.gl);
gl.DeleteRenderbuffers(1, &id.gl);
}
inline void bind(ID id)
{
glBindRenderbuffer(GL_RENDERBUFFER, id.gl);
gl.BindRenderbuffer(GL_RENDERBUFFER, id.gl);
}
inline void unbind()
@ -131,7 +130,7 @@ namespace RBO
inline void allocEmpty(GLsizei width, GLsizei height)
{
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height);
gl.RenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height);
}
}
@ -155,14 +154,14 @@ namespace FBO
inline ID gen()
{
ID id;
glGenFramebuffers(1, &id.gl);
gl.GenFramebuffers(1, &id.gl);
return id;
}
inline void del(ID id)
{
glDeleteFramebuffers(1, &id.gl);
gl.DeleteFramebuffers(1, &id.gl);
}
inline void bind(ID id, Mode mode)
@ -173,7 +172,7 @@ namespace FBO
GL_READ_FRAMEBUFFER
};
glBindFramebuffer(modes[mode], id.gl);
gl.BindFramebuffer(modes[mode], id.gl);
}
inline void unbind(Mode mode)
@ -183,12 +182,12 @@ namespace FBO
inline void setTarget(TEX::ID target, unsigned colorAttach = 0)
{
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorAttach, GL_TEXTURE_2D, target.gl, 0);
gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorAttach, GL_TEXTURE_2D, target.gl, 0);
}
inline void setTarget(RBO::ID target, unsigned colorAttach = 0)
{
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorAttach, GL_RENDERBUFFER, target.gl);
gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorAttach, GL_RENDERBUFFER, target.gl);
}
inline void blit(int srcX, int srcY,
@ -203,7 +202,7 @@ namespace FBO
GL_LINEAR
};
glBlitFramebuffer(srcX, srcY, srcX+srcW, srcY+srcH,
gl.BlitFramebuffer(srcX, srcY, srcX+srcW, srcY+srcH,
dstX, dstY, dstX+dstW, dstY+dstH,
GL_COLOR_BUFFER_BIT, modes[mode]);
}
@ -218,7 +217,7 @@ namespace FBO
inline void clear()
{
glClear(GL_COLOR_BUFFER_BIT);
gl.Clear(GL_COLOR_BUFFER_BIT);
}
}
@ -230,19 +229,19 @@ namespace VAO
inline ID gen()
{
ID id;
glGenVertexArrays(1, &id.gl);
gl.GenVertexArrays(1, &id.gl);
return id;
}
inline void del(ID id)
{
glDeleteVertexArrays(1, &id.gl);
gl.DeleteVertexArrays(1, &id.gl);
}
inline void bind(ID id)
{
glBindVertexArray(id.gl);
gl.BindVertexArray(id.gl);
}
inline void unbind()
@ -259,19 +258,19 @@ struct GenericBO
inline static ID gen()
{
ID id;
glGenBuffers(1, &id.gl);
gl.GenBuffers(1, &id.gl);
return id;
}
inline static void del(ID id)
{
glDeleteBuffers(1, &id.gl);
gl.DeleteBuffers(1, &id.gl);
}
inline static void bind(ID id)
{
glBindBuffer(target, id.gl);
gl.BindBuffer(target, id.gl);
}
inline static void unbind()
@ -281,12 +280,12 @@ struct GenericBO
inline static void uploadData(GLsizeiptr size, const GLvoid *data, GLenum usage = GL_STATIC_DRAW)
{
glBufferData(target, size, data, usage);
gl.BufferData(target, size, data, usage);
}
inline static void uploadSubData(GLintptr offset, GLsizeiptr size, const GLvoid *data)
{
glBufferSubData(target, offset, size, data);
gl.BufferSubData(target, offset, size, data);
}
inline static void allocEmpty(GLsizeiptr size, GLenum usage = GL_STATIC_DRAW)
@ -309,9 +308,9 @@ namespace PixelStore
* itself is part of a bigger image in client memory */
inline void setupSubImage(GLint imgWidth, GLint subX, GLint subY)
{
glPixelStorei(GL_UNPACK_ROW_LENGTH, imgWidth);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, subX);
glPixelStorei(GL_UNPACK_SKIP_ROWS, subY);
gl.PixelStorei(GL_UNPACK_ROW_LENGTH, imgWidth);
gl.PixelStorei(GL_UNPACK_SKIP_PIXELS, subX);
gl.PixelStorei(GL_UNPACK_SKIP_ROWS, subY);
}
/* Reset all states set with 'setupSubImage()' */

View File

@ -22,19 +22,18 @@
#include "glstate.h"
#include "shader.h"
#include "etc.h"
#include <glew.h>
#include "gl-fun.h"
#include <SDL_rect.h>
void GLClearColor::apply(const Vec4 &value)
{
glClearColor(value.x, value.y, value.z, value.w);
gl.ClearColor(value.x, value.y, value.z, value.w);
}
void GLScissorBox::apply(const IntRect &value)
{
glScissor(value.x, value.y, value.w, value.h);
gl.Scissor(value.x, value.y, value.w, value.h);
}
void GLScissorBox::setIntersect(const IntRect &value)
@ -53,7 +52,7 @@ void GLScissorBox::setIntersect(const IntRect &value)
void GLScissorTest::apply(const bool &value)
{
value ? glEnable(GL_SCISSOR_TEST) : glDisable(GL_SCISSOR_TEST);
value ? gl.Enable(GL_SCISSOR_TEST) : gl.Disable(GL_SCISSOR_TEST);
}
void GLBlendMode::apply(const BlendType &value)
@ -61,26 +60,26 @@ void GLBlendMode::apply(const BlendType &value)
switch (value)
{
case BlendNone :
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ZERO);
gl.BlendEquation(GL_FUNC_ADD);
gl.BlendFunc(GL_ONE, GL_ZERO);
break;
case BlendNormal :
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
gl.BlendEquation(GL_FUNC_ADD);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
break;
case BlendAddition :
glBlendEquation(GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
gl.BlendEquation(GL_FUNC_ADD);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
GL_ONE, GL_ONE);
break;
case BlendSubstraction :
// FIXME Alpha calculation is untested
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
gl.BlendEquation(GL_FUNC_REVERSE_SUBTRACT);
gl.BlendFuncSeparate(GL_SRC_ALPHA, GL_ONE,
GL_ONE, GL_ONE);
break;
}
@ -88,23 +87,23 @@ void GLBlendMode::apply(const BlendType &value)
void GLViewport::apply(const IntRect &value)
{
glViewport(value.x, value.y, value.w, value.h);
gl.Viewport(value.x, value.y, value.w, value.h);
}
void GLProgram::apply(const unsigned int &value)
{
glUseProgram(value);
gl.UseProgram(value);
}
GLState::Caps::Caps()
{
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
gl.GetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
}
GLState::GLState()
{
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
gl.Enable(GL_BLEND);
gl.Disable(GL_DEPTH_TEST);
clearColor.init(Vec4(0, 0, 0, 1));
blendMode.init(BlendNormal);

View File

@ -60,7 +60,7 @@ struct PingPong
TEXFBO::init(rt[i]);
TEXFBO::allocEmpty(rt[i], screenW, screenH);
TEXFBO::linkFBO(rt[i]);
glClearColor(0, 0, 0, 1);
gl.ClearColor(0, 0, 0, 1);
FBO::clear();
}
}

View File

@ -19,7 +19,6 @@
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/
#include <glew.h>
#include <alc.h>
#include <SDL.h>
@ -34,6 +33,7 @@
#include "debuglogger.h"
#include "debugwriter.h"
#include "exception.h"
#include "gl-fun.h"
#include "binding.h"
@ -50,7 +50,7 @@ rgssThreadError(RGSSThreadData *rtData, const std::string &msg)
static inline const char*
glGetStringInt(GLenum name)
{
return (const char*) glGetString(name);
return (const char*) gl.GetString(name);
}
static void
@ -62,60 +62,6 @@ printGLInfo()
Debug() << "GLSL Version :" << glGetStringInt(GL_SHADING_LANGUAGE_VERSION);
}
static bool
setupOptionalGLExtensions(RGSSThreadData* threadData)
{
if (!GLEW_ARB_framebuffer_object)
{
if (!GLEW_EXT_framebuffer_object && !GLEW_EXT_framebuffer_blit)
{
rgssThreadError(threadData, "GL extensions \"GL_ARB_framebuffer_object\" or compatible extensiosns GL_EXT_framebuffer_object and GL_EXT_framebuffer_blit are not present");
return false;
}
else
{
/* setup compat */
/* From EXT_framebuffer_object */
glGenRenderbuffers = glGenRenderbuffersEXT;
glDeleteRenderbuffers = glDeleteRenderbuffersEXT;
glBindRenderbuffer = glBindRenderbufferEXT;
glRenderbufferStorage = glRenderbufferStorageEXT;
glGenFramebuffers = glGenFramebuffersEXT;
glDeleteFramebuffers = glDeleteFramebuffersEXT;
glBindFramebuffer = glBindFramebufferEXT;
glFramebufferTexture2D = glFramebufferTexture2DEXT;
glFramebufferRenderbuffer = glFramebufferRenderbufferEXT;
/* From EXT_framebuffer_blit */
glBlitFramebuffer = glBlitFramebufferEXT;
}
}
if (!GLEW_ARB_timer_query && GLEW_EXT_timer_query)
{
glGetQueryObjecti64v = glGetQueryObjecti64vEXT;
glGetQueryObjectui64v = glGetQueryObjectui64vEXT;
}
if (!GLEW_ARB_vertex_array_object )
{
if (!GLEW_APPLE_vertex_array_object)
{
rgssThreadError(threadData, "GL extensions \"GL_ARB_vertex_array_object\" or compatible extensions GL_APPLE_vertex_array_object are not present");
return false;
}
else
{
/* setup compat */
glBindVertexArray = glBindVertexArrayAPPLE;
/* the cast is because apple's uses const GLuint* and ARB doesn't */
glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)glGenVertexArraysAPPLE;
glDeleteVertexArrays = glDeleteVertexArraysAPPLE;
}
}
return true;
}
int rgssThreadFun(void *userdata)
{
RGSSThreadData *threadData = static_cast<RGSSThreadData*>(userdata);
@ -136,36 +82,24 @@ int rgssThreadFun(void *userdata)
return 0;
}
if (glewInit() != GLEW_OK)
try
{
rgssThreadError(threadData, "Error initializing glew");
initGLFunctions();
}
catch (const Exception &exc)
{
rgssThreadError(threadData, exc.msg);
SDL_GL_DeleteContext(glCtx);
return 0;
}
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
gl.ClearColor(0, 0, 0, 1);
gl.Clear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(win);
printGLInfo();
/* Check for required GL version */
if (!GLEW_VERSION_2_0)
{
rgssThreadError(threadData, "At least OpenGL 2.0 is required");
SDL_GL_DeleteContext(glCtx);
return 0;
}
/* Setup optional GL extensions */
if (!setupOptionalGLExtensions(threadData))
{
SDL_GL_DeleteContext(glCtx);
return 0;
}
SDL_GL_SetSwapInterval(threadData->config.vsync ? 1 : 0);
DebugLogger dLogger;

View File

@ -1,8 +1,8 @@
#include "perftimer.h"
#include <SDL_timer.h>
#include <glew.h>
#include "gl-fun.h"
#include "debugwriter.h"
struct TimerQuery
@ -14,7 +14,7 @@ struct TimerQuery
TimerQuery()
: thisQueryActive(false)
{
glGenQueries(1, &query);
gl.GenQueries(1, &query);
}
void begin()
@ -25,7 +25,7 @@ struct TimerQuery
if (thisQueryActive)
return;
glBeginQuery(GL_TIME_ELAPSED, query);
gl.BeginQuery(GL_TIME_ELAPSED, query);
queryActive = true;
thisQueryActive = true;
}
@ -35,7 +35,7 @@ struct TimerQuery
if (!thisQueryActive)
return;
glEndQuery(GL_TIME_ELAPSED);
gl.EndQuery(GL_TIME_ELAPSED);
queryActive = false;
thisQueryActive = false;
}
@ -46,14 +46,14 @@ struct TimerQuery
return false;
GLint isReady = GL_FALSE;
glGetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, &isReady);
gl.GetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, &isReady);
if (isReady != GL_TRUE)
return false;
glGetQueryObjectui64v(query, GL_QUERY_RESULT, result);
gl.GetQueryObjectui64v(query, GL_QUERY_RESULT, result);
if (glGetError() == GL_INVALID_OPERATION)
if (gl.GetError() == GL_INVALID_OPERATION)
return false;
return true;
@ -68,9 +68,9 @@ struct TimerQuery
GLint isReady = GL_FALSE;
while (isReady == GL_FALSE)
glGetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, &isReady);
gl.GetQueryObjectiv(query, GL_QUERY_RESULT_AVAILABLE, &isReady);
glGetQueryObjectui64v(query, GL_QUERY_RESULT, &result);
gl.GetQueryObjectui64v(query, GL_QUERY_RESULT, &result);
return result;
}
@ -80,7 +80,7 @@ struct TimerQuery
if (thisQueryActive)
end();
glDeleteQueries(1, &query);
gl.DeleteQueries(1, &query);
}
};
@ -193,7 +193,7 @@ PerfTimer *createCPUTimer(int iter)
PerfTimer *createGPUTimer(int iter)
{
if (GLEW_ARB_timer_query || GLEW_EXT_timer_query)
if (gl.timerQuery)
{
return new GPUTimerGLQuery(iter);
}

View File

@ -22,7 +22,6 @@
#ifndef QUAD_H
#define QUAD_H
#include "glew.h"
#include "etc-internal.h"
#include "gl-util.h"
#include "sharedstate.h"
@ -114,13 +113,13 @@ struct Quad
VBO::allocEmpty(sizeof(Vertex[4]), GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(Shader::Color);
glEnableVertexAttribArray(Shader::Position);
glEnableVertexAttribArray(Shader::TexCoord);
gl.EnableVertexAttribArray(Shader::Color);
gl.EnableVertexAttribArray(Shader::Position);
gl.EnableVertexAttribArray(Shader::TexCoord);
glVertexAttribPointer(Shader::Color, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::colorOffset());
glVertexAttribPointer(Shader::Position, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::posOffset());
glVertexAttribPointer(Shader::TexCoord, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::texPosOffset());
gl.VertexAttribPointer(Shader::Color, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::colorOffset());
gl.VertexAttribPointer(Shader::Position, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::posOffset());
gl.VertexAttribPointer(Shader::TexCoord, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::texPosOffset());
VAO::unbind();
VBO::unbind();
@ -177,7 +176,7 @@ struct Quad
}
VAO::bind(vao);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
gl.DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
VAO::unbind();
}
};

View File

@ -37,22 +37,22 @@ typedef uint32_t index_t;
/* A small hack to get mutable QuadArray constructors */
inline void initBufferBindings(Vertex *)
{
glEnableVertexAttribArray(Shader::Color);
glEnableVertexAttribArray(Shader::Position);
glEnableVertexAttribArray(Shader::TexCoord);
gl.EnableVertexAttribArray(Shader::Color);
gl.EnableVertexAttribArray(Shader::Position);
gl.EnableVertexAttribArray(Shader::TexCoord);
glVertexAttribPointer(Shader::Color, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::colorOffset());
glVertexAttribPointer(Shader::Position, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::posOffset());
glVertexAttribPointer(Shader::TexCoord, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::texPosOffset());
gl.VertexAttribPointer(Shader::Color, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::colorOffset());
gl.VertexAttribPointer(Shader::Position, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::posOffset());
gl.VertexAttribPointer(Shader::TexCoord, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), Vertex::texPosOffset());
}
inline void initBufferBindings(SVertex *)
{
glEnableVertexAttribArray(Shader::Position);
glEnableVertexAttribArray(Shader::TexCoord);
gl.EnableVertexAttribArray(Shader::Position);
gl.EnableVertexAttribArray(Shader::TexCoord);
glVertexAttribPointer(Shader::Position, 2, GL_FLOAT, GL_FALSE, sizeof(SVertex), SVertex::posOffset());
glVertexAttribPointer(Shader::TexCoord, 2, GL_FLOAT, GL_FALSE, sizeof(SVertex), SVertex::texPosOffset());
gl.VertexAttribPointer(Shader::Position, 2, GL_FLOAT, GL_FALSE, sizeof(SVertex), SVertex::posOffset());
gl.VertexAttribPointer(Shader::TexCoord, 2, GL_FLOAT, GL_FALSE, sizeof(SVertex), SVertex::texPosOffset());
}
template<class VertexType>
@ -135,7 +135,7 @@ struct QuadArray
VAO::bind(vao);
const char *_offset = (const char*) 0 + offset * 6 * sizeof(index_t);
glDrawElements(GL_TRIANGLES, count * 6, _GL_INDEX_TYPE, _offset);
gl.DrawElements(GL_TRIANGLES, count * 6, _GL_INDEX_TYPE, _offset);
VAO::unbind();
}

View File

@ -24,8 +24,6 @@
#include "glstate.h"
#include "exception.h"
#include <glew.h>
#include <assert.h>
#include <iostream>
@ -57,15 +55,15 @@
#vert, #frag, #name); \
}
#define GET_U(name) u_##name = glGetUniformLocation(program, #name)
#define GET_U(name) u_##name = gl.GetUniformLocation(program, #name)
static void printShaderLog(GLuint shader)
{
GLint logLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
gl.GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
std::string log(logLength, '\0');
glGetShaderInfoLog(shader, log.size(), 0, &log[0]);
gl.GetShaderInfoLog(shader, log.size(), 0, &log[0]);
std::clog << "Shader log:\n" << log;
}
@ -73,28 +71,28 @@ static void printShaderLog(GLuint shader)
static void printProgramLog(GLuint program)
{
GLint logLength;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
gl.GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
std::string log(logLength, '\0');
glGetProgramInfoLog(program, log.size(), 0, &log[0]);
gl.GetProgramInfoLog(program, log.size(), 0, &log[0]);
std::clog << "Program log:\n" << log;
}
Shader::Shader()
{
vertShader = glCreateShader(GL_VERTEX_SHADER);
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
vertShader = gl.CreateShader(GL_VERTEX_SHADER);
fragShader = gl.CreateShader(GL_FRAGMENT_SHADER);
program = glCreateProgram();
program = gl.CreateProgram();
}
Shader::~Shader()
{
glUseProgram(0);
glDeleteProgram(program);
glDeleteShader(vertShader);
glDeleteShader(fragShader);
gl.UseProgram(0);
gl.DeleteProgram(program);
gl.DeleteShader(vertShader);
gl.DeleteShader(fragShader);
}
void Shader::bind()
@ -104,7 +102,7 @@ void Shader::bind()
void Shader::unbind()
{
glActiveTexture(GL_TEXTURE0);
gl.ActiveTexture(GL_TEXTURE0);
glState.program.set(0);
}
@ -116,10 +114,10 @@ void Shader::init(const unsigned char *vert, int vertSize,
GLint success;
/* Compile vertex shader */
glShaderSource(vertShader, 1, (const GLchar**) &vert, (const GLint*) &vertSize);
glCompileShader(vertShader);
gl.ShaderSource(vertShader, 1, (const GLchar**) &vert, (const GLint*) &vertSize);
gl.CompileShader(vertShader);
glGetObjectParameterivARB(vertShader, GL_COMPILE_STATUS, &success);
gl.GetObjectParameterivARB(vertShader, GL_COMPILE_STATUS, &success);
if (!success)
{
@ -130,10 +128,10 @@ void Shader::init(const unsigned char *vert, int vertSize,
}
/* Compile fragment shader */
glShaderSource(fragShader, 1, (const GLchar**) &frag, (const GLint*) &fragSize);
glCompileShader(fragShader);
gl.ShaderSource(fragShader, 1, (const GLchar**) &frag, (const GLint*) &fragSize);
gl.CompileShader(fragShader);
glGetObjectParameterivARB(fragShader, GL_COMPILE_STATUS, &success);
gl.GetObjectParameterivARB(fragShader, GL_COMPILE_STATUS, &success);
if (!success)
{
@ -144,16 +142,16 @@ void Shader::init(const unsigned char *vert, int vertSize,
}
/* Link shader program */
glAttachShader(program, vertShader);
glAttachShader(program, fragShader);
gl.AttachShader(program, vertShader);
gl.AttachShader(program, fragShader);
glBindAttribLocation(program, Position, "position");
glBindAttribLocation(program, TexCoord, "texCoord");
glBindAttribLocation(program, Color, "color");
gl.BindAttribLocation(program, Position, "position");
gl.BindAttribLocation(program, TexCoord, "texCoord");
gl.BindAttribLocation(program, Color, "color");
glLinkProgram(program);
gl.LinkProgram(program);
glGetObjectParameterivARB(program, GL_LINK_STATUS, &success);
gl.GetObjectParameterivARB(program, GL_LINK_STATUS, &success);
if (!success)
{
@ -178,17 +176,17 @@ void Shader::initFromFile(const char *_vertFile, const char *_fragFile,
void Shader::setVec4Uniform(GLint location, const Vec4 &vec)
{
glUniform4f(location, vec.x, vec.y, vec.z, vec.w);
gl.Uniform4f(location, vec.x, vec.y, vec.z, vec.w);
}
void Shader::setTexUniform(GLint location, unsigned unitIndex, TEX::ID texture)
{
GLenum texUnit = GL_TEXTURE0 + unitIndex;
glActiveTexture(texUnit);
glBindTexture(GL_TEXTURE_2D, texture.gl);
glUniform1i(location, unitIndex);
glActiveTexture(GL_TEXTURE0);
gl.ActiveTexture(texUnit);
gl.BindTexture(GL_TEXTURE_2D, texture.gl);
gl.Uniform1i(location, unitIndex);
gl.ActiveTexture(GL_TEXTURE0);
}
void ShaderBase::GLProjMat::apply(const Vec2i &value)
@ -206,7 +204,7 @@ void ShaderBase::GLProjMat::apply(const Vec2i &value)
-1, -1, -1, 1
};
glUniformMatrix4fv(u_mat, 1, GL_FALSE, mat);
gl.UniformMatrix4fv(u_mat, 1, GL_FALSE, mat);
}
void ShaderBase::init()
@ -214,7 +212,7 @@ void ShaderBase::init()
GET_U(texSizeInv);
GET_U(translation);
projMat.u_mat = glGetUniformLocation(program, "projMat");
projMat.u_mat = gl.GetUniformLocation(program, "projMat");
}
void ShaderBase::applyViewportProj()
@ -225,12 +223,12 @@ void ShaderBase::applyViewportProj()
void ShaderBase::setTexSize(const Vec2i &value)
{
glUniform2f(u_texSizeInv, 1.f / value.x, 1.f / value.y);
gl.Uniform2f(u_texSizeInv, 1.f / value.x, 1.f / value.y);
}
void ShaderBase::setTranslation(const Vec2i &value)
{
glUniform2f(u_translation, value.x, value.y);
gl.Uniform2f(u_translation, value.x, value.y);
}
@ -245,7 +243,7 @@ SimpleShader::SimpleShader()
void SimpleShader::setTexOffsetX(int value)
{
glUniform1f(u_texOffsetX, value);
gl.Uniform1f(u_texOffsetX, value);
}
@ -276,7 +274,7 @@ SimpleSpriteShader::SimpleSpriteShader()
void SimpleSpriteShader::setSpriteMat(const float value[16])
{
glUniformMatrix4fv(u_spriteMat, 1, GL_FALSE, value);
gl.UniformMatrix4fv(u_spriteMat, 1, GL_FALSE, value);
}
@ -310,12 +308,12 @@ void TransShader::setTransMap(TEX::ID tex)
void TransShader::setProg(float value)
{
glUniform1f(u_prog, value);
gl.Uniform1f(u_prog, value);
}
void TransShader::setVague(float value)
{
glUniform1f(u_vague, value);
gl.Uniform1f(u_vague, value);
}
@ -342,7 +340,7 @@ void SimpleTransShader::setFrozenScene(TEX::ID tex)
void SimpleTransShader::setProg(float value)
{
glUniform1f(u_prog, value);
gl.Uniform1f(u_prog, value);
}
@ -362,7 +360,7 @@ SpriteShader::SpriteShader()
void SpriteShader::setSpriteMat(const float value[16])
{
glUniformMatrix4fv(u_spriteMat, 1, GL_FALSE, value);
gl.UniformMatrix4fv(u_spriteMat, 1, GL_FALSE, value);
}
void SpriteShader::setTone(const Vec4 &tone)
@ -377,17 +375,17 @@ void SpriteShader::setColor(const Vec4 &color)
void SpriteShader::setOpacity(float value)
{
glUniform1f(u_opacity, value);
gl.Uniform1f(u_opacity, value);
}
void SpriteShader::setBushDepth(float value)
{
glUniform1f(u_bushDepth, value);
gl.Uniform1f(u_bushDepth, value);
}
void SpriteShader::setBushOpacity(float value)
{
glUniform1f(u_bushOpacity, value);
gl.Uniform1f(u_bushOpacity, value);
}
@ -420,7 +418,7 @@ void PlaneShader::setFlash(const Vec4 &flash)
void PlaneShader::setOpacity(float value)
{
glUniform1f(u_opacity, value);
gl.Uniform1f(u_opacity, value);
}
@ -435,7 +433,7 @@ FlashMapShader::FlashMapShader()
void FlashMapShader::setAlpha(float value)
{
glUniform1f(u_alpha, value);
gl.Uniform1f(u_alpha, value);
}
@ -451,7 +449,7 @@ HueShader::HueShader()
void HueShader::setHueAdjust(float value)
{
glUniform1f(u_hueAdjust, value);
gl.Uniform1f(u_hueAdjust, value);
}
void HueShader::setInputTexture(TEX::ID tex)
@ -473,7 +471,7 @@ SimpleMatrixShader::SimpleMatrixShader()
void SimpleMatrixShader::setMatrix(const float value[16])
{
glUniformMatrix4fv(u_matrix, 1, GL_FALSE, value);
gl.UniformMatrix4fv(u_matrix, 1, GL_FALSE, value);
}
@ -508,7 +506,7 @@ BltShader::BltShader()
void BltShader::setSource()
{
glUniform1i(u_source, 0);
gl.Uniform1i(u_source, 0);
}
void BltShader::setDestination(const TEX::ID value)
@ -518,10 +516,10 @@ void BltShader::setDestination(const TEX::ID value)
void BltShader::setSubRect(const FloatRect &value)
{
glUniform4f(u_subRect, value.x, value.y, value.w, value.h);
gl.Uniform4f(u_subRect, value.x, value.y, value.w, value.h);
}
void BltShader::setOpacity(float value)
{
glUniform1f(u_opacity, value);
gl.Uniform1f(u_opacity, value);
}

View File

@ -393,14 +393,14 @@ struct TilemapPrivate
tiles.vao = VAO::gen();
VAO::bind(tiles.vao);
glEnableVertexAttribArray(Shader::Position);
glEnableVertexAttribArray(Shader::TexCoord);
gl.EnableVertexAttribArray(Shader::Position);
gl.EnableVertexAttribArray(Shader::TexCoord);
VBO::bind(tiles.vbo);
shState->bindQuadIBO();
glVertexAttribPointer(Shader::Position, 2, GL_FLOAT, GL_FALSE, sizeof(SVertex), SVertex::posOffset());
glVertexAttribPointer(Shader::TexCoord, 2, GL_FLOAT, GL_FALSE, sizeof(SVertex), SVertex::texPosOffset());
gl.VertexAttribPointer(Shader::Position, 2, GL_FLOAT, GL_FALSE, sizeof(SVertex), SVertex::posOffset());
gl.VertexAttribPointer(Shader::TexCoord, 2, GL_FLOAT, GL_FALSE, sizeof(SVertex), SVertex::texPosOffset());
VAO::unbind();
VBO::unbind();
@ -414,14 +414,14 @@ struct TilemapPrivate
VAO::bind(flash.vao);
glEnableVertexAttribArray(Shader::Color);
glEnableVertexAttribArray(Shader::Position);
gl.EnableVertexAttribArray(Shader::Color);
gl.EnableVertexAttribArray(Shader::Position);
VBO::bind(flash.vbo);
shState->bindQuadIBO();
glVertexAttribPointer(Shader::Color, 4, GL_FLOAT, GL_FALSE, sizeof(CVertex), CVertex::colorOffset());
glVertexAttribPointer(Shader::Position, 2, GL_FLOAT, GL_FALSE, sizeof(CVertex), CVertex::posOffset());
gl.VertexAttribPointer(Shader::Color, 4, GL_FLOAT, GL_FALSE, sizeof(CVertex), CVertex::colorOffset());
gl.VertexAttribPointer(Shader::Position, 2, GL_FLOAT, GL_FALSE, sizeof(CVertex), CVertex::posOffset());
VAO::unbind();
VBO::unbind();
@ -1162,13 +1162,13 @@ void GroundLayer::draw()
void GroundLayer::drawInt()
{
glDrawElements(GL_TRIANGLES, vboCount,
gl.DrawElements(GL_TRIANGLES, vboCount,
GL_UNSIGNED_INT, (GLvoid*) (p->tiles.frameIdx * p->tiles.bufferFrameSize));
}
void GroundLayer::drawFlashInt()
{
glDrawElements(GL_TRIANGLES, p->flash.quadCount * 6, GL_UNSIGNED_INT, 0);
gl.DrawElements(GL_TRIANGLES, p->flash.quadCount * 6, GL_UNSIGNED_INT, 0);
}
void GroundLayer::onGeometryChange(const Scene::Geometry &geo)
@ -1220,7 +1220,7 @@ void ScanRow::draw()
void ScanRow::drawInt()
{
glDrawElements(GL_TRIANGLES, vboBatchCount,
gl.DrawElements(GL_TRIANGLES, vboBatchCount,
GL_UNSIGNED_INT, (GLvoid*) (vboOffset + p->tiles.frameIdx * p->tiles.bufferFrameSize));
}