| 1 |
/** |
| 2 |
* Graphics primitives with OpenGL (ES) 2 |
| 3 |
|
| 4 |
* Copyright (C) 2015 Sylvain Beucler |
| 5 |
|
| 6 |
* This file is part of GNU FreeDink |
| 7 |
|
| 8 |
* GNU FreeDink is free software: you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU Affero General Public License |
| 10 |
* as published by the Free Software Foundation, either version 3 of |
| 11 |
* the License, or (at your option) any later version. |
| 12 |
|
| 13 |
* GNU FreeDink is distributed in the hope that it will be useful, but |
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* Affero General Public License for more details. |
| 17 |
|
| 18 |
* You should have received a copy of the GNU Affero General Public |
| 19 |
* License along with GNU FreeDink. If not, see |
| 20 |
* <http://www.gnu.org/licenses/>. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef IOGRAPHICS_H |
| 24 |
#define IOGRAPHICS_H |
| 25 |
|
| 26 |
#include "SDL.h" |
| 27 |
|
| 28 |
#include "IOGfxDisplay.h" |
| 29 |
#include "IOGfxGLFuncs.h" |
| 30 |
|
| 31 |
#include <map> |
| 32 |
#include <string> |
| 33 |
|
| 34 |
|
| 35 |
class IOGfxGLFuncs; |
| 36 |
|
| 37 |
class IOGfxGLProg { |
| 38 |
public: |
| 39 |
const GLchar* vshader; |
| 40 |
const GLchar* fshader; |
| 41 |
GLuint program; |
| 42 |
std::map<std::string, GLint> uniforms; |
| 43 |
std::map<std::string, GLint> attributes; |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
class IOGfxDisplayGL2 : public IOGfxDisplay { |
| 48 |
public: |
| 49 |
SDL_GLContext glcontext; |
| 50 |
IOGfxGLFuncs* gl; |
| 51 |
SDL_Texture* screen; |
| 52 |
GLuint palette; |
| 53 |
|
| 54 |
IOGfxGLProg *blit, *fliprgb, *flippal, *fillRect; |
| 55 |
|
| 56 |
GLuint vboSpriteVertices, vboSpriteTexcoords, vboCroppedSpriteTexcoords; |
| 57 |
|
| 58 |
|
| 59 |
IOGfxDisplayGL2(int w, int h, bool truecolor, Uint32 flags); |
| 60 |
~IOGfxDisplayGL2(); |
| 61 |
|
| 62 |
virtual bool open(); |
| 63 |
virtual void close(); |
| 64 |
virtual void logDisplayInfo(); |
| 65 |
|
| 66 |
virtual void clear(); |
| 67 |
virtual void onSizeChange(int w, int h); |
| 68 |
virtual IOGfxSurface* upload(SDL_Surface* image); |
| 69 |
virtual IOGfxSurface* allocBuffer(int surfW, int surfH); |
| 70 |
virtual void flip(IOGfxSurface* backbuffer, SDL_Rect* dstrect, |
| 71 |
bool interpolation, bool hwflip); |
| 72 |
virtual void updatePalette(); |
| 73 |
|
| 74 |
virtual SDL_Surface* screenshot(SDL_Rect* rect); |
| 75 |
|
| 76 |
bool createOpenGLContext(); |
| 77 |
void logOpenGLInfo(); |
| 78 |
|
| 79 |
bool createSpriteVertices(); |
| 80 |
bool createSpriteTexcoords(); |
| 81 |
bool createCroppedSpriteTexcoords(); |
| 82 |
GLuint createShader(const char* name, const char* source, GLenum type); |
| 83 |
void infoLog(GLuint object); |
| 84 |
bool createPrograms(); |
| 85 |
GLuint createProgram(const char* name, const char* vertexShaderSource, const char* fragmentShaderSource); |
| 86 |
GLint getAttribLocation(GLuint program, const char* name); |
| 87 |
GLint getUniformLocation(GLuint program, const char* name); |
| 88 |
void setVertexAttrib(IOGfxGLProg* prog, GLuint attribLocation, GLuint vbo, GLint size); |
| 89 |
bool createPalette(); |
| 90 |
}; |
| 91 |
|
| 92 |
#endif |