Welcome to mirror list, hosted at ThFree Co, Russian Federation.

opengl.hpp « opengl « graphics - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 17f7021310941f0b274f480b9e531a77edc7e730 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#pragma once

#include "../../std/target_os.hpp"
#include "../../base/logging.hpp"

#include "../../base/logging.hpp"

#if defined(OMIM_OS_WINDOWS)
  #include "../../std/windows.hpp"
  #include <gl/gl.h>
  #define GL_GLEXT_PROTOTYPES
  #include "../../3party/GL/glext.h"

#elif defined(OMIM_OS_BADA)
  #include <FGraphicsOpengl.h>
  using namespace Osp::Graphics::Opengl;
  #define OMIM_GL_ES

#elif defined(OMIM_OS_MAC) || defined(OMIM_OS_IPHONE)
  #include <TargetConditionals.h>

  #ifdef OMIM_OS_IPHONE
    #define USE_OPENGLES20_IF_AVAILABLE 1
    #include <OpenGLES/ES2/gl.h>
    #define OMIM_GL_ES
  #else
    #include <OpenGL/gl.h>
    #include <OpenGL/glext.h>
  #endif

#elif defined(OMIM_OS_ANDROID)

  #include <GLES2/gl2.h>

  #define OMIM_GL_ES

#else
  #define GL_GLEXT_PROTOTYPES
  #include <GL/gl.h>
  #include <GL/glext.h>
#endif


#ifdef OMIM_OS_WINDOWS
  #define OPENGL_CALLING_CONVENTION __stdcall
#else
  #define OPENGL_CALLING_CONVENTION
#endif


#include "../../base/src_point.hpp"
#include "../../std/exception.hpp"


namespace graphics
{
  namespace gl
  {
    // basic opengl functions and constants
    extern void (OPENGL_CALLING_CONVENTION * glEnableFn)(GLenum cap);
    extern void (OPENGL_CALLING_CONVENTION * glDisableFn)(GLenum cap);
    extern void (OPENGL_CALLING_CONVENTION * glAlphaFuncFn)(GLenum func, GLclampf ref);
    extern void (OPENGL_CALLING_CONVENTION * glEnableClientStateFn) (GLenum array);
    extern void (OPENGL_CALLING_CONVENTION * glVertexPointerFn) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
    extern void (OPENGL_CALLING_CONVENTION * glNormalPointerFn) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
    extern void (OPENGL_CALLING_CONVENTION * glTexCoordPointerFn) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);

    /// this is a quickfix for sharpness of straight texts and symbols.
    /// should be refactored to something more consistent.
    extern void (OPENGL_CALLING_CONVENTION * glUseSharpGeometryFn) (GLboolean flag);

    extern const GLenum GL_VERTEX_ARRAY_MWM;
    extern const GLenum GL_TEXTURE_COORD_ARRAY_MWM;
    extern const GLenum GL_NORMAL_ARRAY_MWM;

    extern void (OPENGL_CALLING_CONVENTION * glMatrixModeFn) (GLenum mode);
    extern void (OPENGL_CALLING_CONVENTION * glLoadIdentityFn)();
    extern void (OPENGL_CALLING_CONVENTION * glLoadMatrixfFn) (const GLfloat *m);

    extern void (OPENGL_CALLING_CONVENTION * glOrthoFn) (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
    extern void (OPENGL_CALLING_CONVENTION * glDrawElementsFn) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);

    extern const GLenum GL_MODELVIEW_MWM;
    extern const GLenum GL_PROJECTION_MWM;

    extern const GLenum GL_ALPHA_TEST_MWM;

    /// information about supported extensions

    extern bool g_isMapBufferSupported;
    extern bool g_isBufferObjectsSupported;
    extern bool g_isFramebufferSupported;
    extern bool g_isRenderbufferSupported;
    extern bool g_isSeparateBlendFuncSupported;

    // buffer objects extensions

    extern const int GL_WRITE_ONLY_MWM;

    extern void (OPENGL_CALLING_CONVENTION * glBindBufferFn) (GLenum target, GLuint buffer);
    extern void (OPENGL_CALLING_CONVENTION * glGenBuffersFn) (GLsizei n, GLuint *buffers);
    extern void (OPENGL_CALLING_CONVENTION * glBufferDataFn) (GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
    extern void (OPENGL_CALLING_CONVENTION * glBufferSubDataFn) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data);
    extern void (OPENGL_CALLING_CONVENTION * glDeleteBuffersFn) (GLsizei n, const GLuint *buffers);
    extern void * (OPENGL_CALLING_CONVENTION * glMapBufferFn) (GLenum target, GLenum access);
    extern GLboolean (OPENGL_CALLING_CONVENTION * glUnmapBufferFn) (GLenum target);

    // framebuffers extensions

