diff --git a/Projects/Android/jni/Doom3Quest/Doom3Quest_SurfaceView.c b/Projects/Android/jni/Doom3Quest/Doom3Quest_SurfaceView.c index 1845187..c4c3c57 100644 --- a/Projects/Android/jni/Doom3Quest/Doom3Quest_SurfaceView.c +++ b/Projects/Android/jni/Doom3Quest/Doom3Quest_SurfaceView.c @@ -256,8 +256,8 @@ static void EglInitExtensions() glExtensions.multi_view = strstr( allExtensions, "GL_OVR_multiview2" ) && strstr( allExtensions, "GL_OVR_multiview_multisampled_render_to_texture" ); - glExtensions.EXT_texture_border_clamp = false;//strstr( allExtensions, "GL_EXT_texture_border_clamp" ) || - //strstr( allExtensions, "GL_OES_texture_border_clamp" ); + glExtensions.EXT_texture_border_clamp = strstr( allExtensions, "GL_EXT_texture_border_clamp" ) || + strstr( allExtensions, "GL_OES_texture_border_clamp" ); } } @@ -500,114 +500,222 @@ static void ovrFramebuffer_Clear( ovrFramebuffer * frameBuffer ) typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); +#if !defined(GL_OVR_multiview) +/// static const int GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR = 0x9630; +/// static const int GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR = 0x9632; +/// static const int GL_MAX_VIEWS_OVR = 0x9631; +typedef void(GL_APIENTRY* PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC)( + GLenum target, + GLenum attachment, + GLuint texture, + GLint level, + GLint baseViewIndex, + GLsizei numViews); +#endif -static bool ovrFramebuffer_Create( ovrFramebuffer * frameBuffer, const GLenum colorFormat, const int width, const int height, const int multisamples ) -{ - frameBuffer->Width = width; +#if !defined(GL_OVR_multiview_multisampled_render_to_texture) +typedef void(GL_APIENTRY* PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEMULTIVIEWOVRPROC)( + GLenum target, + GLenum attachment, + GLuint texture, + GLint level, + GLsizei samples, + GLint baseViewIndex, + GLsizei numViews); +#endif + +static bool ovrFramebuffer_Create( + ovrFramebuffer* frameBuffer, + const bool useMultiview, + const GLenum colorFormat, + const int width, + const int height, + const int multisamples) { + PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC glRenderbufferStorageMultisampleEXT = + (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC)eglGetProcAddress( + "glRenderbufferStorageMultisampleEXT"); + PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC glFramebufferTexture2DMultisampleEXT = + (PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC)eglGetProcAddress( + "glFramebufferTexture2DMultisampleEXT"); + + PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC glFramebufferTextureMultiviewOVR = + (PFNGLFRAMEBUFFERTEXTUREMULTIVIEWOVRPROC)eglGetProcAddress( + "glFramebufferTextureMultiviewOVR"); + PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEMULTIVIEWOVRPROC glFramebufferTextureMultisampleMultiviewOVR = + (PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEMULTIVIEWOVRPROC)eglGetProcAddress( + "glFramebufferTextureMultisampleMultiviewOVR"); + + frameBuffer->Width = width; frameBuffer->Height = height; frameBuffer->Multisamples = multisamples; + frameBuffer->UseMultiview = + (useMultiview && (glFramebufferTextureMultiviewOVR != NULL)) ? true : false; - frameBuffer->ColorTextureSwapChain = vrapi_CreateTextureSwapChain3( VRAPI_TEXTURE_TYPE_2D, colorFormat, frameBuffer->Width, frameBuffer->Height, 1, 3 ); - if (frameBuffer->ColorTextureSwapChain == NULL) - { - ALOGE("Couldn't create swap chain"); - return false; - } + frameBuffer->ColorTextureSwapChain = vrapi_CreateTextureSwapChain3( + frameBuffer->UseMultiview ? VRAPI_TEXTURE_TYPE_2D_ARRAY : VRAPI_TEXTURE_TYPE_2D, + colorFormat, + width, + height, + 1, + 3); + frameBuffer->TextureSwapChainLength = + vrapi_GetTextureSwapChainLength(frameBuffer->ColorTextureSwapChain); + frameBuffer->DepthBuffers = + (GLuint*)malloc(frameBuffer->TextureSwapChainLength * sizeof(GLuint)); + frameBuffer->FrameBuffers = + (GLuint*)malloc(frameBuffer->TextureSwapChainLength * sizeof(GLuint)); - frameBuffer->TextureSwapChainLength = vrapi_GetTextureSwapChainLength( frameBuffer->ColorTextureSwapChain ); - frameBuffer->DepthBuffers = (GLuint *)malloc( frameBuffer->TextureSwapChainLength * sizeof( GLuint ) ); - frameBuffer->FrameBuffers = (GLuint *)malloc( frameBuffer->TextureSwapChainLength * sizeof( GLuint ) ); + ALOGV(" frameBuffer->UseMultiview = %d", frameBuffer->UseMultiview); - PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC glRenderbufferStorageMultisampleEXT = - (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC)eglGetProcAddress("glRenderbufferStorageMultisampleEXT"); - PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC glFramebufferTexture2DMultisampleEXT = - (PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC)eglGetProcAddress("glFramebufferTexture2DMultisampleEXT"); - - for ( int i = 0; i < frameBuffer->TextureSwapChainLength; i++ ) - { + for (int i = 0; i < frameBuffer->TextureSwapChainLength; i++) { // Create the color buffer texture. - const GLuint colorTexture = vrapi_GetTextureSwapChainHandle( frameBuffer->ColorTextureSwapChain, i ); - GLenum colorTextureTarget = GL_TEXTURE_2D; - GL( glBindTexture( colorTextureTarget, colorTexture ) ); - // Just clamp to edge. However, this requires manually clearing the border - // around the layer to clear the edge texels. - GL( glTexParameteri( colorTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ) ); - GL( glTexParameteri( colorTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ) ); + const GLuint colorTexture = + vrapi_GetTextureSwapChainHandle(frameBuffer->ColorTextureSwapChain, i); + GLenum colorTextureTarget = frameBuffer->UseMultiview ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D; + GL(glBindTexture(colorTextureTarget, colorTexture)); + GL(glTexParameteri(colorTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER)); + GL(glTexParameteri(colorTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER)); + GLfloat borderColor[] = {0.0f, 0.0f, 0.0f, 0.0f}; + GL(glTexParameterfv(colorTextureTarget, GL_TEXTURE_BORDER_COLOR, borderColor)); + GL(glTexParameteri(colorTextureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + GL(glTexParameteri(colorTextureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + GL(glBindTexture(colorTextureTarget, 0)); - GL( glTexParameteri( colorTextureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR ) ); - GL( glTexParameteri( colorTextureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) ); - GL( glBindTexture( colorTextureTarget, 0 ) ); + if (frameBuffer->UseMultiview) { + // Create the depth buffer texture. + GL(glGenTextures(1, &frameBuffer->DepthBuffers[i])); + GL(glBindTexture(GL_TEXTURE_2D_ARRAY, frameBuffer->DepthBuffers[i])); + GL(glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_DEPTH_COMPONENT24, width, height, 2)); + GL(glBindTexture(GL_TEXTURE_2D_ARRAY, 0)); - if (multisamples > 1 && glRenderbufferStorageMultisampleEXT != NULL && glFramebufferTexture2DMultisampleEXT != NULL) - { + // Create the frame buffer. + GL(glGenFramebuffers(1, &frameBuffer->FrameBuffers[i])); + GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->FrameBuffers[i])); + if (multisamples > 1 && (glFramebufferTextureMultisampleMultiviewOVR != NULL)) { + GL(glFramebufferTextureMultisampleMultiviewOVR( + GL_DRAW_FRAMEBUFFER, + GL_DEPTH_ATTACHMENT, + frameBuffer->DepthBuffers[i], + 0 /* level */, + multisamples /* samples */, + 0 /* baseViewIndex */, + 2 /* numViews */)); + GL(glFramebufferTextureMultisampleMultiviewOVR( + GL_DRAW_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + colorTexture, + 0 /* level */, + multisamples /* samples */, + 0 /* baseViewIndex */, + 2 /* numViews */)); + } else { + GL(glFramebufferTextureMultiviewOVR( + GL_DRAW_FRAMEBUFFER, + GL_DEPTH_ATTACHMENT, + frameBuffer->DepthBuffers[i], + 0 /* level */, + 0 /* baseViewIndex */, + 2 /* numViews */)); + GL(glFramebufferTextureMultiviewOVR( + GL_DRAW_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + colorTexture, + 0 /* level */, + 0 /* baseViewIndex */, + 2 /* numViews */)); + } - // Create multisampled depth buffer. - GL(glGenRenderbuffers(1, &frameBuffer->DepthBuffers[i])); - GL(glBindRenderbuffer(GL_RENDERBUFFER, frameBuffer->DepthBuffers[i])); - GL(glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, multisamples, GL_DEPTH24_STENCIL8, width, height)); - GL(glBindRenderbuffer(GL_RENDERBUFFER, 0)); + GL(GLenum renderFramebufferStatus = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER)); + GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); + if (renderFramebufferStatus != GL_FRAMEBUFFER_COMPLETE) { + ALOGE( + "Incomplete frame buffer object: %s", + GlFrameBufferStatusString(renderFramebufferStatus)); + return false; + } + } else { + if (multisamples > 1 && glRenderbufferStorageMultisampleEXT != NULL && + glFramebufferTexture2DMultisampleEXT != NULL) { + // Create multisampled depth buffer. + GL(glGenRenderbuffers(1, &frameBuffer->DepthBuffers[i])); + GL(glBindRenderbuffer(GL_RENDERBUFFER, frameBuffer->DepthBuffers[i])); + GL(glRenderbufferStorageMultisampleEXT( + GL_RENDERBUFFER, multisamples, GL_DEPTH_COMPONENT24, width, height)); + GL(glBindRenderbuffer(GL_RENDERBUFFER, 0)); - // Create the frame buffer. - GL(glGenFramebuffers(1, &frameBuffer->FrameBuffers[i])); - GL(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer->FrameBuffers[i])); - GL(glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0, multisamples)); - GL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, frameBuffer->DepthBuffers[i])); - GL(GLenum renderFramebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER)); - GL(glBindFramebuffer(GL_FRAMEBUFFER, 0)); - if (renderFramebufferStatus != GL_FRAMEBUFFER_COMPLETE) - { - ALOGE("OVRHelper::Incomplete frame buffer object: %s", GlFrameBufferStatusString(renderFramebufferStatus)); - return false; - } - } - else - { - { - // Create depth buffer. - GL( glGenRenderbuffers( 1, &frameBuffer->DepthBuffers[i] ) ); - GL( glBindRenderbuffer( GL_RENDERBUFFER, frameBuffer->DepthBuffers[i] ) ); - GL( glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, frameBuffer->Width, frameBuffer->Height ) ); - GL( glBindRenderbuffer( GL_RENDERBUFFER, 0 ) ); + // Create the frame buffer. + // NOTE: glFramebufferTexture2DMultisampleEXT only works with GL_FRAMEBUFFER. + GL(glGenFramebuffers(1, &frameBuffer->FrameBuffers[i])); + GL(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer->FrameBuffers[i])); + GL(glFramebufferTexture2DMultisampleEXT( + GL_FRAMEBUFFER, + GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, + colorTexture, + 0, + multisamples)); + GL(glFramebufferRenderbuffer( + GL_FRAMEBUFFER, + GL_DEPTH_ATTACHMENT, + GL_RENDERBUFFER, + frameBuffer->DepthBuffers[i])); + GL(GLenum renderFramebufferStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER)); + GL(glBindFramebuffer(GL_FRAMEBUFFER, 0)); + if (renderFramebufferStatus != GL_FRAMEBUFFER_COMPLETE) { + ALOGE( + "Incomplete frame buffer object: %s", + GlFrameBufferStatusString(renderFramebufferStatus)); + return false; + } + } else { + // Create depth buffer. + GL(glGenRenderbuffers(1, &frameBuffer->DepthBuffers[i])); + GL(glBindRenderbuffer(GL_RENDERBUFFER, frameBuffer->DepthBuffers[i])); + GL(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height)); + GL(glBindRenderbuffer(GL_RENDERBUFFER, 0)); - // Create the frame buffer. - GL( glGenFramebuffers( 1, &frameBuffer->FrameBuffers[i] ) ); - GL( glBindFramebuffer( GL_DRAW_FRAMEBUFFER, frameBuffer->FrameBuffers[i] ) ); - GL( glFramebufferRenderbuffer( GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, frameBuffer->DepthBuffers[i] ) ); - GL( glFramebufferTexture2D( GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0 ) ); - GL( GLenum renderFramebufferStatus = glCheckFramebufferStatus( GL_DRAW_FRAMEBUFFER ) ); - GL( glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ) ); - if ( renderFramebufferStatus != GL_FRAMEBUFFER_COMPLETE ) - { - ALOGE( "Incomplete frame buffer object: %s", GlFrameBufferStatusString( renderFramebufferStatus ) ); - return false; - } - } - } + // Create the frame buffer. + GL(glGenFramebuffers(1, &frameBuffer->FrameBuffers[i])); + GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, frameBuffer->FrameBuffers[i])); + GL(glFramebufferRenderbuffer( + GL_DRAW_FRAMEBUFFER, + GL_DEPTH_ATTACHMENT, + GL_RENDERBUFFER, + frameBuffer->DepthBuffers[i])); + GL(glFramebufferTexture2D( + GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0)); + GL(GLenum renderFramebufferStatus = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER)); + GL(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0)); + if (renderFramebufferStatus != GL_FRAMEBUFFER_COMPLETE) { + ALOGE( + "Incomplete frame buffer object: %s", + GlFrameBufferStatusString(renderFramebufferStatus)); + return false; + } + } + } } return true; } -void ovrFramebuffer_Destroy( ovrFramebuffer * frameBuffer ) -{ - GL( glDeleteFramebuffers( frameBuffer->TextureSwapChainLength, frameBuffer->FrameBuffers ) ); - GL( glDeleteRenderbuffers( frameBuffer->TextureSwapChainLength, frameBuffer->DepthBuffers ) ); +void ovrFramebuffer_Destroy(ovrFramebuffer* frameBuffer) { + GL(glDeleteFramebuffers(frameBuffer->TextureSwapChainLength, frameBuffer->FrameBuffers)); + if (frameBuffer->UseMultiview) { + GL(glDeleteTextures(frameBuffer->TextureSwapChainLength, frameBuffer->DepthBuffers)); + } else { + GL(glDeleteRenderbuffers(frameBuffer->TextureSwapChainLength, frameBuffer->DepthBuffers)); + } + vrapi_DestroyTextureSwapChain(frameBuffer->ColorTextureSwapChain); - vrapi_DestroyTextureSwapChain( frameBuffer->ColorTextureSwapChain ); + free(frameBuffer->DepthBuffers); + free(frameBuffer->FrameBuffers); - free( frameBuffer->DepthBuffers ); - free( frameBuffer->FrameBuffers ); - - ovrFramebuffer_Clear( frameBuffer ); + ovrFramebuffer_Clear(frameBuffer); } void ovrFramebuffer_SetCurrent( ovrFramebuffer * frameBuffer ) { - while (glGetError() != GL_NO_ERROR) - { - - } - GL( glBindFramebuffer( GL_FRAMEBUFFER, frameBuffer->FrameBuffers[frameBuffer->ProcessingTextureSwapChainIndex] ) ); } @@ -621,9 +729,6 @@ void ovrFramebuffer_Resolve( ovrFramebuffer * frameBuffer ) // Discard the depth buffer, so the tiler won't need to write it back out to memory. const GLenum depthAttachment[1] = { GL_DEPTH_ATTACHMENT }; glInvalidateFramebuffer( GL_DRAW_FRAMEBUFFER, 1, depthAttachment ); - - // Flush this frame worth of commands. - glFlush(); } void ovrFramebuffer_Advance( ovrFramebuffer * frameBuffer ) @@ -673,10 +778,7 @@ ovrRenderer void ovrRenderer_Clear( ovrRenderer * renderer ) { - for ( int eye = 0; eye < VRAPI_FRAME_LAYER_EYE_MAX; eye++ ) - { - ovrFramebuffer_Clear( &renderer->FrameBuffer[eye] ); - } + ovrFramebuffer_Clear( &renderer->FrameBuffer ); renderer->ProjectionMatrix = ovrMatrix4f_CreateIdentity(); renderer->NumBuffers = VRAPI_FRAME_LAYER_EYE_MAX; } @@ -684,20 +786,18 @@ void ovrRenderer_Clear( ovrRenderer * renderer ) void ovrRenderer_Create( int width, int height, ovrRenderer * renderer, const ovrJava * java ) { - renderer->NumBuffers = VRAPI_FRAME_LAYER_EYE_MAX; + renderer->NumBuffers = 1; // Multiview //Now using a symmetrical render target, based on the horizontal FOV vrFOV = vrapi_GetSystemPropertyInt( java, VRAPI_SYS_PROP_SUGGESTED_EYE_FOV_DEGREES_X); - // Create the render Textures. - for ( int eye = 0; eye < VRAPI_FRAME_LAYER_EYE_MAX; eye++ ) - { - ovrFramebuffer_Create( &renderer->FrameBuffer[eye], - GL_RGBA8, - width, - height, - NUM_MULTI_SAMPLES ); - } + // Create the multi view frame buffer + ovrFramebuffer_Create( &renderer->FrameBuffer, + true, + GL_RGBA8, + width, + height, + NUM_MULTI_SAMPLES ); // Setup the projection matrix. renderer->ProjectionMatrix = ovrMatrix4f_CreateProjectionFov( @@ -707,10 +807,7 @@ void ovrRenderer_Create( int width, int height, ovrRenderer * renderer, const ov void ovrRenderer_Destroy( ovrRenderer * renderer ) { - for ( int eye = 0; eye < renderer->NumBuffers; eye++ ) - { - ovrFramebuffer_Destroy( &renderer->FrameBuffer[eye] ); - } + ovrFramebuffer_Destroy( &renderer->FrameBuffer ); renderer->ProjectionMatrix = ovrMatrix4f_CreateIdentity(); } @@ -1266,15 +1363,15 @@ void VR_Init() shutdown = false; } -long renderThreadCPUTime[2] = {0, 0}; +long renderThreadCPUTime = 0; void Doom3Quest_prepareEyeBuffer(int eye ) { - renderThreadCPUTime[eye] = GetTimeInMilliSeconds(); + renderThreadCPUTime = GetTimeInMilliSeconds(); ovrRenderer *renderer = Doom3Quest_useScreenLayer() ? &gAppState.Scene.CylinderRenderer : &gAppState.Renderer; - ovrFramebuffer *frameBuffer = &(renderer->FrameBuffer[eye]); + ovrFramebuffer *frameBuffer = &(renderer->FrameBuffer); ovrFramebuffer_SetCurrent(frameBuffer); GL(glEnable(GL_SCISSOR_TEST)); @@ -1291,23 +1388,19 @@ void Doom3Quest_prepareEyeBuffer(int eye ) GL(glDisable(GL_SCISSOR_TEST)); } -void Doom3Quest_finishEyeBuffer(int eye ) +void Doom3Quest_finishEyeBuffer( ) { - renderThreadCPUTime[eye] = GetTimeInMilliSeconds() - renderThreadCPUTime[eye]; + renderThreadCPUTime = GetTimeInMilliSeconds() - renderThreadCPUTime; - if (eye == 1) { - int totalTime = renderThreadCPUTime[0] + renderThreadCPUTime[1]; - //__android_log_print(ANDROID_LOG_INFO, "Doom3Quest", "RENDER THREAD LEFT EYE CPU TIME: %i", renderThreadCPUTime[0]); - //__android_log_print(ANDROID_LOG_INFO, "Doom3Quest", "RENDER THREAD RIGHT EYE CPU TIME: %i", renderThreadCPUTime[1]); - __android_log_print(ANDROID_LOG_INFO, "Doom3Quest", "RENDER THREAD TOTAL CPU TIME: %i", totalTime); + __android_log_print(ANDROID_LOG_INFO, "Doom3Quest", "RENDER THREAD TOTAL CPU TIME: %i", renderThreadCPUTime); } GLCheckErrors( __LINE__ ); ovrRenderer *renderer = Doom3Quest_useScreenLayer() ? &gAppState.Scene.CylinderRenderer : &gAppState.Renderer; - ovrFramebuffer *frameBuffer = &(renderer->FrameBuffer[eye]); + ovrFramebuffer *frameBuffer = &(renderer->FrameBuffer); //Clear edge to prevent smearing ovrFramebuffer_ClearEdgeTexels(frameBuffer); @@ -1654,7 +1747,7 @@ void Doom3Quest_submitFrame() layer.HeadPose = gAppState.Tracking[renderThreadFrameIndex % MAX_TRACKING_SAMPLES].HeadPose; for ( int eye = 0; eye < VRAPI_FRAME_LAYER_EYE_MAX; eye++ ) { - ovrFramebuffer * frameBuffer = &gAppState.Renderer.FrameBuffer[gAppState.Renderer.NumBuffers == 1 ? 0 : eye]; + ovrFramebuffer * frameBuffer = &gAppState.Renderer.FrameBuffer; layer.Textures[eye].ColorSwapChain = frameBuffer->ColorTextureSwapChain; layer.Textures[eye].SwapChainIndex = frameBuffer->ReadyTextureSwapChainIndex; diff --git a/Projects/Android/jni/Doom3Quest/VrCommon.h b/Projects/Android/jni/Doom3Quest/VrCommon.h index 161bcf8..4395960 100644 --- a/Projects/Android/jni/Doom3Quest/VrCommon.h +++ b/Projects/Android/jni/Doom3Quest/VrCommon.h @@ -84,9 +84,9 @@ void Doom3Quest_getHMDOrientation(); void Doom3Quest_getTrackedRemotesOrientation(int controlscheme); -void Doom3Quest_prepareEyeBuffer(int eye); +void Doom3Quest_prepareEyeBuffer(); -void Doom3Quest_finishEyeBuffer(int eye); +void Doom3Quest_finishEyeBuffer(); void Doom3Quest_submitFrame(); diff --git a/Projects/Android/jni/Doom3Quest/VrCompositor.c b/Projects/Android/jni/Doom3Quest/VrCompositor.c index c3c6c97..3da5fb3 100644 --- a/Projects/Android/jni/Doom3Quest/VrCompositor.c +++ b/Projects/Android/jni/Doom3Quest/VrCompositor.c @@ -118,10 +118,10 @@ ovrLayerCylinder2 BuildCylinderLayer( ovrRenderer * cylinderRenderer, const float circScale = density * 0.5f / textureWidth; const float circBias = -circScale * ( 0.5f * ( 1.0f - 1.0f / circScale ) ); + ovrFramebuffer * cylinderFrameBuffer = &cylinderRenderer->FrameBuffer; + for ( int eye = 0; eye < VRAPI_FRAME_LAYER_EYE_MAX; eye++ ) { - ovrFramebuffer * cylinderFrameBuffer = &cylinderRenderer->FrameBuffer[eye]; - ovrMatrix4f modelViewMatrix = ovrMatrix4f_Multiply( &tracking->Eye[eye].ViewMatrix, &cylinderTransform ); layer.Textures[eye].TexCoordsFromTanAngles = ovrMatrix4f_Inverse( &modelViewMatrix ); layer.Textures[eye].ColorSwapChain = cylinderFrameBuffer->ColorTextureSwapChain; diff --git a/Projects/Android/jni/Doom3Quest/VrCompositor.h b/Projects/Android/jni/Doom3Quest/VrCompositor.h index 39dd9ce..99148e6 100644 --- a/Projects/Android/jni/Doom3Quest/VrCompositor.h +++ b/Projects/Android/jni/Doom3Quest/VrCompositor.h @@ -64,6 +64,7 @@ typedef struct ovrTextureSwapChain * ColorTextureSwapChain; GLuint * DepthBuffers; GLuint * FrameBuffers; + bool UseMultiview; } ovrFramebuffer; void ovrFramebuffer_SetCurrent( ovrFramebuffer * frameBuffer ); @@ -83,7 +84,7 @@ ovrRenderer typedef struct { - ovrFramebuffer FrameBuffer[VRAPI_FRAME_LAYER_EYE_MAX]; + ovrFramebuffer FrameBuffer; ovrMatrix4f ProjectionMatrix; int NumBuffers; } ovrRenderer; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/framework/Console.cpp b/Projects/Android/jni/d3es-multithread-master/neo/framework/Console.cpp index 3517302..f15fb5f 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/framework/Console.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/framework/Console.cpp @@ -206,39 +206,29 @@ float SCR_DrawFPS( float y ) { int new_y = idMath::FtoiFast(y) + 300; - int eye = cvarSystem->GetCVarInteger("vr_eye"); - if (eye == 0) { - // don't use serverTime, because that will be drifting to - // correct for internet lag changes, timescales, timedemos, etc - t = Sys_Milliseconds(); - frameTime = t - previous; - previous = t; + // don't use serverTime, because that will be drifting to + // correct for internet lag changes, timescales, timedemos, etc + t = Sys_Milliseconds(); + frameTime = t - previous; + previous = t; - previousTimes[index % FPS_FRAMES] = frameTime; - index++; - if (index > FPS_FRAMES) { - // average multiple frames together to smooth changes out a bit - total = 0; - for (i = 0; i < FPS_FRAMES; i++) { - total += previousTimes[i]; - } - if (!total) { - total = 1; - } - fps = 10000 * FPS_FRAMES / total; - fps = (fps + 5) / 10; - - s = va("%ifps", fps); - w = strlen(s) * SMALLCHAR_WIDTH; - - renderSystem->DrawSmallStringExt((634 / 2) - w, new_y, s, colorWhite, true, - localConsole.charSetShader); + previousTimes[index % FPS_FRAMES] = frameTime; + index++; + if (index > FPS_FRAMES) { + // average multiple frames together to smooth changes out a bit + total = 0; + for (i = 0; i < FPS_FRAMES; i++) { + total += previousTimes[i]; } - } - else { - //For right eye just use same value + if (!total) { + total = 1; + } + fps = 10000 * FPS_FRAMES / total; + fps = (fps + 5) / 10; + s = va("%ifps", fps); w = strlen(s) * SMALLCHAR_WIDTH; + renderSystem->DrawSmallStringExt((634 / 2) - w, new_y, s, colorWhite, true, localConsole.charSetShader); } diff --git a/Projects/Android/jni/d3es-multithread-master/neo/framework/Session.cpp b/Projects/Android/jni/d3es-multithread-master/neo/framework/Session.cpp index dec3899..3340879 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/framework/Session.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/framework/Session.cpp @@ -2509,21 +2509,16 @@ void idSessionLocal::UpdateScreen( bool outOfSequence ) { Sys_GrabMouseCursor( false ); } - for (int eye = 0; eye < 2; ++eye) { + renderSystem->BeginFrame(renderSystem->GetScreenWidth(), renderSystem->GetScreenHeight()); - cvarSystem->SetCVarInteger("vr_eye", eye); + // draw everything + Draw(); - renderSystem->BeginFrame(renderSystem->GetScreenWidth(), renderSystem->GetScreenHeight()); - - // draw everything - Draw(); - - if (com_speeds.GetBool()) { - renderSystem->EndFrame(&time_frontend, &time_backend); - } else { - renderSystem->EndFrame(NULL, NULL); - } - } + if (com_speeds.GetBool()) { + renderSystem->EndFrame(&time_frontend, &time_backend); + } else { + renderSystem->EndFrame(NULL, NULL); + } insideUpdateScreen = false; } diff --git a/Projects/Android/jni/d3es-multithread-master/neo/game/PlayerView.cpp b/Projects/Android/jni/d3es-multithread-master/neo/game/PlayerView.cpp index 0b18836..1802f3a 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/game/PlayerView.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/game/PlayerView.cpp @@ -730,12 +730,12 @@ void idPlayerView::RenderPlayerView( idUserInterface *hud ) { { renderView_t *eyeView = view ? new renderView_t(*view) : NULL; - if (eyeView && +/* if (eyeView && !game->InCinematic()) { eyeView->vieworg += (vr_eye.GetInteger() == 0 ? 1.0f : -1.0f) * eyeView->viewaxis[1] * (vr_ipd.GetFloat() / 2.0f) * vr_worldscale.GetFloat(); - } + }*/ if (g_skipViewEffects.GetBool()) { SingleView(hud, eyeView); diff --git a/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.cpp b/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.cpp index 06d1c74..a612477 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.cpp @@ -341,7 +341,6 @@ idCVar net_serverDlTable( "net_serverDlTable", "", CVAR_GAME | CVAR_ARCHIV idCVar vr_ipd( "vr_ipd", "0.065", CVAR_GAME | CVAR_FLOAT | CVAR_ARCHIVE, "VR IPD" ); idCVar vr_worldscale( "vr_worldscale", "43.0", CVAR_GAME | CVAR_FLOAT | CVAR_ARCHIVE, "VR World Scale" ); idCVar vr_heightoffset( "vr_heightoffset", "0.0", CVAR_GAME | CVAR_FLOAT | CVAR_ARCHIVE, "VR Height Offset" ); -idCVar vr_eye( "vr_eye", "0", CVAR_GAME | CVAR_INTEGER, "VR Eye currently being drawn" ); idCVar vr_controlscheme( "vr_controlscheme", "0", CVAR_GAME | CVAR_INTEGER, "VR Control Scheme: 0 = right handed, 10 = left handed" ); idCVar vr_shakeamplitude( "vr_shakeamplitude", "0.8", CVAR_FLOAT | CVAR_ARCHIVE, "Screen shake amplitude 0.0 = disabled to 1.0 = full\n", 0.0f, 1.0f ); idCVar vr_knockback( "vr_knockback", "0", CVAR_BOOL | CVAR_ARCHIVE | CVAR_GAME, "Enable damage knockback in VR. 0 = Disabled, 1 = Enabled" ); diff --git a/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.h b/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.h index 1dde8cb..c78874b 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.h +++ b/Projects/Android/jni/d3es-multithread-master/neo/game/gamesys/SysCvar.h @@ -254,7 +254,6 @@ extern idCVar net_clientLagOMeter; //VR CVARS extern idCVar vr_ipd; extern idCVar vr_worldscale; -extern idCVar vr_eye; extern idCVar vr_heightoffset; extern idCVar vr_controlscheme; extern idCVar vr_shakeamplitude; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/GuiModel.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/GuiModel.cpp index 5bed97b..c78eb60 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/GuiModel.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/GuiModel.cpp @@ -161,7 +161,7 @@ void idGuiModel::ReadFromDemo( idDemoFile *demo ) { EmitSurface ================ */ -void idGuiModel::EmitSurface( guiModelSurface_t *surf, float modelMatrix[16], float modelViewMatrix[16], bool depthHack ) { +void idGuiModel::EmitSurface( guiModelSurface_t *surf, float modelMatrix[16], float centerModelViewMatrix[16], bool depthHack ) { srfTriangles_t *tri; if ( surf->numVerts == 0 ) { @@ -193,7 +193,9 @@ void idGuiModel::EmitSurface( guiModelSurface_t *surf, float modelMatrix[16], fl viewEntity_t *guiSpace = (viewEntity_t *)R_ClearedFrameAlloc( sizeof( *guiSpace ) ); memcpy( guiSpace->modelMatrix, modelMatrix, sizeof( guiSpace->modelMatrix ) ); - memcpy( guiSpace->modelViewMatrix, modelViewMatrix, sizeof( guiSpace->modelViewMatrix ) ); + memcpy( guiSpace->centerModelViewMatrix, centerModelViewMatrix, sizeof( guiSpace->centerModelViewMatrix ) ); + memcpy( guiSpace->modelViewMatrix[0], centerModelViewMatrix, sizeof( guiSpace->centerModelViewMatrix ) ); + memcpy( guiSpace->modelViewMatrix[1], centerModelViewMatrix, sizeof( guiSpace->centerModelViewMatrix ) ); guiSpace->weaponDepthHack = depthHack; // add the surface, which might recursively create another gui @@ -206,13 +208,13 @@ EmitToCurrentView ==================== */ void idGuiModel::EmitToCurrentView( float modelMatrix[16], bool depthHack ) { - float modelViewMatrix[16]; + float centerModelViewMatrix[16]; - myGlMultMatrix( modelMatrix, tr.viewDef->worldSpace.modelViewMatrix, - modelViewMatrix ); + myGlMultMatrix( modelMatrix, tr.viewDef->worldSpace.centerModelViewMatrix, + centerModelViewMatrix ); for ( int i = 0 ; i < surfaces.Num() ; i++ ) { - EmitSurface( &surfaces[i], modelMatrix, modelViewMatrix, depthHack ); + EmitSurface( &surfaces[i], modelMatrix, centerModelViewMatrix, depthHack ); } } @@ -273,10 +275,20 @@ void idGuiModel::EmitFullScreen( void ) { viewDef->projectionMatrix[14] = -1.0f; viewDef->projectionMatrix[15] = 1.0f; - viewDef->worldSpace.modelViewMatrix[0] = 1.0f; - viewDef->worldSpace.modelViewMatrix[5] = 1.0f; - viewDef->worldSpace.modelViewMatrix[10] = 1.0f; - viewDef->worldSpace.modelViewMatrix[15] = 1.0f; + for (int i = 0; i < 3; ++i) { + if (i < 2) + { + viewDef->worldSpace.modelViewMatrix[i][0] = 1.0f; + viewDef->worldSpace.modelViewMatrix[i][5] = 1.0f; + viewDef->worldSpace.modelViewMatrix[i][10] = 1.0f; + viewDef->worldSpace.modelViewMatrix[i][15] = 1.0f; + } else { + viewDef->worldSpace.centerModelViewMatrix[0] = 1.0f; + viewDef->worldSpace.centerModelViewMatrix[5] = 1.0f; + viewDef->worldSpace.centerModelViewMatrix[10] = 1.0f; + viewDef->worldSpace.centerModelViewMatrix[15] = 1.0f; + } + } viewDef->maxDrawSurfs = surfaces.Num(); viewDef->drawSurfs = (drawSurf_t **)R_FrameAlloc( viewDef->maxDrawSurfs * sizeof( viewDef->drawSurfs[0] ) ); @@ -287,7 +299,7 @@ void idGuiModel::EmitFullScreen( void ) { // add the surfaces to this view for ( int i = 0 ; i < surfaces.Num() ; i++ ) { - EmitSurface( &surfaces[i], viewDef->worldSpace.modelMatrix, viewDef->worldSpace.modelViewMatrix, false ); + EmitSurface( &surfaces[i], viewDef->worldSpace.modelMatrix, viewDef->worldSpace.centerModelViewMatrix, false ); } tr.viewDef = oldViewDef; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/RenderSystem.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/RenderSystem.cpp index 59eeaaa..7783b82 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/RenderSystem.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/RenderSystem.cpp @@ -258,7 +258,9 @@ void R_LockSurfaceScene( viewDef_t *parms ) { // update the view origin and axis, and all // the entity matricies for (vModel = tr.lockSurfacesCmd.viewDef->viewEntitys; vModel; vModel = vModel->next) { - myGlMultMatrix(vModel->modelMatrix, tr.lockSurfacesCmd.viewDef->worldSpace.modelViewMatrix, vModel->modelViewMatrix); + myGlMultMatrix(vModel->modelMatrix, tr.lockSurfacesCmd.viewDef->worldSpace.modelViewMatrix[0], vModel->modelViewMatrix[0]); + myGlMultMatrix(vModel->modelMatrix, tr.lockSurfacesCmd.viewDef->worldSpace.modelViewMatrix[1], vModel->modelViewMatrix[1]); + myGlMultMatrix(vModel->modelMatrix, tr.lockSurfacesCmd.viewDef->worldSpace.centerModelViewMatrix, vModel->centerModelViewMatrix); } // add the stored off surface commands again @@ -583,7 +585,7 @@ void idRenderSystemLocal::BeginFrame( int windowWidth, int windowHeight ) { cmd = (setBufferCommand_t *)R_GetCommandBuffer( sizeof( *cmd ) ); cmd->commandId = RC_SET_BUFFER; cmd->frameCount = frameCount; - cmd->buffer = cvarSystem->GetCVarInteger("vr_eye"); + cmd->buffer = 0; } diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/RenderWorld_portals.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/RenderWorld_portals.cpp index 966ddd3..c8798fc 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/RenderWorld_portals.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/RenderWorld_portals.cpp @@ -128,10 +128,10 @@ bool idRenderWorldLocal::PortalIsFoggedOut( const portal_t *p ) { a = -0.5f / alpha; } - forward[0] = a * tr.viewDef->worldSpace.modelViewMatrix[2]; - forward[1] = a * tr.viewDef->worldSpace.modelViewMatrix[6]; - forward[2] = a * tr.viewDef->worldSpace.modelViewMatrix[10]; - forward[3] = a * tr.viewDef->worldSpace.modelViewMatrix[14]; + forward[0] = a * tr.viewDef->worldSpace.centerModelViewMatrix[2]; + forward[1] = a * tr.viewDef->worldSpace.centerModelViewMatrix[6]; + forward[2] = a * tr.viewDef->worldSpace.centerModelViewMatrix[10]; + forward[3] = a * tr.viewDef->worldSpace.centerModelViewMatrix[14]; w = p->w; for ( i = 0 ; i < w->GetNumPoints() ; i++ ) { diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/draw_gles2.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/draw_gles2.cpp index e0f33ca..11ade19 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/draw_gles2.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/draw_gles2.cpp @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#include #include "sys/platform.h" #include "renderer/VertexCache.h" @@ -91,6 +92,33 @@ static void GL_UniformMatrix4fv(GLint location, const GLfloat* value) { qglUniformMatrix4fv(*( GLint * )((char*) backEnd.glState.currentProgram + location), 1, GL_FALSE, value); } +/* +==================== +GL_UniformMatrix4fv +==================== +*/ +static void GL_UniformBuffer(GLint location, const float value[32]) { + + // Update the scene matrices. + glBindBuffer(GL_UNIFORM_BUFFER, *( GLint * )((char*) backEnd.glState.currentProgram + location)); + float* shaderMatrices = (float*)glMapBufferRange( + GL_UNIFORM_BUFFER, + 0, + 32 * sizeof(float), + GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT); + + if (shaderMatrices == NULL) + { + common->Error("Shader Matrices Uniform Buffer is NULL"); + return; + } + + memcpy((char*)shaderMatrices, value, 32 * sizeof(float)); + + glUnmapBuffer(GL_UNIFORM_BUFFER); + qglBindBuffer(GL_UNIFORM_BUFFER, 0); +} + /* ==================== GL_EnableVertexAttribArray @@ -247,7 +275,27 @@ static void RB_GLSL_GetUniformLocations(shaderProgram_t* shader) { shader->glColor = qglGetUniformLocation(shader->program, "u_glColor"); shader->alphaTest = qglGetUniformLocation(shader->program, "u_alphaTest"); shader->specularExponent = qglGetUniformLocation(shader->program, "u_specularExponent"); - shader->modelViewProjectionMatrix = qglGetUniformLocation(shader->program, "u_modelViewProjectionMatrix"); + + GLuint shaderMatricesUniformLocation = glGetUniformBlockIndex(shader->program, "ShaderMatrices"); + + int numBufferBindings = 0; + shader->shaderMatricesBinding = numBufferBindings++; + glUniformBlockBinding( + shader->program, + shaderMatricesUniformLocation, + shader->shaderMatricesBinding); + + //Create the buffer + qglGenBuffers(1, &shader->shaderMatricesBuffer); + glBindBuffer(GL_UNIFORM_BUFFER, shader->shaderMatricesBuffer); + glBufferData( + GL_UNIFORM_BUFFER, + 2 * 16 * sizeof(float), + NULL, + GL_STATIC_DRAW); + glBindBuffer(GL_UNIFORM_BUFFER, 0); + + shader->modelViewMatrix = qglGetUniformLocation(shader->program, "u_modelViewMatrix"); shader->textureMatrix = qglGetUniformLocation(shader->program, "u_textureMatrix"); shader->clipPlane = qglGetUniformLocation(shader->program, "u_clipPlane"); @@ -475,7 +523,7 @@ RB_ComputeMVP Compute the model view matrix, with eventually required projection matrix depth hacks ================= */ -void RB_ComputeMVP( const drawSurf_t * const surf, float mvp[16] ) { +void RB_ComputeMVP( const drawSurf_t * const surf, float mvp[32] ) { // Get the projection matrix float localProjectionMatrix[16]; memcpy(localProjectionMatrix, backEnd.viewDef->projectionMatrix, sizeof(localProjectionMatrix)); @@ -488,7 +536,8 @@ void RB_ComputeMVP( const drawSurf_t * const surf, float mvp[16] ) { localProjectionMatrix[14] = backEnd.viewDef->projectionMatrix[14] - surf->space->modelDepthHack; } - myGlMultMatrix(surf->space->modelViewMatrix, localProjectionMatrix, mvp); + myGlMultMatrix(surf->space->modelViewMatrix[0], localProjectionMatrix, mvp); + myGlMultMatrix(surf->space->modelViewMatrix[1], localProjectionMatrix, (mvp + 16) ); } /* @@ -747,6 +796,12 @@ static void RB_GLSL_CreateDrawInteractions(const drawSurf_t* surf, const viewLig GL_UseProgram(&interactionShader); } + glBindBufferBase( + GL_UNIFORM_BUFFER, + backEnd.glState.currentProgram->shaderMatricesBinding, + backEnd.glState.currentProgram->shaderMatricesBuffer); + + // Setup attributes arrays // Vertex attribute is always enabled // Color attribute is always enabled @@ -762,9 +817,9 @@ static void RB_GLSL_CreateDrawInteractions(const drawSurf_t* surf, const viewLig // perform setup here that will not change over multiple interaction passes if ( surf->space != backEnd.currentSpace ) { - float mvp[16]; + float mvp[32]; RB_ComputeMVP(surf, mvp); - GL_UniformMatrix4fv(offsetof(shaderProgram_t, modelViewProjectionMatrix), mvp); + GL_UniformBuffer(offsetof(shaderProgram_t, shaderMatricesBuffer), mvp); } // Hack Depth Range if necessary @@ -922,10 +977,10 @@ void RB_GLSL_RenderDrawSurfChainWithFunction(const drawSurf_t* drawSurfs, // Change the MVP matrix if needed if ( drawSurf->space != backEnd.currentSpace ) { - float mvp[16]; + float mvp[32]; RB_ComputeMVP(drawSurf, mvp); // We can set the uniform now, as the shader is already bound - GL_UniformMatrix4fv(offsetof(shaderProgram_t, modelViewProjectionMatrix), mvp); + GL_UniformBuffer(offsetof(shaderProgram_t, shaderMatricesBuffer), mvp); } // Hack Depth Range if necessary @@ -996,6 +1051,11 @@ void RB_GLSL_StencilShadowPass(const drawSurf_t* drawSurfs, const viewLight_t* v // Use the stencil shadow shader GL_UseProgram(&stencilShadowShader); + glBindBufferBase( + GL_UNIFORM_BUFFER, + backEnd.glState.currentProgram->shaderMatricesBinding, + backEnd.glState.currentProgram->shaderMatricesBuffer); + // Setup attributes arrays // Vertex attribute is always enabled // Disable Color attribute (as it is enabled by default) @@ -1186,6 +1246,11 @@ void RB_GLSL_FogPass(const drawSurf_t* drawSurfs, const drawSurf_t* drawSurfs2, GL_UseProgram(&fogShader); + glBindBufferBase( + GL_UNIFORM_BUFFER, + backEnd.glState.currentProgram->shaderMatricesBinding, + backEnd.glState.currentProgram->shaderMatricesBuffer); + // Setup attributes arrays // Vertex attribute is always enabled // Disable Color attribute (as it is enabled by default) @@ -1225,15 +1290,15 @@ void RB_GLSL_FogPass(const drawSurf_t* drawSurfs, const drawSurf_t* drawSurfs2, // It is expected to be already active globalImages->fogImage->Bind(); - fogPlanes[0][0] = a * backEnd.viewDef->worldSpace.modelViewMatrix[2]; - fogPlanes[0][1] = a * backEnd.viewDef->worldSpace.modelViewMatrix[6]; - fogPlanes[0][2] = a * backEnd.viewDef->worldSpace.modelViewMatrix[10]; - fogPlanes[0][3] = a * backEnd.viewDef->worldSpace.modelViewMatrix[14]; + fogPlanes[0][0] = a * backEnd.viewDef->worldSpace.centerModelViewMatrix[2]; + fogPlanes[0][1] = a * backEnd.viewDef->worldSpace.centerModelViewMatrix[6]; + fogPlanes[0][2] = a * backEnd.viewDef->worldSpace.centerModelViewMatrix[10]; + fogPlanes[0][3] = a * backEnd.viewDef->worldSpace.centerModelViewMatrix[14]; - fogPlanes[1][0] = a * backEnd.viewDef->worldSpace.modelViewMatrix[0]; - fogPlanes[1][1] = a * backEnd.viewDef->worldSpace.modelViewMatrix[4]; - fogPlanes[1][2] = a * backEnd.viewDef->worldSpace.modelViewMatrix[8]; - fogPlanes[1][3] = a * backEnd.viewDef->worldSpace.modelViewMatrix[12]; + fogPlanes[1][0] = a * backEnd.viewDef->worldSpace.centerModelViewMatrix[0]; + fogPlanes[1][1] = a * backEnd.viewDef->worldSpace.centerModelViewMatrix[4]; + fogPlanes[1][2] = a * backEnd.viewDef->worldSpace.centerModelViewMatrix[8]; + fogPlanes[1][3] = a * backEnd.viewDef->worldSpace.centerModelViewMatrix[12]; // texture 1 is the entering plane fade correction GL_SelectTexture(1); @@ -1549,6 +1614,11 @@ void RB_GLSL_FillDepthBuffer(drawSurf_t** drawSurfs, int numDrawSurfs) { GL_UseProgram(&zfillShader); } + glBindBufferBase( + GL_UNIFORM_BUFFER, + backEnd.glState.currentProgram->shaderMatricesBinding, + backEnd.glState.currentProgram->shaderMatricesBuffer); + // Setup attributes arrays // Vertex attribute is always enabled // TexCoord attribute is always enabled @@ -1589,10 +1659,10 @@ void RB_GLSL_FillDepthBuffer(drawSurf_t** drawSurfs, int numDrawSurfs) { // Change the MVP matrix if needed if ( drawSurf->space != backEnd.currentSpace ) { - float mvp[16]; + float mvp[32]; RB_ComputeMVP(drawSurf, mvp); // We can set the uniform now as it shader is already bound - GL_UniformMatrix4fv(offsetof(shaderProgram_t, modelViewProjectionMatrix), mvp); + GL_UniformBuffer(offsetof(shaderProgram_t, shaderMatricesBuffer), mvp); } // Hack Depth Range if necessary @@ -1811,6 +1881,11 @@ void RB_GLSL_T_RenderShaderPasses(const drawSurf_t* surf, const float mvp[16]) { // This is diffuse cube mapping GL_UseProgram(&diffuseCubeShader); + glBindBufferBase( + GL_UNIFORM_BUFFER, + backEnd.glState.currentProgram->shaderMatricesBinding, + backEnd.glState.currentProgram->shaderMatricesBuffer); + // Possible that normals should be transformed by a normal matrix in the shader ? I am not sure... // Setup texcoord array to use the normals @@ -1827,6 +1902,11 @@ void RB_GLSL_T_RenderShaderPasses(const drawSurf_t* surf, const float mvp[16]) { // This is skybox cube mapping GL_UseProgram(&skyboxCubeShader); + glBindBufferBase( + GL_UNIFORM_BUFFER, + backEnd.glState.currentProgram->shaderMatricesBinding, + backEnd.glState.currentProgram->shaderMatricesBuffer); + // Disable TexCoord attribute GL_DisableVertexAttribArray(ATTR_TEXCOORD); @@ -1843,6 +1923,11 @@ void RB_GLSL_T_RenderShaderPasses(const drawSurf_t* surf, const float mvp[16]) { // This is skybox cube mapping, with special texture matrix GL_UseProgram(&skyboxCubeShader); + glBindBufferBase( + GL_UNIFORM_BUFFER, + backEnd.glState.currentProgram->shaderMatricesBinding, + backEnd.glState.currentProgram->shaderMatricesBuffer); + // Disable TexCoord attribute GL_DisableVertexAttribArray(ATTR_TEXCOORD); @@ -1873,6 +1958,11 @@ void RB_GLSL_T_RenderShaderPasses(const drawSurf_t* surf, const float mvp[16]) { // This is reflection cubemapping GL_UseProgram(&reflectionCubeShader); + glBindBufferBase( + GL_UNIFORM_BUFFER, + backEnd.glState.currentProgram->shaderMatricesBinding, + backEnd.glState.currentProgram->shaderMatricesBuffer); + // NB: in original D3, if the surface had a bump map it would lead to the "Bumpy reflection cubemaping" shader being used. // This is not implemented for now, we only do standard reflection cubemaping. Visual difference is really minor. @@ -1881,17 +1971,22 @@ void RB_GLSL_T_RenderShaderPasses(const drawSurf_t* surf, const float mvp[16]) { ac->normal.ToFloatPtr()); // Setup the modelViewMatrix, we will need it to compute the reflection - GL_UniformMatrix4fv(offsetof(shaderProgram_t, modelViewMatrix), surf->space->modelViewMatrix); + GL_UniformMatrix4fv(offsetof(shaderProgram_t, modelViewMatrix), surf->space->centerModelViewMatrix); // Setup the texture matrix like original D3 code does: using the transpose modelViewMatrix of the view // NB: this is curious, not sure why this is done like this.... float mat[16]; - R_TransposeGLMatrix(backEnd.viewDef->worldSpace.modelViewMatrix, mat); + R_TransposeGLMatrix(backEnd.viewDef->worldSpace.centerModelViewMatrix, mat); GL_UniformMatrix4fv(offsetof(shaderProgram_t, textureMatrix), mat); } else { // TG_EXPLICIT // Otherwise, this is just regular surface shader with explicit texcoords GL_UseProgram(&diffuseMapShader); + glBindBufferBase( + GL_UNIFORM_BUFFER, + backEnd.glState.currentProgram->shaderMatricesBinding, + backEnd.glState.currentProgram->shaderMatricesBuffer); + // Setup the TexCoord pointer GL_VertexAttribPointer(offsetof(shaderProgram_t, attr_TexCoord), 2, GL_FLOAT, false, sizeof(idDrawVert), ac->st.ToFloatPtr()); @@ -1926,7 +2021,7 @@ void RB_GLSL_T_RenderShaderPasses(const drawSurf_t* surf, const float mvp[16]) { // MVP if ( !bMVPSet[pStage->texture.texgen] ) { // Setup the MVP uniform - GL_UniformMatrix4fv(offsetof(shaderProgram_t, modelViewProjectionMatrix), mvp); + GL_UniformBuffer(offsetof(shaderProgram_t, shaderMatricesBuffer), mvp); bMVPSet[pStage->texture.texgen] = true; } } @@ -2102,7 +2197,7 @@ int RB_GLSL_DrawShaderPasses(drawSurf_t** drawSurfs, int numDrawSurfs) { // For each surface loop ///////////////////////// - float mvp[16]; + float mvp[32]; backEnd.currentSpace = NULL; int i; @@ -2258,6 +2353,11 @@ void RB_GLSL_BlendLight(const drawSurf_t *drawSurfs, const drawSurf_t *drawSurfs // Use blendLight shader GL_UseProgram(&blendLightShader); + glBindBufferBase( + GL_UNIFORM_BUFFER, + backEnd.glState.currentProgram->shaderMatricesBinding, + backEnd.glState.currentProgram->shaderMatricesBuffer); + // Texture 1 will get the falloff texture GL_SelectTexture(1); vLight->falloffImage->Bind(); diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/blendLightShaderVP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/blendLightShaderVP.cpp index 3044a34..c12ee2c 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/blendLightShaderVP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/blendLightShaderVP.cpp @@ -18,24 +18,33 @@ #include "glsl_shaders.h" const char * const blendLightShaderVP = R"( -#version 100 +#version 300 es + +// Multiview +#define NUM_VIEWS 2 +#extension GL_OVR_multiview2 : enable +layout(num_views=NUM_VIEWS) in; + precision mediump float; // In -attribute highp vec4 attr_Vertex; +in highp vec4 attr_Vertex; // Uniforms -uniform highp mat4 u_modelViewProjectionMatrix; +uniform ShaderMatrices +{ + uniform highp mat4 modelViewProjectionMatrix[NUM_VIEWS]; +} u_shaderMatrices; uniform mat4 u_fogMatrix; // Out // gl_Position -varying vec2 var_TexFog; -varying vec2 var_TexFogEnter; +out vec2 var_TexFog; +out vec2 var_TexFogEnter; -void main(void) +void main() { - gl_Position = u_modelViewProjectionMatrix * attr_Vertex; + gl_Position = u_shaderMatrices.modelViewProjectionMatrix[gl_ViewID_OVR] * attr_Vertex; // What will be computed: // diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/cubeMapShaderFP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/cubeMapShaderFP.cpp index 5df8436..798dc2a 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/cubeMapShaderFP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/cubeMapShaderFP.cpp @@ -18,22 +18,22 @@ #include "glsl_shaders.h" const char * const cubeMapShaderFP = R"( -#version 100 +#version 300 es precision mediump float; // In -varying vec3 var_TexCoord; -varying lowp vec4 var_Color; +in vec3 var_TexCoord; +in lowp vec4 var_Color; // Uniforms uniform samplerCube u_fragmentCubeMap0; uniform lowp vec4 u_glColor; // Out -// gl_FragColor +layout(location = 0) out vec4 fragColor; -void main(void) +void main() { - gl_FragColor = textureCube(u_fragmentCubeMap0, var_TexCoord) * u_glColor * var_Color; + fragColor = texture(u_fragmentCubeMap0, var_TexCoord) * u_glColor * var_Color; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseCubeShaderVP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseCubeShaderVP.cpp index 1bf1b2c..ed725fa 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseCubeShaderVP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseCubeShaderVP.cpp @@ -18,26 +18,35 @@ #include "glsl_shaders.h" const char * const diffuseCubeShaderVP = R"( -#version 100 +#version 300 es + +// Multiview +#define NUM_VIEWS 2 +#extension GL_OVR_multiview2 : enable +layout(num_views=NUM_VIEWS) in; + precision mediump float; // In -attribute highp vec4 attr_Vertex; -attribute lowp vec4 attr_Color; -attribute vec3 attr_TexCoord; +in highp vec4 attr_Vertex; +in lowp vec4 attr_Color; +in vec3 attr_TexCoord; // Uniforms -uniform highp mat4 u_modelViewProjectionMatrix; +uniform ShaderMatrices +{ + uniform highp mat4 modelViewProjectionMatrix[NUM_VIEWS]; +} u_shaderMatrices; uniform mat4 u_textureMatrix; uniform lowp float u_colorAdd; uniform lowp float u_colorModulate; // Out // gl_Position -varying vec3 var_TexCoord; -varying lowp vec4 var_Color; +out vec3 var_TexCoord; +out lowp vec4 var_Color; -void main(void) +void main() { var_TexCoord = (u_textureMatrix * vec4(attr_TexCoord, 0.0)).xyz; @@ -47,6 +56,6 @@ void main(void) var_Color = (attr_Color * u_colorModulate) + vec4(u_colorAdd); } - gl_Position = u_modelViewProjectionMatrix * attr_Vertex; + gl_Position = u_shaderMatrices.modelViewProjectionMatrix[gl_ViewID_OVR] * attr_Vertex; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseMapShaderFP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseMapShaderFP.cpp index 8110a1c..044ac9f 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseMapShaderFP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseMapShaderFP.cpp @@ -18,22 +18,22 @@ #include "glsl_shaders.h" const char * const diffuseMapShaderFP = R"( -#version 100 +#version 300 es precision mediump float; // In -varying vec2 var_TexCoord; -varying lowp vec4 var_Color; +in vec2 var_TexCoord; +in lowp vec4 var_Color; // Uniforms uniform sampler2D u_fragmentMap0; uniform lowp vec4 u_glColor; // Out -// gl_FragCoord +layout(location = 0) out vec4 fragColor; -void main(void) +void main() { - gl_FragColor = texture2D(u_fragmentMap0, var_TexCoord) * u_glColor * var_Color; + fragColor = texture(u_fragmentMap0, var_TexCoord) * u_glColor * var_Color; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseMapShaderVP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseMapShaderVP.cpp index f57b871..ccae28d 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseMapShaderVP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/diffuseMapShaderVP.cpp @@ -18,26 +18,36 @@ #include "glsl_shaders.h" const char * const diffuseMapShaderVP = R"( -#version 100 +#version 300 es + +// Multiview +#define NUM_VIEWS 2 +#extension GL_OVR_multiview2 : enable +layout(num_views=NUM_VIEWS) in; + + precision mediump float; // In -attribute highp vec4 attr_Vertex; -attribute lowp vec4 attr_Color; -attribute vec4 attr_TexCoord; +in highp vec4 attr_Vertex; +in lowp vec4 attr_Color; +in vec4 attr_TexCoord; // Uniforms -uniform highp mat4 u_modelViewProjectionMatrix; +uniform ShaderMatrices +{ + uniform highp mat4 modelViewProjectionMatrix[NUM_VIEWS]; +} u_shaderMatrices; uniform mat4 u_textureMatrix; uniform lowp float u_colorAdd; uniform lowp float u_colorModulate; // Out // gl_Position -varying vec2 var_TexCoord; -varying lowp vec4 var_Color; +out vec2 var_TexCoord; +out lowp vec4 var_Color; -void main(void) +void main() { var_TexCoord = (u_textureMatrix * attr_TexCoord).xy; // Homogeneous coordinates of textureMatrix supposed to be 1 @@ -47,6 +57,6 @@ void main(void) var_Color = (attr_Color * u_colorModulate) + vec4(u_colorAdd); } - gl_Position = u_modelViewProjectionMatrix * attr_Vertex; + gl_Position = u_shaderMatrices.modelViewProjectionMatrix[gl_ViewID_OVR] * attr_Vertex; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/fogShaderFP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/fogShaderFP.cpp index fad674c..ad2b745 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/fogShaderFP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/fogShaderFP.cpp @@ -18,12 +18,12 @@ #include "glsl_shaders.h" const char * const fogShaderFP = R"( -#version 100 +#version 300 es precision mediump float; // In -varying vec2 var_TexFog; // input Fog TexCoord -varying vec2 var_TexFogEnter; // input FogEnter TexCoord +in vec2 var_TexFog; // input Fog TexCoord +in vec2 var_TexFogEnter; // input FogEnter TexCoord // Uniforms uniform sampler2D u_fragmentMap0; // Fog Image @@ -31,10 +31,10 @@ uniform sampler2D u_fragmentMap1; // Fog Enter Image uniform lowp vec4 u_fogColor; // Fog Color // Out -// gl_FragCoord // output Fragment color +layout(location = 0) out vec4 fragColor; -void main(void) +void main() { - gl_FragColor = texture2D( u_fragmentMap0, var_TexFog ) * texture2D( u_fragmentMap1, var_TexFogEnter ) * vec4(u_fogColor.rgb, 1.0); + fragColor = texture( u_fragmentMap0, var_TexFog ) * texture( u_fragmentMap1, var_TexFogEnter ) * vec4(u_fogColor.rgb, 1.0); } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/fogShaderVP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/fogShaderVP.cpp index b57aab3..685191f 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/fogShaderVP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/fogShaderVP.cpp @@ -18,24 +18,33 @@ #include "glsl_shaders.h" const char * const fogShaderVP = R"( -#version 100 +#version 300 es + +// Multiview +#define NUM_VIEWS 2 +#extension GL_OVR_multiview2 : enable +layout(num_views=NUM_VIEWS) in; + precision mediump float; // In -attribute highp vec4 attr_Vertex; // input Vertex Coordinates +in highp vec4 attr_Vertex; // input Vertex Coordinates // Uniforms -uniform highp mat4 u_modelViewProjectionMatrix; +uniform ShaderMatrices +{ + uniform highp mat4 modelViewProjectionMatrix[NUM_VIEWS]; +} u_shaderMatrices; uniform mat4 u_fogMatrix; // fogPlanes 0, 1, 3 (CATION: not 2!), 2 // Out // gl_Position // output Vertex Coordinates -varying vec2 var_TexFog; // output Fog TexCoord -varying vec2 var_TexFogEnter; // output FogEnter TexCoord +out vec2 var_TexFog; // output Fog TexCoord +out vec2 var_TexFogEnter; // output FogEnter TexCoord -void main(void) +void main() { - gl_Position = u_modelViewProjectionMatrix * attr_Vertex; + gl_Position = u_shaderMatrices.modelViewProjectionMatrix[gl_ViewID_OVR] * attr_Vertex; // What will be computed: // diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionPhongShaderFP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionPhongShaderFP.cpp index df05074..5a0dc81 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionPhongShaderFP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionPhongShaderFP.cpp @@ -18,17 +18,17 @@ #include "glsl_shaders.h" const char * const interactionPhongShaderFP = R"( -#version 100 +#version 300 es precision highp float; // In -varying vec2 var_TexDiffuse; -varying vec2 var_TexNormal; -varying vec2 var_TexSpecular; -varying vec4 var_TexLight; -varying lowp vec4 var_Color; -varying vec3 var_L; -varying vec3 var_V; +in vec2 var_TexDiffuse; +in vec2 var_TexNormal; +in vec2 var_TexSpecular; +in vec4 var_TexLight; +in lowp vec4 var_Color; +in vec3 var_L; +in vec3 var_V; // Uniforms uniform lowp vec4 u_diffuseColor; @@ -41,20 +41,20 @@ uniform sampler2D u_fragmentMap3; // u_diffuseTexture uniform sampler2D u_fragmentMap4; // u_specularTexture // Out -// gl_FragCoord +layout(location = 0) out vec4 fragColor; -void main(void) +void main() { vec3 L = normalize(var_L); vec3 V = normalize(var_V); - vec3 N = normalize(2.0 * texture2D(u_fragmentMap0, var_TexNormal.st).agb - 1.0); + vec3 N = normalize(2.0 * texture(u_fragmentMap0, var_TexNormal.st).agb - 1.0); float NdotL = clamp(dot(N, L), 0.0, 1.0); - vec3 lightProjection = texture2DProj(u_fragmentMap2, var_TexLight.xyw).rgb; - vec3 lightFalloff = texture2D(u_fragmentMap1, vec2(var_TexLight.z, 0.5)).rgb; - vec3 diffuseColor = texture2D(u_fragmentMap3, var_TexDiffuse).rgb * u_diffuseColor.rgb; - vec3 specularColor = 2.0 * texture2D(u_fragmentMap4, var_TexSpecular).rgb * u_specularColor.rgb; + vec3 lightProjection = textureProj(u_fragmentMap2, var_TexLight.xyw).rgb; + vec3 lightFalloff = texture(u_fragmentMap1, vec2(var_TexLight.z, 0.5)).rgb; + vec3 diffuseColor = texture(u_fragmentMap3, var_TexDiffuse).rgb * u_diffuseColor.rgb; + vec3 specularColor = 2.0 * texture(u_fragmentMap4, var_TexSpecular).rgb * u_specularColor.rgb; vec3 R = -reflect(L, N); float RdotV = clamp(dot(R, V), 0.0, 1.0); @@ -66,6 +66,6 @@ void main(void) color *= NdotL * lightProjection; color *= lightFalloff; - gl_FragColor = vec4(color, 1.0) * var_Color; + fragColor = vec4(color, 1.0) * var_Color; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionPhongShaderVP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionPhongShaderVP.cpp index 2f5b438..e855447 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionPhongShaderVP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionPhongShaderVP.cpp @@ -18,19 +18,28 @@ #include "glsl_shaders.h" const char * const interactionPhongShaderVP = R"( -#version 100 +#version 300 es + +// Multiview +#define NUM_VIEWS 2 +#extension GL_OVR_multiview2 : enable +layout(num_views=NUM_VIEWS) in; + precision highp float; // In -attribute highp vec4 attr_Vertex; -attribute lowp vec4 attr_Color; -attribute vec4 attr_TexCoord; -attribute vec3 attr_Tangent; -attribute vec3 attr_Bitangent; -attribute vec3 attr_Normal; +in highp vec4 attr_Vertex; +in lowp vec4 attr_Color; +in vec4 attr_TexCoord; +in vec3 attr_Tangent; +in vec3 attr_Bitangent; +in vec3 attr_Normal; // Uniforms -uniform highp mat4 u_modelViewProjectionMatrix; +uniform ShaderMatrices +{ + uniform highp mat4 modelViewProjectionMatrix[NUM_VIEWS]; +} u_shaderMatrices; uniform mat4 u_lightProjection; uniform lowp float u_colorModulate; uniform lowp float u_colorAdd; @@ -45,15 +54,15 @@ uniform vec4 u_specularMatrixT; // Out // gl_Position -varying vec2 var_TexDiffuse; -varying vec2 var_TexNormal; -varying vec2 var_TexSpecular; -varying vec4 var_TexLight; -varying lowp vec4 var_Color; -varying vec3 var_L; -varying vec3 var_V; +out vec2 var_TexDiffuse; +out vec2 var_TexNormal; +out vec2 var_TexSpecular; +out vec4 var_TexLight; +out lowp vec4 var_Color; +out vec3 var_L; +out vec3 var_V; -void main(void) +void main() { mat3 M = mat3(attr_Tangent, attr_Bitangent, attr_Normal); @@ -83,6 +92,6 @@ void main(void) var_Color = (attr_Color * u_colorModulate) + vec4(u_colorAdd); } - gl_Position = u_modelViewProjectionMatrix * attr_Vertex; + gl_Position = u_shaderMatrices.modelViewProjectionMatrix[gl_ViewID_OVR] * attr_Vertex; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionShaderFP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionShaderFP.cpp index b584de5..79c218e 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionShaderFP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionShaderFP.cpp @@ -18,17 +18,17 @@ #include "glsl_shaders.h" const char * const interactionShaderFP = R"( -#version 100 +#version 300 es precision highp float; // In -varying vec2 var_TexDiffuse; -varying vec2 var_TexNormal; -varying vec2 var_TexSpecular; -varying vec4 var_TexLight; -varying lowp vec4 var_Color; -varying vec3 var_L; -varying vec3 var_H; +in vec2 var_TexDiffuse; +in vec2 var_TexNormal; +in vec2 var_TexSpecular; +in vec4 var_TexLight; +in lowp vec4 var_Color; +in vec3 var_L; +in vec3 var_H; // Uniforms uniform lowp vec4 u_diffuseColor; @@ -41,21 +41,21 @@ uniform sampler2D u_fragmentMap3; // u_diffuseTexture uniform sampler2D u_fragmentMap4; // u_specularTexture // Out -// gl_FragCoord +layout(location = 0) out vec4 fragColor; -void main(void) +void main() { vec3 L = normalize(var_L); vec3 H = normalize(var_H); - vec3 N = 2.0 * texture2D(u_fragmentMap0, var_TexNormal.st).agb - 1.0; + vec3 N = 2.0 * texture(u_fragmentMap0, var_TexNormal.st).agb - 1.0; float NdotL = clamp(dot(N, L), 0.0, 1.0); float NdotH = clamp(dot(N, H), 0.0, 1.0); - vec3 lightProjection = texture2DProj(u_fragmentMap2, var_TexLight.xyw).rgb; - vec3 lightFalloff = texture2D(u_fragmentMap1, vec2(var_TexLight.z, 0.5)).rgb; - vec3 diffuseColor = texture2D(u_fragmentMap3, var_TexDiffuse).rgb * u_diffuseColor.rgb; - vec3 specularColor = 2.0 * texture2D(u_fragmentMap4, var_TexSpecular).rgb * u_specularColor.rgb; + vec3 lightProjection = textureProj(u_fragmentMap2, var_TexLight.xyw).rgb; + vec3 lightFalloff = texture(u_fragmentMap1, vec2(var_TexLight.z, 0.5)).rgb; + vec3 diffuseColor = texture(u_fragmentMap3, var_TexDiffuse).rgb * u_diffuseColor.rgb; + vec3 specularColor = 2.0 * texture(u_fragmentMap4, var_TexSpecular).rgb * u_specularColor.rgb; float specularFalloff = pow(NdotH, 12.0); // Hardcoded to try to match with original D3 look @@ -65,6 +65,6 @@ void main(void) color *= NdotL * lightProjection; color *= lightFalloff; - gl_FragColor = vec4(color, 1.0) * var_Color; + fragColor = vec4(color, 1.0) * var_Color; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionShaderVP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionShaderVP.cpp index 1889033..6f19c26 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionShaderVP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/interactionShaderVP.cpp @@ -18,19 +18,28 @@ #include "glsl_shaders.h" const char * const interactionShaderVP = R"( -#version 100 +#version 300 es + +// Multiview +#define NUM_VIEWS 2 +#extension GL_OVR_multiview2 : enable +layout(num_views=NUM_VIEWS) in; + precision highp float; // In -attribute highp vec4 attr_Vertex; -attribute lowp vec4 attr_Color; -attribute vec4 attr_TexCoord; -attribute vec3 attr_Tangent; -attribute vec3 attr_Bitangent; -attribute vec3 attr_Normal; +in highp vec4 attr_Vertex; +in lowp vec4 attr_Color; +in vec4 attr_TexCoord; +in vec3 attr_Tangent; +in vec3 attr_Bitangent; +in vec3 attr_Normal; // Uniforms -uniform highp mat4 u_modelViewProjectionMatrix; +uniform ShaderMatrices +{ + uniform highp mat4 modelViewProjectionMatrix[NUM_VIEWS]; +} u_shaderMatrices; uniform mat4 u_lightProjection; uniform lowp float u_colorModulate; uniform lowp float u_colorAdd; @@ -45,15 +54,15 @@ uniform vec4 u_specularMatrixT; // Out // gl_Position -varying vec2 var_TexDiffuse; -varying vec2 var_TexNormal; -varying vec2 var_TexSpecular; -varying vec4 var_TexLight; -varying lowp vec4 var_Color; -varying vec3 var_L; -varying vec3 var_H; +out vec2 var_TexDiffuse; +out vec2 var_TexNormal; +out vec2 var_TexSpecular; +out vec4 var_TexLight; +out lowp vec4 var_Color; +out vec3 var_L; +out vec3 var_H; -void main(void) +void main() { mat3 M = mat3(attr_Tangent, attr_Bitangent, attr_Normal); @@ -84,6 +93,6 @@ void main(void) var_Color = (attr_Color * u_colorModulate) + vec4(u_colorAdd); } - gl_Position = u_modelViewProjectionMatrix * attr_Vertex; + gl_Position = u_shaderMatrices.modelViewProjectionMatrix[gl_ViewID_OVR] * attr_Vertex; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/reflectionCubeShaderVP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/reflectionCubeShaderVP.cpp index 8447701..b91482d 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/reflectionCubeShaderVP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/reflectionCubeShaderVP.cpp @@ -18,16 +18,32 @@ #include "glsl_shaders.h" const char * const reflectionCubeShaderVP = R"( -#version 100 +#version 300 es + +// Multiview +#define NUM_VIEWS 2 +#if defined( GL_OVR_multiview2 ) + #extension GL_OVR_multiview2 : enable + layout(num_views=NUM_VIEWS) in; + #define VIEW_ID gl_ViewID_OVR +#else + uniform lowp int ViewID; + #define VIEW_ID ViewID +#endif + + precision mediump float; // In -attribute highp vec4 attr_Vertex; -attribute lowp vec4 attr_Color; -attribute vec3 attr_TexCoord; +in highp vec4 attr_Vertex; +in lowp vec4 attr_Color; +in vec3 attr_TexCoord; // Uniforms -uniform highp mat4 u_modelViewProjectionMatrix; +uniform ShaderMatrices +{ + uniform highp mat4 modelViewProjectionMatrix[NUM_VIEWS]; +} u_shaderMatrices; uniform mat4 u_modelViewMatrix; uniform mat4 u_textureMatrix; uniform lowp float u_colorAdd; @@ -35,10 +51,10 @@ uniform lowp float u_colorModulate; // Out // gl_Position -varying vec3 var_TexCoord; -varying lowp vec4 var_Color; +out vec3 var_TexCoord; +out lowp vec4 var_Color; -void main(void) +void main() { var_TexCoord = (u_textureMatrix * reflect( normalize( u_modelViewMatrix * attr_Vertex ), // This suppose the modelView matrix is orthogonal @@ -51,6 +67,6 @@ void main(void) var_Color = (attr_Color * u_colorModulate) + vec4(u_colorAdd); } - gl_Position = u_modelViewProjectionMatrix * attr_Vertex; + gl_Position = u_shaderMatrices.modelViewProjectionMatrix[gl_ViewID_OVR] * attr_Vertex; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/skyboxCubeShaderVP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/skyboxCubeShaderVP.cpp index cbda95f..fd8d371 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/skyboxCubeShaderVP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/skyboxCubeShaderVP.cpp @@ -18,15 +18,24 @@ #include "glsl_shaders.h" const char * const skyboxCubeShaderVP = R"( -#version 100 +#version 300 es + +// Multiview +#define NUM_VIEWS 2 +#extension GL_OVR_multiview2 : enable +layout(num_views=NUM_VIEWS) in; + precision mediump float; // In -attribute highp vec4 attr_Vertex; -attribute lowp vec4 attr_Color; +in highp vec4 attr_Vertex; +in lowp vec4 attr_Color; // Uniforms -uniform highp mat4 u_modelViewProjectionMatrix; +uniform ShaderMatrices +{ + uniform highp mat4 modelViewProjectionMatrix[NUM_VIEWS]; +} u_shaderMatrices; uniform mat4 u_textureMatrix; uniform lowp float u_colorAdd; uniform lowp float u_colorModulate; @@ -34,10 +43,10 @@ uniform vec4 u_viewOrigin; // Out // gl_Position -varying vec3 var_TexCoord; -varying lowp vec4 var_Color; +out vec3 var_TexCoord; +out lowp vec4 var_Color; -void main(void) +void main() { var_TexCoord = (u_textureMatrix * (attr_Vertex - u_viewOrigin)).xyz; @@ -47,6 +56,6 @@ void main(void) var_Color = (attr_Color * u_colorModulate) + vec4(u_colorAdd); } - gl_Position = u_modelViewProjectionMatrix * attr_Vertex; + gl_Position = u_shaderMatrices.modelViewProjectionMatrix[gl_ViewID_OVR] * attr_Vertex; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/stencilShadowShaderFP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/stencilShadowShaderFP.cpp index 9d217b8..543ed2f 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/stencilShadowShaderFP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/stencilShadowShaderFP.cpp @@ -18,14 +18,14 @@ #include "glsl_shaders.h" const char * const stencilShadowShaderFP = R"( -#version 100 +#version 300 es precision lowp float; // Out -// gl_FragColor +layout(location = 0) out vec4 fragColor; -void main(void) +void main() { - gl_FragColor = vec4(0,0,0,1.0); + fragColor = vec4(0,0,0,1.0); } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/stencilShadowShaderVP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/stencilShadowShaderVP.cpp index d3cbac5..5ac13f4 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/stencilShadowShaderVP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/stencilShadowShaderVP.cpp @@ -18,21 +18,30 @@ #include "glsl_shaders.h" const char * const stencilShadowShaderVP = R"( -#version 100 +#version 300 es + +// Multiview +#define NUM_VIEWS 2 +#extension GL_OVR_multiview2 : enable +layout(num_views=NUM_VIEWS) in; + precision mediump float; // In -attribute highp vec4 attr_Vertex; +in highp vec4 attr_Vertex; // Uniforms -uniform highp mat4 u_modelViewProjectionMatrix; +uniform ShaderMatrices +{ + uniform highp mat4 modelViewProjectionMatrix[NUM_VIEWS]; +} u_shaderMatrices; uniform vec4 u_lightOrigin; // Out // gl_Position -void main(void) +void main() { - gl_Position = u_modelViewProjectionMatrix * (attr_Vertex.w * u_lightOrigin + attr_Vertex - u_lightOrigin); + gl_Position = u_shaderMatrices.modelViewProjectionMatrix[gl_ViewID_OVR] * (attr_Vertex.w * u_lightOrigin + attr_Vertex - u_lightOrigin); } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillClipShaderFP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillClipShaderFP.cpp index 3d700b3..f379421 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillClipShaderFP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillClipShaderFP.cpp @@ -18,12 +18,12 @@ #include "glsl_shaders.h" const char * const zfillClipShaderFP = R"( -#version 100 +#version 300 es precision mediump float; // In -varying vec2 var_TexDiffuse; -varying vec2 var_TexClip; +in vec2 var_TexDiffuse; +in vec2 var_TexClip; // Uniforms uniform sampler2D u_fragmentMap0; @@ -32,14 +32,14 @@ uniform lowp float u_alphaTest; uniform lowp vec4 u_glColor; // Out -// gl_FragCoord +layout(location = 0) out vec4 fragColor; -void main(void) +void main() { - if (u_alphaTest > (texture2D(u_fragmentMap0, var_TexDiffuse).a * texture2D(u_fragmentMap1, var_TexClip).a) ) { + if (u_alphaTest > (texture(u_fragmentMap0, var_TexDiffuse).a * texture(u_fragmentMap1, var_TexClip).a) ) { discard; } - gl_FragColor = u_glColor; + fragColor = u_glColor; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillClipShaderVP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillClipShaderVP.cpp index 3b824c5..7730f4d 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillClipShaderVP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillClipShaderVP.cpp @@ -18,29 +18,38 @@ #include "glsl_shaders.h" const char * const zfillClipShaderVP = R"( -#version 100 +#version 300 es + +// Multiview +#define NUM_VIEWS 2 +#extension GL_OVR_multiview2 : enable +layout(num_views=NUM_VIEWS) in; + precision mediump float; // In -attribute highp vec4 attr_Vertex; -attribute vec4 attr_TexCoord; +in highp vec4 attr_Vertex; +in vec4 attr_TexCoord; // Uniforms -uniform highp mat4 u_modelViewProjectionMatrix; +uniform ShaderMatrices +{ + uniform highp mat4 modelViewProjectionMatrix[NUM_VIEWS]; +} u_shaderMatrices; uniform mat4 u_textureMatrix; uniform vec4 u_clipPlane; // Out // gl_Position -varying vec2 var_TexDiffuse; -varying vec2 var_TexClip; +out vec2 var_TexDiffuse; +out vec2 var_TexClip; -void main(void) +void main() { var_TexDiffuse = (u_textureMatrix * attr_TexCoord).xy; // Homogeneous coordinates of textureMatrix supposed to be 1 var_TexClip = vec2( dot( u_clipPlane, attr_Vertex), 0.5 ); - gl_Position = u_modelViewProjectionMatrix * attr_Vertex; + gl_Position = u_shaderMatrices.modelViewProjectionMatrix[gl_ViewID_OVR] * attr_Vertex; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillShaderFP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillShaderFP.cpp index 9bea0b5..a71a0b0 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillShaderFP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillShaderFP.cpp @@ -18,11 +18,11 @@ #include "glsl_shaders.h" const char * const zfillShaderFP = R"( -#version 100 +#version 300 es precision mediump float; // In -varying vec2 var_TexDiffuse; +in vec2 var_TexDiffuse; // Uniforms uniform sampler2D u_fragmentMap0; @@ -30,14 +30,14 @@ uniform lowp float u_alphaTest; uniform lowp vec4 u_glColor; // Out -// gl_FragCoord +layout(location = 0) out vec4 fragColor; -void main(void) +void main() { - if (u_alphaTest > texture2D(u_fragmentMap0, var_TexDiffuse).a) { + if (u_alphaTest > texture(u_fragmentMap0, var_TexDiffuse).a) { discard; } - gl_FragColor = u_glColor; + fragColor = u_glColor; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillShaderVP.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillShaderVP.cpp index 2faafa4..9adb954 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillShaderVP.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/glsl/zfillShaderVP.cpp @@ -18,25 +18,34 @@ #include "glsl_shaders.h" const char * const zfillShaderVP = R"( -#version 100 +#version 300 es + +// Multiview +#define NUM_VIEWS 2 +#extension GL_OVR_multiview2 : enable +layout(num_views=NUM_VIEWS) in; + precision mediump float; // In -attribute highp vec4 attr_Vertex; -attribute vec4 attr_TexCoord; +in highp vec4 attr_Vertex; +in vec4 attr_TexCoord; // Uniforms -uniform highp mat4 u_modelViewProjectionMatrix; +uniform ShaderMatrices +{ + uniform highp mat4 modelViewProjectionMatrix[NUM_VIEWS]; +} u_shaderMatrices; uniform mat4 u_textureMatrix; // Out // gl_Position -varying vec2 var_TexDiffuse; +out vec2 var_TexDiffuse; -void main(void) +void main() { var_TexDiffuse = (u_textureMatrix * attr_TexCoord).xy; // Homogeneous coordinates of textureMatrix supposed to be 1 - gl_Position = u_modelViewProjectionMatrix * attr_Vertex; + gl_Position = u_shaderMatrices.modelViewProjectionMatrix[gl_ViewID_OVR] * attr_Vertex; } )"; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_light.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_light.cpp index 089238a..50ee74d 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_light.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_light.cpp @@ -272,7 +272,9 @@ viewEntity_t* R_SetEntityDefViewEntity(idRenderEntityLocal* def) { // we may not have a viewDef if we are just creating shadows at entity creation time if ( tr.viewDef ) { - myGlMultMatrix(vModel->modelMatrix, tr.viewDef->worldSpace.modelViewMatrix, vModel->modelViewMatrix); + myGlMultMatrix(vModel->modelMatrix, tr.viewDef->worldSpace.modelViewMatrix[0], vModel->modelViewMatrix[0]); + myGlMultMatrix(vModel->modelMatrix, tr.viewDef->worldSpace.modelViewMatrix[1], vModel->modelViewMatrix[1]); + myGlMultMatrix(vModel->modelMatrix, tr.viewDef->worldSpace.centerModelViewMatrix, vModel->centerModelViewMatrix); vModel->next = tr.viewDef->viewEntitys; tr.viewDef->viewEntitys = vModel; @@ -627,7 +629,7 @@ idScreenRect R_ClippedLightScissorRectangle(viewLight_t* vLight) { idPlane eye, clip; idVec3 ndc; - R_TransformModelToClip(w[j].ToVec3(), tr.viewDef->worldSpace.modelViewMatrix, tr.viewDef->projectionMatrix, eye, + R_TransformModelToClip(w[j].ToVec3(), tr.viewDef->worldSpace.centerModelViewMatrix, tr.viewDef->projectionMatrix, eye, clip); if ( clip[3] <= 0.01f ) { @@ -692,7 +694,7 @@ idScreenRect R_CalcLightScissorRectangle(viewLight_t* vLight) { tri = vLight->lightDef->frustumTris; for ( int i = 0; i < tri->numVerts; i++ ) { - R_TransformModelToClip(tri->verts[i].xyz, tr.viewDef->worldSpace.modelViewMatrix, + R_TransformModelToClip(tri->verts[i].xyz, tr.viewDef->worldSpace.centerModelViewMatrix, tr.viewDef->projectionMatrix, eye, clip); // if it is near clipped, clip the winding polygons to the view frustum @@ -1049,7 +1051,7 @@ idRenderModel* R_EntityDefDynamicModel(idRenderEntityLocal* def) { if ( def->dynamicModel && model->DepthHack() != 0.0f && tr.viewDef ) { idPlane eye, clip; idVec3 ndc; - R_TransformModelToClip(def->parms.origin, tr.viewDef->worldSpace.modelViewMatrix, tr.viewDef->projectionMatrix, + R_TransformModelToClip(def->parms.origin, tr.viewDef->worldSpace.centerModelViewMatrix, tr.viewDef->projectionMatrix, eye, clip); R_TransformClipToDevice(clip, tr.viewDef, ndc); diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_local.h b/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_local.h index 135e1fc..a0619c8 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_local.h +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_local.h @@ -369,7 +369,8 @@ typedef struct viewEntity_s { float modelDepthHack; float modelMatrix[16]; // local coords to global coords - float modelViewMatrix[16]; // local coords to eye coords + float modelViewMatrix[2][16]; // local coords to left/right eye coords + float centerModelViewMatrix[16]; // local coords to center eye coords } viewEntity_t; @@ -1253,7 +1254,11 @@ typedef struct shaderProgram_s { GLint alphaTest; GLint specularExponent; - GLint modelViewProjectionMatrix; +// GLint modelViewProjectionMatrix; + //New for multiview + GLuint shaderMatricesBuffer; + GLuint shaderMatricesBinding; + GLint modelViewMatrix; GLint textureMatrix; GLint localLightOrigin; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_main.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_main.cpp index 6cf9bb5..325b2d2 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_main.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_main.cpp @@ -734,10 +734,10 @@ void R_GlobalToNormalizedDeviceCoordinates( const idVec3 &global, idVec3 &ndc ) for ( i = 0 ; i < 4 ; i ++ ) { view[i] = - global[0] * tr.primaryView->worldSpace.modelViewMatrix[ i + 0 * 4 ] + - global[1] * tr.primaryView->worldSpace.modelViewMatrix[ i + 1 * 4 ] + - global[2] * tr.primaryView->worldSpace.modelViewMatrix[ i + 2 * 4 ] + - tr.primaryView->worldSpace.modelViewMatrix[ i + 3 * 4 ]; + global[0] * tr.primaryView->worldSpace.centerModelViewMatrix[ i + 0 * 4 ] + + global[1] * tr.primaryView->worldSpace.centerModelViewMatrix[ i + 1 * 4 ] + + global[2] * tr.primaryView->worldSpace.centerModelViewMatrix[ i + 2 * 4 ] + + tr.primaryView->worldSpace.centerModelViewMatrix[ i + 3 * 4 ]; } for ( i = 0 ; i < 4 ; i ++ ) { @@ -752,10 +752,10 @@ void R_GlobalToNormalizedDeviceCoordinates( const idVec3 &global, idVec3 &ndc ) for ( i = 0 ; i < 4 ; i ++ ) { view[i] = - global[0] * tr.viewDef->worldSpace.modelViewMatrix[ i + 0 * 4 ] + - global[1] * tr.viewDef->worldSpace.modelViewMatrix[ i + 1 * 4 ] + - global[2] * tr.viewDef->worldSpace.modelViewMatrix[ i + 2 * 4 ] + - tr.viewDef->worldSpace.modelViewMatrix[ i + 3 * 4 ]; + global[0] * tr.viewDef->worldSpace.centerModelViewMatrix[ i + 0 * 4 ] + + global[1] * tr.viewDef->worldSpace.centerModelViewMatrix[ i + 1 * 4 ] + + global[2] * tr.viewDef->worldSpace.centerModelViewMatrix[ i + 2 * 4 ] + + tr.viewDef->worldSpace.centerModelViewMatrix[ i + 3 * 4 ]; } @@ -871,35 +871,46 @@ void R_SetViewMatrix( viewDef_t *viewDef ) { world->modelMatrix[1 * 4 + 1] = 1; world->modelMatrix[2 * 4 + 2] = 1; - // transform by the camera placement - origin = viewDef->renderView.vieworg; + for (int eye = 0; eye < 3; ++eye) { + // transform by the camera placement + origin = viewDef->renderView.vieworg; - viewerMatrix[0] = viewDef->renderView.viewaxis[0][0]; - viewerMatrix[4] = viewDef->renderView.viewaxis[0][1]; - viewerMatrix[8] = viewDef->renderView.viewaxis[0][2]; - viewerMatrix[12] = -origin[0] * viewerMatrix[0] + -origin[1] * viewerMatrix[4] + - -origin[2] * viewerMatrix[8]; + if (eye < 2) { + origin += (eye == 0 ? 1.0f : -1.0f) * viewDef->renderView.viewaxis[1] * + ((0.065f) / 2.0f) * (43.0f); + } - viewerMatrix[1] = viewDef->renderView.viewaxis[1][0]; - viewerMatrix[5] = viewDef->renderView.viewaxis[1][1]; - viewerMatrix[9] = viewDef->renderView.viewaxis[1][2]; - viewerMatrix[13] = -origin[0] * viewerMatrix[1] + -origin[1] * viewerMatrix[5] + - -origin[2] * viewerMatrix[9]; + viewerMatrix[0] = viewDef->renderView.viewaxis[0][0]; + viewerMatrix[4] = viewDef->renderView.viewaxis[0][1]; + viewerMatrix[8] = viewDef->renderView.viewaxis[0][2]; + viewerMatrix[12] = -origin[0] * viewerMatrix[0] + -origin[1] * viewerMatrix[4] + + -origin[2] * viewerMatrix[8]; - viewerMatrix[2] = viewDef->renderView.viewaxis[2][0]; - viewerMatrix[6] = viewDef->renderView.viewaxis[2][1]; - viewerMatrix[10] = viewDef->renderView.viewaxis[2][2]; - viewerMatrix[14] = -origin[0] * viewerMatrix[2] + -origin[1] * viewerMatrix[6] + - -origin[2] * viewerMatrix[10]; + viewerMatrix[1] = viewDef->renderView.viewaxis[1][0]; + viewerMatrix[5] = viewDef->renderView.viewaxis[1][1]; + viewerMatrix[9] = viewDef->renderView.viewaxis[1][2]; + viewerMatrix[13] = -origin[0] * viewerMatrix[1] + -origin[1] * viewerMatrix[5] + + -origin[2] * viewerMatrix[9]; - viewerMatrix[3] = 0; - viewerMatrix[7] = 0; - viewerMatrix[11] = 0; - viewerMatrix[15] = 1; + viewerMatrix[2] = viewDef->renderView.viewaxis[2][0]; + viewerMatrix[6] = viewDef->renderView.viewaxis[2][1]; + viewerMatrix[10] = viewDef->renderView.viewaxis[2][2]; + viewerMatrix[14] = -origin[0] * viewerMatrix[2] + -origin[1] * viewerMatrix[6] + + -origin[2] * viewerMatrix[10]; - // convert from our coordinate system (looking down X) - // to OpenGL's coordinate system (looking down -Z) - myGlMultMatrix(viewerMatrix, s_flipMatrix, world->modelViewMatrix); + viewerMatrix[3] = 0; + viewerMatrix[7] = 0; + viewerMatrix[11] = 0; + viewerMatrix[15] = 1; + + if (eye < 2) { + // convert from our coordinate system (looking down X) + // to OpenGL's coordinate system (looking down -Z) + myGlMultMatrix(viewerMatrix, s_flipMatrix, world->modelViewMatrix[eye]); + } else { + myGlMultMatrix(viewerMatrix, s_flipMatrix, world->centerModelViewMatrix); + } + } } } diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_shadowbounds.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_shadowbounds.cpp index 19851cf..7c61013 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_shadowbounds.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_shadowbounds.cpp @@ -473,10 +473,10 @@ void world_to_hclip( const viewDef_t *viewDef, const idVec4 &global, idVec4 &cli for ( i = 0 ; i < 4 ; i ++ ) { view[i] = - global[0] * viewDef->worldSpace.modelViewMatrix[ i + 0 * 4 ] + - global[1] * viewDef->worldSpace.modelViewMatrix[ i + 1 * 4 ] + - global[2] * viewDef->worldSpace.modelViewMatrix[ i + 2 * 4 ] + - global[3] * viewDef->worldSpace.modelViewMatrix[ i + 3 * 4 ]; + global[0] * viewDef->worldSpace.centerModelViewMatrix[ i + 0 * 4 ] + + global[1] * viewDef->worldSpace.centerModelViewMatrix[ i + 1 * 4 ] + + global[2] * viewDef->worldSpace.centerModelViewMatrix[ i + 2 * 4 ] + + global[3] * viewDef->worldSpace.centerModelViewMatrix[ i + 3 * 4 ]; } diff --git a/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_subview.cpp b/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_subview.cpp index 54b0154..522c94d 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_subview.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/renderer/tr_subview.cpp @@ -125,7 +125,7 @@ bool R_PreciseCullSurface( const drawSurf_t *drawSurf, idBounds &ndcBounds ) { int j; unsigned int pointFlags; - R_TransformModelToClip( tri->verts[i].xyz, drawSurf->space->modelViewMatrix, + R_TransformModelToClip( tri->verts[i].xyz, drawSurf->space->centerModelViewMatrix, tr.viewDef->projectionMatrix, eye, clip ); pointFlags = 0; diff --git a/Projects/Android/jni/d3es-multithread-master/neo/sys/glimp.cpp b/Projects/Android/jni/d3es-multithread-master/neo/sys/glimp.cpp index d675134..6a46a64 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/sys/glimp.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/sys/glimp.cpp @@ -139,16 +139,11 @@ GLimp_Shutdown void GLimp_Shutdown() { } -int stereoSide = 0; -void GLimp_SetupFrame(int eye) { +void GLimp_SetupFrame(int buffer /*unused*/) { - //Only do this if we have drawn both buffers and are back to the first buffer - stereoSide = eye; - if (eye == 0) { - Doom3Quest_processMessageQueue(); + Doom3Quest_processMessageQueue(); - Doom3Quest_prepareEyeBuffer(0); - } + Doom3Quest_prepareEyeBuffer(); } @@ -158,19 +153,10 @@ GLimp_SwapBuffers =================== */ void GLimp_SwapBuffers() { + Doom3Quest_finishEyeBuffer(); - if (stereoSide == 0) - { - Doom3Quest_finishEyeBuffer(0); - Doom3Quest_prepareEyeBuffer(1); - } - else - { - Doom3Quest_finishEyeBuffer(1); - - //We can now submit the stereo frame - Doom3Quest_submitFrame(); - } + //We can now submit the stereo frame + Doom3Quest_submitFrame(); } /* @@ -190,7 +176,6 @@ GLimp_ActivateContext extern "C" void ActivateContext(); void GLimp_ActivateContext() { - stereoSide = 0; ActivateContext(); } diff --git a/Projects/Android/jni/d3es-multithread-master/neo/ui/DeviceContext.cpp b/Projects/Android/jni/d3es-multithread-master/neo/ui/DeviceContext.cpp index 5b2bbc1..1a6c4ec 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/ui/DeviceContext.cpp +++ b/Projects/Android/jni/d3es-multithread-master/neo/ui/DeviceContext.cpp @@ -291,22 +291,6 @@ void idDeviceContext::SetMenuScaleFix(bool enable) { } } -// DG: this is used for the "make sure menus are rendered as 4:3" hack -void idDeviceContext::SetMenuScaleForVR( bool enable ) { - int eye = cvarSystem->GetCVarInteger("vr_eye"); - if(enable) { - float scaleX = 0.38; - float scaleY = 0.45; - float offsetX = (1.0f - scaleX) * (VIRTUAL_WIDTH * 0.5f); - float offsetY = (1.0f - scaleY) * (VIRTUAL_HEIGHT * 0.5f); - fixScaleForMenu.Set(scaleX, scaleY); - fixOffsetForMenu.Set(offsetX + (eye==0 ? 20 : -20), offsetY); - } else { - fixScaleForMenu.Set(1, 1); - fixOffsetForMenu.Set(0, 0); - } -} - void idDeviceContext::AdjustCoords(float *x, float *y, float *w, float *h) { if (x) { diff --git a/Projects/Android/jni/d3es-multithread-master/neo/ui/DeviceContext.h b/Projects/Android/jni/d3es-multithread-master/neo/ui/DeviceContext.h index 685ce31..93d7034 100644 --- a/Projects/Android/jni/d3es-multithread-master/neo/ui/DeviceContext.h +++ b/Projects/Android/jni/d3es-multithread-master/neo/ui/DeviceContext.h @@ -101,7 +101,6 @@ public: // DG: this is used for the "make sure menus are rendered as 4:3" hack void SetMenuScaleFix(bool enable); - void SetMenuScaleForVR( bool enable ); bool IsMenuScaleFixActive() const { return fixOffsetForMenu.x != 0.0f || fixOffsetForMenu.y != 0.0f; }