aboutsummaryrefslogtreecommitdiffstats
path: root/Samples/CommonSrc/Render/Render_GL_Device.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Samples/CommonSrc/Render/Render_GL_Device.cpp')
-rw-r--r--Samples/CommonSrc/Render/Render_GL_Device.cpp593
1 files changed, 360 insertions, 233 deletions
diff --git a/Samples/CommonSrc/Render/Render_GL_Device.cpp b/Samples/CommonSrc/Render/Render_GL_Device.cpp
index 4b3ddec..774af07 100644
--- a/Samples/CommonSrc/Render/Render_GL_Device.cpp
+++ b/Samples/CommonSrc/Render/Render_GL_Device.cpp
@@ -26,19 +26,40 @@ limitations under the License.
#include "OVR_CAPI_GL.h"
namespace OVR { namespace Render { namespace GL {
+
+#if !defined(OVR_OS_MAC)
// GL Hooks for PC.
#if defined(OVR_OS_WIN32)
+PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB;
+PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT;
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
-PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT;
-PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT;
+
+void* GetFunction(const char* functionName)
+{
+ return wglGetProcAddress(functionName);
+}
+
+#else
+
+PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
+
+void (*GetFunction(const char *functionName))( void )
+{
+ return glXGetProcAddress((GLubyte*)functionName);
+}
+
+#endif
+
+PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
+PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
PFNGLDELETESHADERPROC glDeleteShader;
-PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT;
-PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT;
-PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT;
-PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT;
+PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
+PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
+PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
+PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
PFNGLACTIVETEXTUREPROC glActiveTexture;
PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;
PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
@@ -73,87 +94,96 @@ PFNGLUNIFORM3FVPROC glUniform3fv;
PFNGLUNIFORM2FVPROC glUniform2fv;
PFNGLUNIFORM1FVPROC glUniform1fv;
PFNGLCOMPRESSEDTEXIMAGE2DPROC glCompressedTexImage2D;
-PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT;
-PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT;
-PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT;
-PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT;
-
+PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
+PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
+PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
+PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
+PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays;
+PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
void InitGLExtensions()
{
- if (glGenFramebuffersEXT)
+ if (glGenFramebuffers)
return;
-
-
- wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC) wglGetProcAddress("wglGetSwapIntervalEXT");
- wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress("wglSwapIntervalEXT");
- glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC) wglGetProcAddress("glGenFramebuffersEXT");
- glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC) wglGetProcAddress("glDeleteFramebuffersEXT");
- glDeleteShader = (PFNGLDELETESHADERPROC) wglGetProcAddress("glDeleteShader");
- glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) wglGetProcAddress("glCheckFramebufferStatusEXT");
- glFramebufferRenderbufferEXT = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) wglGetProcAddress("glFramebufferRenderbufferEXT");
- glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) wglGetProcAddress("glFramebufferTexture2DEXT");
- glBindFramebufferEXT = (PFNGLBINDFRAMEBUFFEREXTPROC) wglGetProcAddress("glBindFramebufferEXT");
- glActiveTexture = (PFNGLACTIVETEXTUREPROC) wglGetProcAddress("glActiveTexture");
- glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC) wglGetProcAddress("glDisableVertexAttribArray");
- glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) wglGetProcAddress("glVertexAttribPointer");
- glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC) wglGetProcAddress("glEnableVertexAttribArray");
- glBindBuffer = (PFNGLBINDBUFFERPROC) wglGetProcAddress("glBindBuffer");
- glUniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC) wglGetProcAddress("glUniformMatrix3fv");
- glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC) wglGetProcAddress("glUniformMatrix4fv");
- glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) wglGetProcAddress("glDeleteBuffers");
- glBufferData = (PFNGLBUFFERDATAPROC) wglGetProcAddress("glBufferData");
- glGenBuffers = (PFNGLGENBUFFERSPROC) wglGetProcAddress("glGenBuffers");
- glMapBuffer = (PFNGLMAPBUFFERPROC) wglGetProcAddress("glMapBuffer");
- glUnmapBuffer = (PFNGLUNMAPBUFFERPROC) wglGetProcAddress("glUnmapBuffer");
- glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) wglGetProcAddress("glGetShaderInfoLog");
- glGetShaderiv = (PFNGLGETSHADERIVPROC) wglGetProcAddress("glGetShaderiv");
- glCompileShader = (PFNGLCOMPILESHADERPROC) wglGetProcAddress("glCompileShader");
- glShaderSource = (PFNGLSHADERSOURCEPROC) wglGetProcAddress("glShaderSource");
- glCreateShader = (PFNGLCREATESHADERPROC) wglGetProcAddress("glCreateShader");
- glCreateProgram = (PFNGLCREATEPROGRAMPROC) wglGetProcAddress("glCreateProgram");
- glAttachShader = (PFNGLATTACHSHADERPROC) wglGetProcAddress("glAttachShader");
- glDetachShader = (PFNGLDETACHSHADERPROC) wglGetProcAddress("glDetachShader");
- glDeleteProgram = (PFNGLDELETEPROGRAMPROC) wglGetProcAddress("glDeleteProgram");
- glUniform1i = (PFNGLUNIFORM1IPROC) wglGetProcAddress("glUniform1i");
- glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) wglGetProcAddress("glGetUniformLocation");
- glGetActiveUniform = (PFNGLGETACTIVEUNIFORMPROC) wglGetProcAddress("glGetActiveUniform");
- glUseProgram = (PFNGLUSEPROGRAMPROC) wglGetProcAddress("glUseProgram");
- glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) wglGetProcAddress("glGetProgramInfoLog");
- glGetProgramiv = (PFNGLGETPROGRAMIVPROC) wglGetProcAddress("glGetProgramiv");
- glLinkProgram = (PFNGLLINKPROGRAMPROC) wglGetProcAddress("glLinkProgram");
- glBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC) wglGetProcAddress("glBindAttribLocation");
- glUniform4fv = (PFNGLUNIFORM4FVPROC) wglGetProcAddress("glUniform4fv");
- glUniform3fv = (PFNGLUNIFORM3FVPROC) wglGetProcAddress("glUniform3fv");
- glUniform2fv = (PFNGLUNIFORM2FVPROC) wglGetProcAddress("glUniform2fv");
- glUniform1fv = (PFNGLUNIFORM1FVPROC) wglGetProcAddress("glUniform1fv");
- glCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC) wglGetProcAddress("glCompressedTexImage2D");
- glRenderbufferStorageEXT = (PFNGLRENDERBUFFERSTORAGEEXTPROC) wglGetProcAddress("glRenderbufferStorageEXT");
- glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC) wglGetProcAddress("glBindRenderbufferEXT");
- glGenRenderbuffersEXT = (PFNGLGENRENDERBUFFERSEXTPROC) wglGetProcAddress("glGenRenderbuffersEXT");
- glDeleteRenderbuffersEXT = (PFNGLDELETERENDERBUFFERSEXTPROC) wglGetProcAddress("glDeleteRenderbuffersEXT");
-
-
- glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC) wglGetProcAddress("glGenVertexArrays");
-}
+#if defined(OVR_OS_WIN32)
+ wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC) GetFunction("wglGetSwapIntervalEXT");
+ wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) GetFunction("wglSwapIntervalEXT");
+#else
+ glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) GetFunction("glXSwapIntervalEXT");
#endif
+ glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) GetFunction("glGenFramebuffersEXT");
+ glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) GetFunction("glDeleteFramebuffersEXT");
+ glDeleteShader = (PFNGLDELETESHADERPROC) GetFunction("glDeleteShader");
+ glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) GetFunction("glCheckFramebufferStatusEXT");
+ glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) GetFunction("glFramebufferRenderbufferEXT");
+ glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) GetFunction("glFramebufferTexture2DEXT");
+ glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) GetFunction("glBindFramebufferEXT");
+ glActiveTexture = (PFNGLACTIVETEXTUREPROC) GetFunction("glActiveTexture");
+ glDisableVertexAttribArray = (PFNGLDISABLEVERTEXATTRIBARRAYPROC) GetFunction("glDisableVertexAttribArray");
+ glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC) GetFunction("glVertexAttribPointer");
+ glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC) GetFunction("glEnableVertexAttribArray");
+ glBindBuffer = (PFNGLBINDBUFFERPROC) GetFunction("glBindBuffer");
+ glUniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC) GetFunction("glUniformMatrix3fv");
+ glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC) GetFunction("glUniformMatrix4fv");
+ glDeleteBuffers = (PFNGLDELETEBUFFERSPROC) GetFunction("glDeleteBuffers");
+ glBufferData = (PFNGLBUFFERDATAPROC) GetFunction("glBufferData");
+ glGenBuffers = (PFNGLGENBUFFERSPROC) GetFunction("glGenBuffers");
+ glMapBuffer = (PFNGLMAPBUFFERPROC) GetFunction("glMapBuffer");
+ glUnmapBuffer = (PFNGLUNMAPBUFFERPROC) GetFunction("glUnmapBuffer");
+ glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) GetFunction("glGetShaderInfoLog");
+ glGetShaderiv = (PFNGLGETSHADERIVPROC) GetFunction("glGetShaderiv");
+ glCompileShader = (PFNGLCOMPILESHADERPROC) GetFunction("glCompileShader");
+ glShaderSource = (PFNGLSHADERSOURCEPROC) GetFunction("glShaderSource");
+ glCreateShader = (PFNGLCREATESHADERPROC) GetFunction("glCreateShader");
+ glCreateProgram = (PFNGLCREATEPROGRAMPROC) GetFunction("glCreateProgram");
+ glAttachShader = (PFNGLATTACHSHADERPROC) GetFunction("glAttachShader");
+ glDetachShader = (PFNGLDETACHSHADERPROC) GetFunction("glDetachShader");
+ glDeleteProgram = (PFNGLDELETEPROGRAMPROC) GetFunction("glDeleteProgram");
+ glUniform1i = (PFNGLUNIFORM1IPROC) GetFunction("glUniform1i");
+ glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) GetFunction("glGetUniformLocation");
+ glGetActiveUniform = (PFNGLGETACTIVEUNIFORMPROC) GetFunction("glGetActiveUniform");
+ glUseProgram = (PFNGLUSEPROGRAMPROC) GetFunction("glUseProgram");
+ glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) GetFunction("glGetProgramInfoLog");
+ glGetProgramiv = (PFNGLGETPROGRAMIVPROC) GetFunction("glGetProgramiv");
+ glLinkProgram = (PFNGLLINKPROGRAMPROC) GetFunction("glLinkProgram");
+ glBindAttribLocation = (PFNGLBINDATTRIBLOCATIONPROC) GetFunction("glBindAttribLocation");
+ glUniform4fv = (PFNGLUNIFORM4FVPROC) GetFunction("glUniform4fv");
+ glUniform3fv = (PFNGLUNIFORM3FVPROC) GetFunction("glUniform3fv");
+ glUniform2fv = (PFNGLUNIFORM2FVPROC) GetFunction("glUniform2fv");
+ glUniform1fv = (PFNGLUNIFORM1FVPROC) GetFunction("glUniform1fv");
+ glCompressedTexImage2D = (PFNGLCOMPRESSEDTEXIMAGE2DPROC) GetFunction("glCompressedTexImage2D");
+ glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) GetFunction("glRenderbufferStorageEXT");
+ glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) GetFunction("glBindRenderbufferEXT");
+ glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) GetFunction("glGenRenderbuffersEXT");
+ glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) GetFunction("glDeleteRenderbuffersEXT");
+ glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC) GetFunction("glGenVertexArrays");
+ glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC) GetFunction("glDeleteVertexArrays");
+ glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC) GetFunction("glBindVertexArray");
+}
+
+#endif
static const char* StdVertexShaderSrc =
+ "#version 110\n"
+
"uniform mat4 Proj;\n"
"uniform mat4 View;\n"
+
"attribute vec4 Position;\n"
"attribute vec4 Color;\n"
"attribute vec2 TexCoord;\n"
"attribute vec2 TexCoord1;\n"
"attribute vec3 Normal;\n"
- "varying vec4 oColor;\n"
- "varying vec2 oTexCoord;\n"
- "varying vec2 oTexCoord1;\n"
- "varying vec3 oNormal;\n"
- "varying vec3 oVPos;\n"
+
+ "varying vec4 oColor;\n"
+ "varying vec2 oTexCoord;\n"
+ "varying vec2 oTexCoord1;\n"
+ "varying vec3 oNormal;\n"
+ "varying vec3 oVPos;\n"
+
"void main()\n"
"{\n"
" gl_Position = Proj * (View * Position);\n"
@@ -165,14 +195,19 @@ static const char* StdVertexShaderSrc =
"}\n";
static const char* DirectVertexShaderSrc =
+ "#version 110\n"
+
"uniform mat4 View;\n"
+
"attribute vec4 Position;\n"
"attribute vec4 Color;\n"
"attribute vec2 TexCoord;\n"
"attribute vec3 Normal;\n"
- "varying vec4 oColor;\n"
- "varying vec2 oTexCoord;\n"
- "varying vec3 oNormal;\n"
+
+ "varying vec4 oColor;\n"
+ "varying vec2 oTexCoord;\n"
+ "varying vec3 oNormal;\n"
+
"void main()\n"
"{\n"
" gl_Position = View * Position;\n"
@@ -182,23 +217,33 @@ static const char* DirectVertexShaderSrc =
"}\n";
static const char* SolidFragShaderSrc =
+ "#version 110\n"
+
"uniform vec4 Color;\n"
+
"void main()\n"
"{\n"
" gl_FragColor = Color;\n"
"}\n";
static const char* GouraudFragShaderSrc =
+ "#version 110\n"
+
"varying vec4 oColor;\n"
+
"void main()\n"
"{\n"
" gl_FragColor = oColor;\n"
"}\n";
static const char* TextureFragShaderSrc =
+ "#version 110\n"
+
"uniform sampler2D Texture0;\n"
+
"varying vec4 oColor;\n"
"varying vec2 oTexCoord;\n"
+
"void main()\n"
"{\n"
" gl_FragColor = oColor * texture2D(Texture0, oTexCoord);\n"
@@ -207,6 +252,7 @@ static const char* TextureFragShaderSrc =
"}\n";
#define LIGHTING_COMMON \
+ "#version 110\n" \
"uniform vec3 Ambient;\n" \
"uniform vec4 LightPos[8];\n" \
"uniform vec4 LightColor[8];\n" \
@@ -231,98 +277,91 @@ static const char* TextureFragShaderSrc =
static const char* LitSolidFragShaderSrc =
LIGHTING_COMMON
+
"void main()\n"
"{\n"
" gl_FragColor = DoLight() * oColor;\n"
"}\n";
static const char* LitTextureFragShaderSrc =
- "uniform sampler2D Texture0;\n"
LIGHTING_COMMON
+
+ "uniform sampler2D Texture0;\n"
+
"void main()\n"
"{\n"
" gl_FragColor = DoLight() * texture2D(Texture0, oTexCoord);\n"
"}\n";
static const char* AlphaTextureFragShaderSrc =
+ "#version 110\n"
+
"uniform sampler2D Texture0;\n"
+
"varying vec4 oColor;\n"
"varying vec2 oTexCoord;\n"
+
"void main()\n"
"{\n"
- " gl_FragColor = oColor * vec4(1,1,1,texture2D(Texture0, oTexCoord).a);\n"
+ " gl_FragColor = oColor * vec4(1,1,1,texture2D(Texture0, oTexCoord).r);\n"
"}\n";
static const char* MultiTextureFragShaderSrc =
+ "#version 110\n"
+
"uniform sampler2D Texture0;\n"
"uniform sampler2D Texture1;\n"
+
"varying vec4 oColor;\n"
"varying vec2 oTexCoord;\n"
"varying vec2 oTexCoord1;\n"
+
"void main()\n"
"{\n"
- " vec4 color1 = texture2D(Texture0, oTexCoord);\n"
- " vec4 color2 = texture2D(Texture1, oTexCoord1);\n"
- " color2.rgb = color2.rgb * mix(1.9, 1.2, clamp(length(color2.rgb),0.0,1.0));\n"
- " color2 = color1 * color2;\n"
- " if (color2.a <= 0.6)\n"
+ " vec4 color = texture2D(Texture0, oTexCoord);\n"
+
+ " gl_FragColor = texture2D(Texture1, oTexCoord1);\n"
+ " gl_FragColor.rgb = gl_FragColor.rgb * mix(1.9, 1.2, clamp(length(gl_FragColor.rgb),0.0,1.0));\n"
+
+ " gl_FragColor = color * gl_FragColor;\n"
+
+ " if (gl_FragColor.a <= 0.6)\n"
" discard;\n"
- " gl_FragColor = color2;\n"
"}\n";
static const char* PostProcessMeshFragShaderSrc =
+ "#version 110\n"
+
"uniform sampler2D Texture;\n"
+
"varying vec4 oColor;\n"
"varying vec2 oTexCoord0;\n"
"varying vec2 oTexCoord1;\n"
"varying vec2 oTexCoord2;\n"
- "\n"
- "void main()\n"
- "{\n"
- " float ResultR = texture2D(Texture, oTexCoord0).r;\n"
- " float ResultG = texture2D(Texture, oTexCoord1).g;\n"
- " float ResultB = texture2D(Texture, oTexCoord2).b;\n"
- " gl_FragColor = vec4(ResultR * oColor.r, ResultG * oColor.g, ResultB * oColor.b, 1.0);\n"
- "}\n";
-
-static const char* PostProcessMeshTimewarpFragShaderSrc =
- "uniform sampler2D Texture;\n"
- "varying vec4 oColor;\n"
- "varying vec2 oTexCoord0;\n"
- "varying vec2 oTexCoord1;\n"
- "varying vec2 oTexCoord2;\n"
- "\n"
- "void main()\n"
- "{\n"
- " float ResultR = texture2D(Texture, oTexCoord0).r;\n"
- " float ResultG = texture2D(Texture, oTexCoord1).g;\n"
- " float ResultB = texture2D(Texture, oTexCoord2).b;\n"
- " gl_FragColor = vec4(ResultR * oColor.r, ResultG * oColor.g, ResultB * oColor.b, 1.0);\n"
- "}\n";
-
-static const char* PostProcessMeshPositionalTimewarpFragShaderSrc =
- "uniform sampler2D Texture0;\n"
- "uniform sampler2D Texture1;\n"
- "varying vec4 oColor;\n"
- "varying vec2 oTexCoord0;\n"
- "varying vec2 oTexCoord1;\n"
- "varying vec2 oTexCoord2;\n"
- "\n"
+
"void main()\n"
"{\n"
- " gl_FragColor.r = oColor.r * texture2D(Texture1, oTexCoord0).r;\n"
- " gl_FragColor.g = oColor.g * texture2D(Texture1, oTexCoord1).g;\n"
- " gl_FragColor.b = oColor.b * texture2D(Texture1, oTexCoord2).b;\n"
+ " gl_FragColor.r = oColor.r * texture2D(Texture, oTexCoord0).r;\n"
+ " gl_FragColor.g = oColor.g * texture2D(Texture, oTexCoord1).g;\n"
+ " gl_FragColor.b = oColor.b * texture2D(Texture, oTexCoord2).b;\n"
" gl_FragColor.a = 1.0;\n"
"}\n";
+static const char* PostProcessMeshTimewarpFragShaderSrc = PostProcessMeshFragShaderSrc;
+static const char* PostProcessMeshPositionalTimewarpFragShaderSrc = PostProcessMeshFragShaderSrc;
+static const char* PostProcessHeightmapTimewarpFragShaderSrc = PostProcessMeshFragShaderSrc;
static const char* PostProcessVertexShaderSrc =
+ "#version 110\n"
+
"uniform mat4 View;\n"
"uniform mat4 Texm;\n"
+
"attribute vec4 Position;\n"
"attribute vec2 TexCoord;\n"
- "varying vec2 oTexCoord;\n"
+
+ "varying vec2 oTexCoord;\n"
+
"void main()\n"
"{\n"
" gl_Position = View * Position;\n"
@@ -330,6 +369,8 @@ static const char* PostProcessVertexShaderSrc =
"}\n";
static const char* PostProcessMeshVertexShaderSrc =
+ "#version 110\n"
+
"uniform vec2 EyeToSourceUVScale;\n"
"uniform vec2 EyeToSourceUVOffset;\n"
@@ -353,15 +394,17 @@ static const char* PostProcessMeshVertexShaderSrc =
// Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion).
// Scale them into the correct [0-1],[0-1] UV lookup space (depending on eye)
" oTexCoord0 = TexCoord0 * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
- " oTexCoord0.y = 1-oTexCoord0.y;\n"
+ " oTexCoord0.y = 1.0-oTexCoord0.y;\n"
" oTexCoord1 = TexCoord1 * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
- " oTexCoord1.y = 1-oTexCoord1.y;\n"
+ " oTexCoord1.y = 1.0-oTexCoord1.y;\n"
" oTexCoord2 = TexCoord2 * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
- " oTexCoord2.y = 1-oTexCoord2.y;\n"
+ " oTexCoord2.y = 1.0-oTexCoord2.y;\n"
" oColor = Color;\n" // Used for vignette fade.
"}\n";
static const char* PostProcessMeshTimewarpVertexShaderSrc =
+ "#version 110\n"
+
"uniform vec2 EyeToSourceUVScale;\n"
"uniform vec2 EyeToSourceUVOffset;\n"
"uniform mat4 EyeRotationStart;\n"
@@ -392,7 +435,7 @@ static const char* PostProcessMeshTimewarpVertexShaderSrc =
" vec3 TanEyeAngleB = vec3 ( TexCoord2.x, TexCoord2.y, 1.0 );\n"
// Accurate time warp lerp vs. faster
-#if 1
+#if 0
// Apply the two 3x3 timewarp rotations to these vectors.
" vec3 TransformedRStart = (EyeRotationStart * vec4(TanEyeAngleR, 0)).xyz;\n"
" vec3 TransformedGStart = (EyeRotationStart * vec4(TanEyeAngleG, 0)).xyz;\n"
@@ -405,7 +448,10 @@ static const char* PostProcessMeshTimewarpVertexShaderSrc =
" vec3 TransformedG = mix ( TransformedGStart, TransformedGEnd, Color.a );\n"
" vec3 TransformedB = mix ( TransformedBStart, TransformedBEnd, Color.a );\n"
#else
- " mat3 EyeRotation = mix ( EyeRotationStart, EyeRotationEnd, Color.a );\n"
+ " mat3 EyeRotation;\n"
+ " EyeRotation[0] = mix ( EyeRotationStart[0], EyeRotationEnd[0], Color.a ).xyz;\n"
+ " EyeRotation[1] = mix ( EyeRotationStart[1], EyeRotationEnd[1], Color.a ).xyz;\n"
+ " EyeRotation[2] = mix ( EyeRotationStart[2], EyeRotationEnd[2], Color.a ).xyz;\n"
" vec3 TransformedR = EyeRotation * TanEyeAngleR;\n"
" vec3 TransformedG = EyeRotation * TanEyeAngleG;\n"
" vec3 TransformedB = EyeRotation * TanEyeAngleB;\n"
@@ -425,42 +471,46 @@ static const char* PostProcessMeshTimewarpVertexShaderSrc =
" vec2 SrcCoordG = FlattenedG * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
" vec2 SrcCoordB = FlattenedB * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
" oTexCoord0 = SrcCoordR;\n"
- " oTexCoord0.y = 1-oTexCoord0.y;\n"
+ " oTexCoord0.y = 1.0-oTexCoord0.y;\n"
" oTexCoord1 = SrcCoordG;\n"
- " oTexCoord1.y = 1-oTexCoord1.y;\n"
+ " oTexCoord1.y = 1.0-oTexCoord1.y;\n"
" oTexCoord2 = SrcCoordB;\n"
- " oTexCoord2.y = 1-oTexCoord2.y;\n"
- " oColor = Color.r;\n" // Used for vignette fade.
+ " oTexCoord2.y = 1.0-oTexCoord2.y;\n"
+ " oColor = vec4(Color.r, Color.r, Color.r, Color.r);\n" // Used for vignette fade.
"}\n";
static const char* PostProcessMeshPositionalTimewarpVertexShaderSrc =
+#if 1 //TODO: Disabled until we fix positional timewarp and layering on GL.
+PostProcessMeshTimewarpVertexShaderSrc;
+#else
"#version 150\n"
- "uniform sampler2D Texture0;\n"
+
+ "uniform sampler2D Texture0;\n"
"uniform vec2 EyeToSourceUVScale;\n"
"uniform vec2 EyeToSourceUVOffset;\n"
- "uniform vec2 DepthProjector;\n"
- "uniform vec2 DepthDimSize;\n"
- "uniform mat4 EyeRotationStart;\n"
+ "uniform vec2 DepthProjector;\n"
+ "uniform vec2 DepthDimSize;\n"
+ "uniform mat4 EyeRotationStart;\n"
"uniform mat4 EyeRotationEnd;\n"
- "in vec2 Position;\n"
- "in vec4 Color;\n"
- "in vec2 TexCoord0;\n"
- "in vec2 TexCoord1;\n"
- "in vec2 TexCoord2;\n"
+ "attribute vec2 Position;\n"
+ "attribute vec4 Color;\n"
+ "attribute vec2 TexCoord0;\n"
+ "attribute vec2 TexCoord1;\n"
+ "attribute vec2 TexCoord2;\n"
- "out vec4 oColor;\n"
- "out vec2 oTexCoord0;\n"
- "out vec2 oTexCoord1;\n"
- "out vec2 oTexCoord2;\n"
+ "varying vec4 oColor;\n"
+ "varying vec2 oTexCoord0;\n"
+ "varying vec2 oTexCoord1;\n"
+ "varying vec2 oTexCoord2;\n"
"vec4 PositionFromDepth(vec2 inTexCoord)\n"
"{\n"
" vec2 eyeToSourceTexCoord = inTexCoord * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
- " eyeToSourceTexCoord.y = 1 - eyeToSourceTexCoord.y;\n"
- " float depth = texelFetch(Texture0, ivec2(eyeToSourceTexCoord * DepthDimSize), 0).x;\n"
- " float linearDepth = DepthProjector.y / (depth - DepthProjector.x);\n"
- " vec4 retVal = vec4(inTexCoord, 1, 1);\n"
+ " eyeToSourceTexCoord.y = 1.0 - eyeToSourceTexCoord.y;\n"
+ " float depth = texelFetch(Texture0, ivec2(eyeToSourceTexCoord * DepthDimSize), 0).x;\n" //FIXME: Use Texture2DLod for #version 110 support.
+ " float linearDepth = DepthProjector.y / (depth - DepthProjector.x);\n"
+ " vec4 retVal = vec4(inTexCoord, 1, 1);\n"
" retVal.xyz *= linearDepth;\n"
" return retVal;\n"
"}\n"
@@ -468,7 +518,7 @@ static const char* PostProcessMeshPositionalTimewarpVertexShaderSrc =
"vec2 TimewarpTexCoordToWarpedPos(vec2 inTexCoord, float a)\n"
"{\n"
// Vertex inputs are in TanEyeAngle space for the R,G,B channels (i.e. after chromatic aberration and distortion).
- // These are now "real world" vectors in direction (x,y,1) relative to the eye of the HMD.
+ // These are now "real world" vectors in direction (x,y,1) relative to the eye of the HMD.
// Apply the 4x4 timewarp rotation to these vectors.
" vec4 inputPos = PositionFromDepth(inTexCoord);\n"
" vec3 transformed = mix ( EyeRotationStart * inputPos, EyeRotationEnd * inputPos, a ).xyz;\n"
@@ -476,7 +526,7 @@ static const char* PostProcessMeshPositionalTimewarpVertexShaderSrc =
" vec2 flattened = transformed.xy / transformed.z;\n"
// Scale them into ([0,0.5],[0,1]) or ([0.5,0],[0,1]) UV lookup space (depending on eye)
" vec2 noDepthUV = flattened * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
- //" float depth = texture2DLod(Texture0, noDepthUV, 0).r;\n"
+ //" float depth = texture2D(Texture0, noDepthUV).r;\n"
" return noDepthUV.xy;\n"
"}\n"
@@ -489,45 +539,76 @@ static const char* PostProcessMeshPositionalTimewarpVertexShaderSrc =
// warped positions are a bit more involved, hence a separate function
" oTexCoord0 = TimewarpTexCoordToWarpedPos(TexCoord0, Color.a);\n"
- " oTexCoord0.y = 1-oTexCoord0.y;\n"
+ " oTexCoord0.y = 1.0 - oTexCoord0.y;\n"
" oTexCoord1 = TimewarpTexCoordToWarpedPos(TexCoord1, Color.a);\n"
- " oTexCoord1.y = 1-oTexCoord1.y;\n"
+ " oTexCoord1.y = 1.0 - oTexCoord1.y;\n"
" oTexCoord2 = TimewarpTexCoordToWarpedPos(TexCoord2, Color.a);\n"
- " oTexCoord2.y = 1-oTexCoord2.y;\n"
+ " oTexCoord2.y = 1.0 - oTexCoord2.y;\n"
- " oColor = vec4(Color.r); // Used for vignette fade.\n"
+ " oColor = vec4(Color.r, Color.r, Color.r, Color.r); // Used for vignette fade.\n"
"}\n";
+#endif
-static const char* PostProcessFragShaderSrc =
- "uniform vec2 LensCenter;\n"
- "uniform vec2 ScreenCenter;\n"
+
+static const char* PostProcessHeightmapTimewarpVertexShaderSrc =
+#if 1 //TODO: Disabled until we fix positional timewarp and layering on GL.
+PostProcessMeshTimewarpVertexShaderSrc;
+#else
+ "#version 150\n"
+
+ "uniform sampler2D Texture0;\n"
"uniform vec2 EyeToSourceUVScale;\n"
- "uniform vec2 EyeToSourceNDCScale;\n"
- "uniform vec4 HmdWarpParam;\n"
- "uniform sampler2D Texture1;\n"
+ "uniform vec2 EyeToSourceUVOffset;\n"
+ "uniform vec2 DepthDimSize;\n"
+ "uniform mat4 EyeXformStart;\n"
+ "uniform mat4 EyeXformEnd;\n"
+ //"uniform mat4 Projection;\n"
+ "uniform mat4 InvProjection;\n"
- "varying vec2 oTexCoord;\n"
+ "attribute vec2 Position;\n"
+ "attribute vec3 TexCoord0;\n"
+
+ "varying vec2 oTexCoord0;\n"
+
+ "vec4 PositionFromDepth(vec2 position, vec2 inTexCoord)\n"
+ "{\n"
+ " float depth = texelFetch(Texture0, ivec2(inTexCoord * DepthDimSize), 0).x;\n" //FIXME: Use Texture2DLod for #version 110 support.
+ " vec4 retVal = vec4(position, depth, 1);\n"
+ " return retVal;\n"
+ "}\n"
- "vec2 HmdWarp(vec2 in01)\n"
+ "vec4 TimewarpPos(vec2 position, vec2 inTexCoord, mat4 rotMat)\n"
"{\n"
- " vec2 theta = (in01 - LensCenter) * EyeToSourceNDCScale;\n" // Scales to [-1, 1]
- " float rSq = theta.x * theta.x + theta.y * theta.y;\n"
- " vec2 theta1 = theta * (HmdWarpParam.x + HmdWarpParam.y * rSq + "
- " HmdWarpParam.z * rSq * rSq + HmdWarpParam.w * rSq * rSq * rSq);\n"
- " return LensCenter + EyeToSourceUVScale * theta1;\n"
+ // Apply the 4x4 timewarp rotation to these vectors.
+ " vec4 transformed = PositionFromDepth(position, inTexCoord);\n"
+ " transformed = InvProjection * transformed;\n"
+ " transformed = rotMat * transformed;\n"
+ //" transformed = mul ( Projection, transformed );\n"
+ " return transformed;\n"
"}\n"
"void main()\n"
"{\n"
- " vec2 tc = HmdWarp(oTexCoord);\n"
- " if (!all(equal(clamp(tc, ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25,0.5)), tc)))\n"
- " gl_FragColor = vec4(0);\n"
- " else\n"
- " gl_FragColor = texture2D(Texture1, tc);\n"
- "}\n";
+ " vec2 eyeToSrcTexCoord = TexCoord0.xy * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
+ " oTexCoord0 = eyeToSrcTexCoord;\n"
+
+ " float timewarpLerpFactor = TexCoord0.z;\n"
+ " mat4 lerpedEyeRot; // GL cannot mix() matrices :-( \n"
+ " lerpedEyeRot[0] = mix(EyeXformStart[0], EyeXformEnd[0], timewarpLerpFactor);\n"
+ " lerpedEyeRot[1] = mix(EyeXformStart[1], EyeXformEnd[1], timewarpLerpFactor);\n"
+ " lerpedEyeRot[2] = mix(EyeXformStart[2], EyeXformEnd[2], timewarpLerpFactor);\n"
+ " lerpedEyeRot[3] = mix(EyeXformStart[3], EyeXformEnd[3], timewarpLerpFactor);\n"
+ //" float4x4 lerpedEyeRot = EyeXformStart;\n"
+ // warped positions are a bit more involved, hence a separate function
+ " gl_Position = TimewarpPos(Position.xy, oTexCoord0, lerpedEyeRot);\n"
+ "}\n";
+#endif
+
// Shader with lens distortion and chromatic aberration correction.
static const char* PostProcessFragShaderWithChromAbSrc =
+ "#version 110\n"
+
"uniform sampler2D Texture;\n"
"uniform vec3 DistortionClearColor;\n"
"uniform float EdgeFadeScale;\n"
@@ -562,19 +643,19 @@ static const char* PostProcessFragShaderWithChromAbSrc =
// Scale them into ([0,0.5],[0,1]) or ([0.5,0],[0,1]) UV lookup space (depending on eye)
" vec2 SourceCoordR = TanEyeAngleR * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
- " SourceCoordR.y = 1 - SourceCoordR.y;\n"
+ " SourceCoordR.y = 1.0 - SourceCoordR.y;\n"
" vec2 SourceCoordG = TanEyeAngleG * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
- " SourceCoordG.y = 1 - SourceCoordG.y;\n"
+ " SourceCoordG.y = 1.0 - SourceCoordG.y;\n"
" vec2 SourceCoordB = TanEyeAngleB * EyeToSourceUVScale + EyeToSourceUVOffset;\n"
- " SourceCoordB.y = 1 - SourceCoordB.y;\n"
+ " SourceCoordB.y = 1.0 - SourceCoordB.y;\n"
// Find the distance to the nearest edge.
" vec2 NDCCoord = TanEyeAngleG * EyeToSourceNDCScale + EyeToSourceNDCOffset;\n"
- " float EdgeFadeIn = clamp ( EdgeFadeScale, 0, 1e5 ) * ( 1.0 - max ( abs ( NDCCoord.x ), abs ( NDCCoord.y ) ) );\n"
+ " float EdgeFadeIn = clamp ( EdgeFadeScale, 0.0, 1e5 ) * ( 1.0 - max ( abs ( NDCCoord.x ), abs ( NDCCoord.y ) ) );\n"
" if ( EdgeFadeIn < 0.0 )\n"
" {\n"
" gl_FragColor = vec4(DistortionClearColor.r, DistortionClearColor.g, DistortionClearColor.b, 1.0);\n"
- " return;\n"
+ " return;\n"
" }\n"
" EdgeFadeIn = clamp ( EdgeFadeIn, 0.0, 1.0 );\n"
@@ -583,7 +664,7 @@ static const char* PostProcessFragShaderWithChromAbSrc =
" float ResultG = texture2D(Texture, SourceCoordG).g;\n"
" float ResultB = texture2D(Texture, SourceCoordB).b;\n"
- " gl_FragColor = vec4(ResultR * EdgeFadeIn, ResultG * EdgeFadeIn, ResultB * EdgeFadeIn, 1.0);\n"
+ " gl_FragColor = vec4(ResultR * EdgeFadeIn, ResultG * EdgeFadeIn, ResultB * EdgeFadeIn, 1.0);\n"
"}\n";
@@ -595,7 +676,8 @@ static const char* VShaderSrcs[VShader_Count] =
PostProcessVertexShaderSrc,
PostProcessMeshVertexShaderSrc,
PostProcessMeshTimewarpVertexShaderSrc,
- PostProcessMeshPositionalTimewarpVertexShaderSrc
+ PostProcessMeshPositionalTimewarpVertexShaderSrc,
+ PostProcessHeightmapTimewarpVertexShaderSrc,
};
static const char* FShaderSrcs[FShader_Count] =
{
@@ -609,24 +691,71 @@ static const char* FShaderSrcs[FShader_Count] =
MultiTextureFragShaderSrc,
PostProcessMeshFragShaderSrc,
PostProcessMeshTimewarpFragShaderSrc,
- PostProcessMeshPositionalTimewarpFragShaderSrc
+ PostProcessMeshPositionalTimewarpFragShaderSrc,
+ PostProcessHeightmapTimewarpFragShaderSrc
};
RenderDevice::RenderDevice(const RendererParams&)
{
+ int GlMajorVersion = 0;
+ int GlMinorVersion = 0;
+
+ const char* glVersionString = (const char*)glGetString(GL_VERSION);
+ char prefix[64];
+ bool foundVersion = false;
+
+ for (int i = 10; i < 30; ++i)
+ {
+ int major = i / 10;
+ int minor = i % 10;
+ OVR_sprintf(prefix, 64, "%d.%d", major, minor);
+ if (strstr(glVersionString, prefix) == glVersionString)
+ {
+ GlMajorVersion = major;
+ GlMinorVersion = minor;
+ foundVersion = true;
+ break;
+ }
+ }
+
+ if (!foundVersion)
+ {
+ glGetIntegerv(GL_MAJOR_VERSION, &GlMajorVersion);
+ glGetIntegerv(GL_MAJOR_VERSION, &GlMinorVersion);
+ }
+
+ if (GlMajorVersion >= 3)
+ {
+ SupportsVao = true;
+ }
+ else
+ {
+ const char* extensions = (const char*)glGetString(GL_EXTENSIONS);
+ SupportsVao = (strstr("GL_ARB_vertex_array_object", extensions) != NULL);
+ }
+
for (int i = 0; i < VShader_Count; i++)
+ {
+ OVR_ASSERT ( VShaderSrcs[i] != NULL ); // You forgot a shader!
VertexShaders[i] = *new Shader(this, Shader_Vertex, VShaderSrcs[i]);
+ }
for (int i = 0; i < FShader_Count; i++)
+ {
+ OVR_ASSERT ( FShaderSrcs[i] != NULL ); // You forgot a shader!
FragShaders[i] = *new Shader(this, Shader_Fragment, FShaderSrcs[i]);
+ }
Ptr<ShaderSet> gouraudShaders = *new ShaderSet();
gouraudShaders->SetShader(VertexShaders[VShader_MVP]);
gouraudShaders->SetShader(FragShaders[FShader_Gouraud]);
DefaultFill = *new ShaderFill(gouraudShaders);
- glGenFramebuffersEXT(1, &CurrentFbo);
+ glGenFramebuffers(1, &CurrentFbo);
+
+ if (SupportsVao)
+ glGenVertexArrays(1, &Vao);
}
RenderDevice::~RenderDevice()
@@ -641,7 +770,10 @@ void RenderDevice::Shutdown()
// This runs before the subclass's Shutdown(), where the context, etc, may be deleted.
- glDeleteFramebuffersEXT(1, &CurrentFbo);
+ glDeleteFramebuffers(1, &CurrentFbo);
+
+ if (SupportsVao)
+ glDeleteVertexArrays(1, &Vao);
for (int i = 0; i < VShader_Count; ++i)
VertexShaders[i].Clear();
@@ -674,17 +806,14 @@ Shader *RenderDevice::LoadBuiltinShader(ShaderStage stage, int shader)
void RenderDevice::BeginRendering()
{
+ //glEnable(GL_FRAMEBUFFER_SRGB);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CW);
- glLineWidth(3.0f);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
}
void RenderDevice::SetDepthMode(bool enable, bool write, CompareFunc func)
@@ -707,15 +836,12 @@ void RenderDevice::SetDepthMode(bool enable, bool write, CompareFunc func)
void RenderDevice::SetViewport(const Recti& vp)
{
- int wh;
- if (CurRenderTarget)
- wh = CurRenderTarget->Height;
- else
- wh = WindowHeight;
- glViewport(vp.x, wh-vp.y-vp.h, vp.w, vp.h);
-
- //glEnable(GL_SCISSOR_TEST);
- //glScissor(vp.x, wh-vp.y-vp.h, vp.w, vp.h);
+ int wh;
+ if (CurRenderTarget)
+ wh = CurRenderTarget->Height;
+ else
+ wh = WindowHeight;
+ glViewport(vp.x, wh - vp.y - vp.h, vp.w, vp.h);
}
void RenderDevice::WaitUntilGpuIdle()
@@ -752,22 +878,22 @@ void RenderDevice::SetRenderTarget(Render::Texture* color, Render::Texture* dept
CurRenderTarget = (Texture*)color;
if (color == NULL)
{
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
return;
}
if (depth == NULL)
depth = GetDepthBuffer(color->GetWidth(), color->GetHeight(), CurRenderTarget->GetSamples());
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, CurrentFbo);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, ((Texture*)color)->TexId, 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, CurrentFbo);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ((Texture*)color)->TexId, 0);
if (depth)
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, ((Texture*)depth)->TexId, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, ((Texture*)depth)->TexId, 0);
else
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
- GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
- if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ if (status != GL_FRAMEBUFFER_COMPLETE)
OVR_DEBUG_LOG(("framebuffer not complete: %x", status));
}
@@ -781,7 +907,6 @@ void RenderDevice::SetTexture(Render::ShaderStage, int slot, const Texture* t)
{
glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(GL_TEXTURE_2D, ((Texture*)t)->TexId);
- glActiveTexture(GL_TEXTURE0);
}
Buffer* RenderDevice::CreateBuffer()
@@ -797,17 +922,20 @@ Fill* RenderDevice::CreateSimpleFill(int flags)
void RenderDevice::Render(const Matrix4f& matrix, Model* model)
{
+ if (SupportsVao)
+ glBindVertexArray(Vao);
+
// Store data in buffers if not already
if (!model->VertexBuffer)
{
Ptr<Render::Buffer> vb = *CreateBuffer();
- vb->Data(Buffer_Vertex, &model->Vertices[0], model->Vertices.GetSize() * sizeof(Vertex));
+ vb->Data(Buffer_Vertex | Buffer_ReadOnly, &model->Vertices[0], model->Vertices.GetSize() * sizeof(Vertex));
model->VertexBuffer = vb;
}
if (!model->IndexBuffer)
{
Ptr<Render::Buffer> ib = *CreateBuffer();
- ib->Data(Buffer_Index, &model->Indices[0], model->Indices.GetSize() * 2);
+ ib->Data(Buffer_Index | Buffer_ReadOnly, &model->Indices[0], model->Indices.GetSize() * 2);
model->IndexBuffer = ib;
}
@@ -817,7 +945,7 @@ void RenderDevice::Render(const Matrix4f& matrix, Model* model)
}
void RenderDevice::Render(const Fill* fill, Render::Buffer* vertices, Render::Buffer* indices,
- const Matrix4f& matrix, int offset, int count, PrimitiveType rprim, bool useDistortionVertex/* = false*/)
+ const Matrix4f& matrix, int offset, int count, PrimitiveType rprim, MeshType meshType /*= Mesh_Scene*/)
{
ShaderSet* shaders = (ShaderSet*) ((ShaderFill*)fill)->GetShaders();
@@ -854,28 +982,33 @@ void RenderDevice::Render(const Fill* fill, Render::Buffer* vertices, Render::Bu
for (int i = 0; i < 5; i++)
glEnableVertexAttribArray(i);
- if (useDistortionVertex)
- {
- glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof(DistortionVertex), (char*)offset + offsetof(DistortionVertex, Pos));
- glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, true, sizeof(DistortionVertex), (char*)offset + offsetof(DistortionVertex, Col));
- glVertexAttribPointer(2, 2, GL_FLOAT, false, sizeof(DistortionVertex), (char*)offset + offsetof(DistortionVertex, TexR));
- glVertexAttribPointer(3, 2, GL_FLOAT, false, sizeof(DistortionVertex), (char*)offset + offsetof(DistortionVertex, TexG));
- glVertexAttribPointer(4, 2, GL_FLOAT, false, sizeof(DistortionVertex), (char*)offset + offsetof(DistortionVertex, TexB));
- }
- else
- {
- glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(Vertex), (char*)offset + offsetof(Vertex, Pos));
- glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, true, sizeof(Vertex), (char*)offset + offsetof(Vertex, C));
- glVertexAttribPointer(2, 2, GL_FLOAT, false, sizeof(Vertex), (char*)offset + offsetof(Vertex, U));
- glVertexAttribPointer(3, 2, GL_FLOAT, false, sizeof(Vertex), (char*)offset + offsetof(Vertex, U2));
- glVertexAttribPointer(4, 3, GL_FLOAT, false, sizeof(Vertex), (char*)offset + offsetof(Vertex, Norm));
- }
+ switch (meshType)
+ {
+ case Mesh_Distortion:
+ glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof(DistortionVertex), reinterpret_cast<char*>(offset) + offsetof(DistortionVertex, Pos));
+ glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, true, sizeof(DistortionVertex), reinterpret_cast<char*>(offset) + offsetof(DistortionVertex, Col));
+ glVertexAttribPointer(2, 2, GL_FLOAT, false, sizeof(DistortionVertex), reinterpret_cast<char*>(offset) + offsetof(DistortionVertex, TexR));
+ glVertexAttribPointer(3, 2, GL_FLOAT, false, sizeof(DistortionVertex), reinterpret_cast<char*>(offset) + offsetof(DistortionVertex, TexG));
+ glVertexAttribPointer(4, 2, GL_FLOAT, false, sizeof(DistortionVertex), reinterpret_cast<char*>(offset) + offsetof(DistortionVertex, TexB));
+ break;
+
+ case Mesh_Heightmap:
+ glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof(HeightmapVertex), reinterpret_cast<char*>(offset) + offsetof(HeightmapVertex, Pos));
+ glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(HeightmapVertex), reinterpret_cast<char*>(offset) + offsetof(HeightmapVertex, Tex));
+ break;
+
+ default:
+ glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(Vertex), reinterpret_cast<char*>(offset) + offsetof(Vertex, Pos));
+ glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, true, sizeof(Vertex), reinterpret_cast<char*>(offset) + offsetof(Vertex, C));
+ glVertexAttribPointer(2, 2, GL_FLOAT, false, sizeof(Vertex), reinterpret_cast<char*>(offset) + offsetof(Vertex, U));
+ glVertexAttribPointer(3, 2, GL_FLOAT, false, sizeof(Vertex), reinterpret_cast<char*>(offset) + offsetof(Vertex, U2));
+ glVertexAttribPointer(4, 3, GL_FLOAT, false, sizeof(Vertex), reinterpret_cast<char*>(offset) + offsetof(Vertex, Norm));
+ }
if (indices)
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ((Buffer*)indices)->GLBuffer);
glDrawElements(prim, count, GL_UNSIGNED_SHORT, NULL);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
else
{
@@ -922,7 +1055,6 @@ bool Buffer::Data(int use, const void* buffer, size_t size)
glBindBuffer(Use, GLBuffer);
glBufferData(Use, size, buffer, mode);
- glBindBuffer(Use, 0);
return 1;
}
@@ -934,7 +1066,6 @@ void* Buffer::Map(size_t, size_t, int)
glBindBuffer(Use, GLBuffer);
void* v = glMapBuffer(Use, mode);
- glBindBuffer(Use, 0);
return v;
}
@@ -942,7 +1073,6 @@ bool Buffer::Unmap(void*)
{
glBindBuffer(Use, GLBuffer);
int r = glUnmapBuffer(Use);
- glBindBuffer(Use, 0);
return r != 0;
}
@@ -997,7 +1127,6 @@ void ShaderSet::UnsetShader(int stage)
if (gls)
glDetachShader(Prog, gls->GLShader);
Shaders[stage] = NULL;
- Link();
}
bool ShaderSet::Link()
@@ -1160,7 +1289,7 @@ void Texture::SetSampleMode(int sm)
case Sample_Anisotropic:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4);
break;
case Sample_Nearest:
@@ -1187,7 +1316,6 @@ void Texture::SetSampleMode(int sm)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
break;
}
- glBindTexture(GL_TEXTURE_2D, 0);
}
ovrTexture Texture::Get_ovrTexture()
@@ -1210,7 +1338,7 @@ Texture* RenderDevice::CreateTexture(int format, int width, int height, const vo
switch(format & Texture_TypeMask)
{
case Texture_RGBA: glformat = GL_RGBA; break;
- case Texture_R: glformat = GL_ALPHA; break;
+ case Texture_R: glformat = GL_RED; break;
case Texture_Depth: glformat = GL_DEPTH_COMPONENT32F; gltype = GL_FLOAT; break;
case Texture_DXT1: glformat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
case Texture_DXT3: glformat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
@@ -1220,7 +1348,7 @@ Texture* RenderDevice::CreateTexture(int format, int width, int height, const vo
}
Texture* NewTex = new Texture(this, width, height);
glBindTexture(GL_TEXTURE_2D, NewTex->TexId);
- OVR_ASSERT(!glGetError());
+ OVR_ASSERT(!glGetError());
if (format & Texture_Compressed)
{
@@ -1275,7 +1403,6 @@ Texture* RenderDevice::CreateTexture(int format, int width, int height, const vo
}
OVR_ASSERT(!glGetError());
- glBindTexture(GL_TEXTURE_2D, 0);
return NewTex;
}
@@ -1283,16 +1410,16 @@ RBuffer::RBuffer(GLenum format, GLint w, GLint h)
{
Width = w;
Height = h;
- glGenRenderbuffersEXT(1, &BufId);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, BufId);
- glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, format, w, h);
- glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
+ glGenRenderbuffers(1, &BufId);
+ glBindRenderbuffer(GL_RENDERBUFFER, BufId);
+ glRenderbufferStorage(GL_RENDERBUFFER, format, w, h);
+ glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
RBuffer::~RBuffer()
{
if (BufId)
- glDeleteRenderbuffersEXT(1, &BufId);
+ glDeleteRenderbuffers(1, &BufId);
}
}}}