OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OpenGL.h
1 // This file was copied from the bsnes project.
2 
3 // This is the license info, from ruby.hpp:
4 
5 /*
6  ruby
7  version: 0.08 (2011-11-25)
8  license: public domain
9 */
10 #ifndef OXC_OPENGL_H
11 #define OXC_OPENGL_H
12 
13 #ifndef __NO_OPENGL
14 
15 #include <SDL.h>
16 #include <SDL_opengl.h>
17 #include <string>
18 
19 namespace OpenXcom
20 {
21 
22 class Surface;
23 
24 #ifndef __APPLE__
25 extern PFNGLCREATEPROGRAMPROC glCreateProgram;
26 extern PFNGLUSEPROGRAMPROC glUseProgram;
27 extern PFNGLCREATESHADERPROC glCreateShader;
28 extern PFNGLDELETESHADERPROC glDeleteShader;
29 extern PFNGLSHADERSOURCEPROC glShaderSource;
30 extern PFNGLCOMPILESHADERPROC glCompileShader;
31 extern PFNGLATTACHSHADERPROC glAttachShader;
32 extern PFNGLDETACHSHADERPROC glDetachShader;
33 extern PFNGLLINKPROGRAMPROC glLinkProgram;
34 extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
35 extern PFNGLUNIFORM1IPROC glUniform1i;
36 extern PFNGLUNIFORM2FVPROC glUniform2fv;
37 extern PFNGLUNIFORM4FVPROC glUniform4fv;
38 #endif
39 
40 std::string strGLError(GLenum glErr);
41 
42 #define glErrorCheck() {\
43  static bool reported = false;\
44  GLenum glErr;\
45  if (OpenGL::checkErrors && !reported && (glErr = glGetError()) != GL_NO_ERROR)\
46  {\
47  reported = true;\
48  \
49  do \
50  { \
51  Log(LOG_WARNING) << __FILE__ << ":" << __LINE__ << ": glGetError() complaint: " << strGLError(glErr);\
52  } while (((glErr = glGetError()) != GL_NO_ERROR));\
53  }\
54 }
55 
56 
57 class OpenGL {
58 public:
59  GLuint gltexture;
60  GLuint glprogram;
61  GLuint fragmentshader;
62  bool linear;
63  GLuint vertexshader;
64  bool shader_support;
65 
66  uint32_t *buffer;
67  Surface *buffer_surface;
68  unsigned iwidth, iheight, iformat, ibpp;
69 
70  static bool checkErrors;
71 
73  void resize(unsigned width, unsigned height);
75  bool lock(uint32_t *&data, unsigned &pitch);
77  void clear();
79  void refresh(bool smooth, unsigned inwidth, unsigned inheight, unsigned outwidth, unsigned outheight, int topBlackBand, int bottomBlackBand, int leftBlackBand, int rightBlackBand);
81  void set_shader(const char *source);
83  void set_fragment_shader(const char *source);
85  void set_vertex_shader(const char *source);
87  void init(int width, int height);
89  void term();
91  void setVSync(bool sync);
93  OpenGL();
94  ~OpenGL();
95 };
96 
97 }
98 
99 #else
100 
101 namespace OpenXcom { class OpenGL {}; }
102 
103 #endif
104 
105 #endif
void set_vertex_shader(const char *source)
and vertex?
Definition: OpenGL.cpp:257
void set_fragment_shader(const char *source)
same but for fragment shader?
Definition: OpenGL.cpp:250
OpenGL()
constructor – like we said, we're too cool to actually construct things
Definition: OpenGL.cpp:345
void resize(unsigned width, unsigned height)
call to resize internal buffer; internal use
Definition: OpenGL.cpp:104
void init(int width, int height)
init(), because we're too cool to initialize everything in the constructor
Definition: OpenGL.cpp:264
void term()
more like exit, because destructors are for uncool people
Definition: OpenGL.cpp:330
bool lock(uint32_t *&data, unsigned &pitch)
actually returns pointer to data buffer where one is to write the image
Definition: OpenGL.cpp:126
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
void setVSync(bool sync)
Try to set VSync!
Definition: OpenGL.cpp:311
Definition: OpenGL.h:57
void set_shader(const char *source)
set a shader! but what kind?
Definition: OpenGL.cpp:214
void clear()
make all the pixels go away
Definition: OpenGL.cpp:131
void refresh(bool smooth, unsigned inwidth, unsigned inheight, unsigned outwidth, unsigned outheight, int topBlackBand, int bottomBlackBand, int leftBlackBand, int rightBlackBand)
make the buffer show up on screen
Definition: OpenGL.cpp:139