24 #ifndef INC_OVR_CAPI_GL_Util_h
25 #define INC_OVR_CAPI_GL_Util_h
27 #include "../../OVR_CAPI.h"
28 #include "../../Kernel/OVR_Array.h"
29 #include "../../Kernel/OVR_Math.h"
30 #include "../../Kernel/OVR_RefCount.h"
31 #include "../../Kernel/OVR_String.h"
32 #include "../../Kernel/OVR_Types.h"
33 #include "../../Kernel/OVR_Log.h"
35 #if defined(OVR_OS_WIN32)
39 #if defined(OVR_OS_MAC)
40 #include <OpenGL/gl3.h>
41 #include <OpenGL/gl3ext.h>
43 #ifndef GL_GLEXT_PROTOTYPES
44 #define GL_GLEXT_PROTOTYPES
48 #if defined(OVR_OS_WIN32)
49 #include <GL/wglext.h>
50 #elif defined(OVR_OS_LINUX)
55 namespace OVR {
namespace CAPI {
namespace GL {
58 #if !defined(OVR_OS_MAC)
61 #if defined(OVR_OS_WIN32)
63 typedef void (__stdcall *PFNGLENABLEPROC) (GLenum);
64 typedef void (__stdcall *PFNGLDISABLEPROC) (GLenum);
65 typedef void (__stdcall *PFNGLGETFLOATVPROC) (GLenum, GLfloat*);
66 typedef const GLubyte * (__stdcall *PFNGLGETSTRINGPROC) (GLenum);
67 typedef void (__stdcall *PFNGLGETINTEGERVPROC) (GLenum, GLint*);
68 typedef PROC (__stdcall *PFNWGLGETPROCADDRESS) (LPCSTR);
69 typedef void (__stdcall *PFNGLFLUSHPROC) ();
70 typedef void (__stdcall *PFNGLFINISHPROC) ();
71 typedef void (__stdcall *PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count);
72 typedef void (__stdcall *PFNGLCLEARPROC) (GLbitfield);
73 typedef void (__stdcall *PFNGLCOLORMASKPROC) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
74 typedef void (__stdcall *PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type,
const GLvoid *indices);
75 typedef void (__stdcall *PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
76 typedef void (__stdcall *PFNGLDELETETEXTURESPROC) (GLsizei n, GLuint *textures);
77 typedef void (__stdcall *PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
78 typedef void (__stdcall *PFNGLCLEARCOLORPROC) (GLfloat
r, GLfloat g, GLfloat b, GLfloat a);
79 typedef void (__stdcall *PFNGLCLEARDEPTHPROC) (GLclampd depth);
80 typedef void (__stdcall *PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
81 typedef void (__stdcall *PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
83 extern PFNWGLGETPROCADDRESS wglGetProcAddress;
84 extern PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT;
85 extern PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
87 extern PFNGLENABLEPROC glEnable;
88 extern PFNGLDISABLEPROC glDisable;
89 extern PFNGLCOLORMASKPROC glColorMask;
90 extern PFNGLGETFLOATVPROC glGetFloatv;
91 extern PFNGLGETSTRINGPROC glGetString;
92 extern PFNGLGETINTEGERVPROC glGetIntegerv;
93 extern PFNGLCLEARPROC glClear;
94 extern PFNGLCLEARCOLORPROC glClearColor;
95 extern PFNGLCLEARDEPTHPROC glClearDepth;
96 extern PFNGLVIEWPORTPROC glViewport;
97 extern PFNGLDRAWARRAYSPROC glDrawArrays;
98 extern PFNGLDRAWELEMENTSPROC glDrawElements;
99 extern PFNGLGENTEXTURESPROC glGenTextures;
100 extern PFNGLDELETETEXTURESPROC glDeleteTextures;
101 extern PFNGLBINDTEXTUREPROC glBindTexture;
102 extern PFNGLTEXPARAMETERIPROC glTexParameteri;
103 extern PFNGLFLUSHPROC glFlush;
104 extern PFNGLFINISHPROC glFinish;
106 #elif defined(OVR_OS_LINUX)
108 extern PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
110 #endif // defined(OVR_OS_WIN32)
153 #endif // !defined(OVR_OS_MAC)
224 #if defined(OVR_OS_WIN32)
226 #elif defined(OVR_OS_LINUX)
251 virtual void*
Map(
size_t start,
size_t size,
int flags = 0);
252 virtual bool Unmap(
void *m);
253 virtual bool Data(
int use,
const void* buffer,
size_t size);
276 const Sizei& textureSize);
346 virtual bool SetUniform(
const char* name,
int n,
const float* v);
349 const float v[] = {x};
354 const float v[] = {x,y};
359 const float v[] = {x,y,z};
362 bool SetUniform4f(
const char* name,
float x,
float y,
float z,
float w = 1)
364 const float v[] = {x,y,z,w};
370 const float a[] = {v.
x,v.
y,v.
z,1};
403 for(
int i = 0; i < 8; i++)
428 operator bool ()
const
472 void InitUniforms(
const Uniform* refl,
size_t reflSize);
473 bool SetUniform(
const char* name,
int n,
const float* v);
478 template<ShaderStage SStage, GLenum SType>
490 success =
Compile((
const char*) s);
516 OVR_DEBUG_LOG((
"Compiling shader\n%s\nfailed: %s\n", src, msg));
537 #endif // INC_OVR_CAPI_GL_Util_h
PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray
const Uniform * UniformRefl
virtual void SetShader(Shader *s)
bool SetUniform1f(const char *name, float x)
ShaderImpl< Shader_Fragment, GL_FRAGMENT_SHADER > FragmentShader
virtual int GetHeight() const
PFNGLUNIFORM4FVPROC glUniform4fv
virtual int GetWidth() const
PFNGLUNIFORM3FVPROC glUniform3fv
PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer
Shader * GetShader(int stage)
virtual void SetSampleMode(int sm)
#define OVR_UNUSED3(a1, a2, a3)
PFNGLUNIFORM1IPROC glUniform1i
unsigned char * UniformData
DisplayId(String m, long id=0)
PFNGLBUFFERDATAPROC glBufferData
ShaderFill(ShaderSet *sh)
PFNGLCREATEPROGRAMPROC glCreateProgram
ShaderStage GetStage() const
PFNGLDELETEPROGRAMPROC glDeleteProgram
bool Compile(const char *src)
PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays
Texture(RenderParams *rp, int w, int h)
PFNGLDELETESHADERPROC glDeleteShader
PFNGLGETPROGRAMIVPROC glGetProgramiv
Matrix4 Transposed() const
virtual bool SetUniform(const char *name, int n, const float *v)
ShaderImpl(RenderParams *rp, void *s, size_t size, const Uniform *refl, size_t reflSize)
void UpdatePlaceholderTexture(GLuint texId, const Sizei &textureSize)
bool SetUniform3f(const char *name, float x, float y, float z)
PFNGLUNMAPBUFFERPROC glUnmapBuffer
GLint GetGLShader(Shader *s)
ShaderSet * GetShaders() const
PFNGLSHADERSOURCEPROC glShaderSource
PFNGLUNIFORM1FVPROC glUniform1fv
virtual void Set(int slot, ShaderStage stage=Shader_Fragment) const
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer
const char * ToCStr() const
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog
virtual bool Unmap(void *m)
bool SetUniform(const char *name, int n, const float *v)
virtual void * Map(size_t start, size_t size, int flags=0)
PFNGLCOMPILESHADERPROC glCompileShader
PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform
PFNGLLINKPROGRAMPROC glLinkProgram
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays
bool SetUniformv(const char *name, const Vector3f &v)
virtual void UnsetShader(int stage)
PFNGLGETATTRIBLOCATIONPROC glGetAttribLocation
Ptr< Shader > Shaders[Shader_Count]
PFNGLUSEPROGRAMPROC glUseProgram
virtual void Set(PrimitiveType prim=Prim_Unknown) const
ShaderBase(RenderParams *rp, ShaderStage stage)
virtual bool SetUniformBool(const char *name, int n, const bool *v)
virtual bool SetUniform4x4f(const char *name, const Matrix4f &m)
PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray
virtual void Set(PrimitiveType) const
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog
PFNGLBINDVERTEXARRAYPROC glBindVertexArray
PFNGLUNIFORM2FVPROC glUniform2fv
Ptr< class Texture > Textures[8]
PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation
PFNGLATTACHSHADERPROC glAttachShader
bool SetUniformBool(const char *name, int n, const bool *v)
virtual bool SetUniform(const char *name, int n, const float *v)
PFNGLGENBUFFERSPROC glGenBuffers
PFNGLBINDBUFFERPROC glBindBuffer
PFNGLDETACHSHADERPROC glDetachShader
void InitUniforms(const Uniform *refl, size_t reflSize)
PFNGLCREATESHADERPROC glCreateShader
void * GetInputLayout() const
bool SetUniform2f(const char *name, float x, float y)
virtual void Set(PrimitiveType prim) const
virtual void SetUniformBuffer(class Buffer *buffers, int i=0)
virtual void SetTexture(int i, class Texture *tex)
PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv
Array< Uniform > UniformInfo
bool SetUniform4f(const char *name, float x, float y, float z, float w=1)
PFNGLDELETEBUFFERSPROC glDeleteBuffers
ShaderImpl< Shader_Vertex, GL_VERTEX_SHADER > VertexShader
#define OVR_DEBUG_LOG(args)
virtual bool Data(int use, const void *buffer, size_t size)
PFNGLACTIVETEXTUREPROC glActiveTexture
PFNGLMAPBUFFERPROC glMapBuffer
ShaderFill(ShaderSet &sh)
__END_NAMESPACE_STD __BEGIN_NAMESPACE_STD size_t size_t char char * strstr(const char *__haystack, const char *__needle) __THROW __attribute_pure__ __nonnull((1
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation
#define OVR_UNUSED2(a1, a2)
bool operator==(const DisplayId &b) const
PFNGLGETSHADERIVPROC glGetShaderiv