    extern const int GL_FRAMEBUFFER_BINDING_MWM;
    extern const int GL_FRAMEBUFFER_MWM;
    extern const int GL_FRAMEBUFFER_UNSUPPORTED_MWM;
    extern const int GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_MWM;
    extern const int GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_MWM;
    extern const int GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_MWM;
    extern const int GL_FRAMEBUFFER_COMPLETE_MWM;
    extern const int GL_DEPTH_ATTACHMENT_MWM;
    extern const int GL_COLOR_ATTACHMENT0_MWM;
    extern const int GL_RENDERBUFFER_MWM;
    extern const int GL_RENDERBUFFER_BINDING_MWM;
    extern const int GL_DEPTH_COMPONENT16_MWM;
    extern const int GL_DEPTH_COMPONENT24_MWM;
    extern const int GL_RGBA8_MWM;

    extern void (OPENGL_CALLING_CONVENTION * glBindFramebufferFn) (GLenum target, GLuint framebuffer);
    extern void (OPENGL_CALLING_CONVENTION * glFramebufferTexture2DFn) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
    extern void (OPENGL_CALLING_CONVENTION * glFramebufferRenderbufferFn) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
    extern void (OPENGL_CALLING_CONVENTION * glGenFramebuffersFn) (GLsizei n, GLuint *framebuffers);
    extern void (OPENGL_CALLING_CONVENTION * glDeleteFramebuffersFn) (GLsizei n, const GLuint *framebuffers);
    extern GLenum (OPENGL_CALLING_CONVENTION * glCheckFramebufferStatusFn) (GLenum target);
    extern void (OPENGL_CALLING_CONVENTION * glDiscardFramebufferFn)(GLenum target, GLsizei numAttachments, GLenum const * attachements);

    // renderbuffer extensions

    extern void (OPENGL_CALLING_CONVENTION * glGenRenderbuffersFn) (GLsizei n, GLuint *renderbuffers);
    extern void (OPENGL_CALLING_CONVENTION * glDeleteRenderbuffersFn) (GLsizei n, const GLuint *renderbuffers);
    extern void (OPENGL_CALLING_CONVENTION * glBindRenderbufferFn) (GLenum target, GLuint renderbuffer);
    extern void (OPENGL_CALLING_CONVENTION * glRenderbufferStorageFn) (GLenum target, GLenum internalformat, GLsizei width, GLsizei height);

    // separate alpha blending extension

    extern void (OPENGL_CALLING_CONVENTION * glBlendFuncSeparateFn) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);

    /// This flag controls, whether OpenGL resources should delete themselves upon destruction.
    /// Sounds odd, but in EGL there are cases when the only function one should call to finish
    /// its work with resources is eglTerminate, which by itself internally deletes all OpenGL resources.
    /// In this case we should set this variable to true to correctly deletes all our wrapper
    /// classes without calls to glDeleteXXX.

    extern bool g_hasContext;

    /// This flag controls, whether the OGLCHECK macroses should log OGL calls.
    /// This is for debugging purpose only.

    extern bool g_doLogOGLCalls;

    /// each platform should have an implementation of this function
    /// to check extensions support and initialize function pointers.
    void InitExtensions();

    /// Does we have an extension with the specified name?
    bool HasExtension(char const * name);

    void DumpGLInformation();

    /// return false to terminate program
    /// @throws platform_unsupported - is the platform we are running on is unsupported.
    void CheckExtensionSupport();

    struct platform_unsupported : public exception
    {
      string m_reason;
      const char * what() const throw();
      platform_unsupported(char const * reason);
      ~platform_unsupported() throw();
    };

    void CheckError(my::SrcPoint const & srcPt);
    void CheckEGLError(my::SrcPoint const & srcPt);

  }
}

//#define OMIM_GL_ENABLE_TRACE 1

#ifdef DEBUG
  #ifdef OMIM_GL_ENABLE_TRACE
    #define OGLCHECK(f) do { if (graphics::gl::g_doLogOGLCalls) LOG(LDEBUG, (#f)); if (graphics::gl::g_hasContext) {f; graphics::gl::CheckError(SRC());} else LOG(LDEBUG, ("no OGL context. skipping OGL call")); } while(false)
    #define OGLCHECKAFTER if (graphics::gl::g_doLogOGLCalls) LOG(LDEBUG, ("OGLCHECKAFTER")); graphics::gl::CheckError(SRC())
    #define EGLCHECK do { LOG(LDEBUG, ("EGLCHECK")); graphics::gl::CheckEGLError(SRC()); } while(false)
  #else
    #define OGLCHECK(f) do { if (graphics::gl::g_hasContext) {f; graphics::gl::CheckError(SRC());} else LOG(LDEBUG, ("no OGL context. skipping OGL call.")); } while(false)
    #define OGLCHECKAFTER graphics::gl::CheckError(SRC())
    #define EGLCHECK do { graphics::gl::CheckEGLError(SRC()); } while(false)
  #endif

#else
#define OGLCHECK(f) do {if (graphics::gl::g_hasContext) {f;} else LOG(LDEBUG, ("no OGL context. skipping OGL call."));} while (false)
#define OGLCHECKAFTER
#define EGLCHECK
#endif