From ee1616994a0726737e1fcfffbaee1c923b8c179b Mon Sep 17 00:00:00 2001 From: "adam.b" Date: Wed, 31 Aug 2016 16:48:53 +0100 Subject: [PATCH] VR: Experimental integration with TizenVR, (WIP) - VR setup moved to the dali-adaptor - added test whether vrengine getter failed - oculus sensor works! - RenderManager renders to the TizenVR surfaces now - The view matrix is not being passed to the vr engine yet - ailising VrEngine GL objects ( no depth buffer support yet ) - Using PreRender() and PostRender() functions from the VrEngine abstraction layer. Change-Id: I73e9f41753edf1096506e3e04cf3f08c3d4f2c30 --- .gitignore | 1 + .../dali-test-suite-utils/test-application.cpp | 4 +- dali/integration-api/core.cpp | 7 +- dali/integration-api/core.h | 6 +- dali/integration-api/file.list | 4 +- dali/integration-api/gyroscope-sensor.h | 47 --- dali/integration-api/vr-engine.h | 149 +++++++ dali/internal/common/core-impl.cpp | 20 +- dali/internal/common/core-impl.h | 6 +- dali/internal/event/common/stage-impl.cpp | 78 ++-- dali/internal/event/common/stage-impl.h | 15 +- dali/internal/render/common/render-algorithms.cpp | 4 +- dali/internal/render/common/render-instruction.h | 2 +- dali/internal/render/common/render-manager.cpp | 448 ++++++--------------- dali/internal/render/common/render-manager.h | 6 +- dali/internal/render/gl-resources/context.h | 6 +- dali/internal/update/manager/update-manager.cpp | 11 +- dali/internal/update/manager/update-manager.h | 7 +- .../update/render-tasks/scene-graph-camera.cpp | 9 +- dali/public-api/actors/camera-actor.h | 3 +- 20 files changed, 359 insertions(+), 474 deletions(-) delete mode 100644 dali/integration-api/gyroscope-sensor.h create mode 100644 dali/integration-api/vr-engine.h diff --git a/.gitignore b/.gitignore index caf34e7..4257843 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ BROWSE /build/tizen/.cov /build/desktop /packaging/home* +/build/tizen-mobile diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-application.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-application.cpp index ce23d85..0f615c0 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-application.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-application.cpp @@ -68,8 +68,8 @@ void TestApplication::Initialize() mGlAbstraction, mGlSyncAbstraction, mGestureManager, - NULL, - mDataRetentionPolicy); + mDataRetentionPolicy, + NULL ); mCore->ContextCreated(); mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight ); diff --git a/dali/integration-api/core.cpp b/dali/integration-api/core.cpp index 5e2dd34..53f6c95 100644 --- a/dali/integration-api/core.cpp +++ b/dali/integration-api/core.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include namespace Dali @@ -32,10 +32,11 @@ namespace Integration { Core* Core::New(RenderController& renderController, PlatformAbstraction& platformAbstraction, - GlAbstraction& glAbstraction, GlSyncAbstraction& glSyncAbstraction, GestureManager& gestureManager, GyroscopeSensor* gyroscopeSensor, ResourcePolicy::DataRetention policy ) + GlAbstraction& glAbstraction, GlSyncAbstraction& glSyncAbstraction, GestureManager& gestureManager, ResourcePolicy::DataRetention policy, + VrEngine* vrEngine ) { Core* instance = new Core; - instance->mImpl = new Internal::Core( renderController, platformAbstraction, glAbstraction, glSyncAbstraction, gestureManager, gyroscopeSensor, policy ); + instance->mImpl = new Internal::Core( renderController, platformAbstraction, glAbstraction, glSyncAbstraction, gestureManager, policy, vrEngine ); return instance; } diff --git a/dali/integration-api/core.h b/dali/integration-api/core.h index 90a0e3d..9f7504a 100644 --- a/dali/integration-api/core.h +++ b/dali/integration-api/core.h @@ -42,7 +42,7 @@ class GlSyncAbstraction; class PlatformAbstraction; class RenderController; class SystemOverlay; -class GyroscopeSensor; +class VrEngine; struct Event; struct TouchData; @@ -205,8 +205,8 @@ public: GlAbstraction& glAbstraction, GlSyncAbstraction& glSyncAbstraction, GestureManager& gestureManager, - GyroscopeSensor* gyroscopeSensor, - ResourcePolicy::DataRetention policy); + ResourcePolicy::DataRetention policy, + VrEngine* vrEngine ); /** * Non-virtual destructor. Core is not intended as a base class. diff --git a/dali/integration-api/file.list b/dali/integration-api/file.list index 37ca0b4..da95736 100644 --- a/dali/integration-api/file.list +++ b/dali/integration-api/file.list @@ -37,14 +37,14 @@ platform_abstraction_header_files = \ $(platform_abstraction_src_dir)/resource-cache.h \ $(platform_abstraction_src_dir)/resource-declarations.h \ $(platform_abstraction_src_dir)/gl-abstraction.h \ - $(platform_abstraction_src_dir)/gyroscope-sensor.h \ $(platform_abstraction_src_dir)/gl-defines.h \ $(platform_abstraction_src_dir)/gl-sync-abstraction.h \ $(platform_abstraction_src_dir)/gesture-manager.h \ $(platform_abstraction_src_dir)/render-controller.h \ $(platform_abstraction_src_dir)/platform-abstraction.h \ $(platform_abstraction_src_dir)/system-overlay.h \ - $(platform_abstraction_src_dir)/lockless-buffer.h + $(platform_abstraction_src_dir)/lockless-buffer.h \ + $(platform_abstraction_src_dir)/vr-engine.h platform_abstraction_events_header_files = \ $(platform_abstraction_src_dir)/events/event.h \ diff --git a/dali/integration-api/gyroscope-sensor.h b/dali/integration-api/gyroscope-sensor.h deleted file mode 100644 index 438ed62..0000000 --- a/dali/integration-api/gyroscope-sensor.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef __DALI_GYROSCOPE_SENSOR_H__ -#define __DALI_GYROSCOPE_SENSOR_H__ - -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -namespace Dali -{ -class Vector4; - -namespace Integration -{ - -// EXTERNAL INCLUDES -class GyroscopeSensor -{ -public: - - GyroscopeSensor() {} - virtual ~GyroscopeSensor() {} - - virtual void Enable() = 0; - virtual void Disable() = 0; - virtual void Read( Dali::Vector4& data ) = 0; - virtual void ReadPackets( Dali::Vector4* data, int count ) = 0; - virtual bool IsEnabled() = 0; - virtual bool IsSupported() = 0; -}; - -} // Integration -} // Dali - -#endif diff --git a/dali/integration-api/vr-engine.h b/dali/integration-api/vr-engine.h new file mode 100644 index 0000000..92453fd --- /dev/null +++ b/dali/integration-api/vr-engine.h @@ -0,0 +1,149 @@ +#ifndef DALI_VR_ENGINE_H +#define DALI_VR_ENGINE_H + +#include + +#include + +namespace Dali +{ +class EglInterface; + +namespace Integration +{ + +// using struct so in case of a need to pass more args only structure +// has to be modified. +namespace Vr +{ +struct VrEngineInitParams +{ + // screen settings + int screenWidth; + int screenHeight; + + // eye settings + uint32_t* fbos; // 2 values + uint32_t* colorTextures; + uint32_t* depthTextures; // may be null +}; + +struct VrEngineEyePose +{ + Quaternion rotation; + double timestamp; +}; + +struct VrEngineRenderTargetInfo +{ + int fbos[2]; + int colorTextures[2]; // if -1, then engine will create those buffers + int depthTextures[2]; +}; +} +/** + * @brief The VrEngine class + * + */ +class VrEngine +{ +public: + + enum EYE_ENUM + { + LEFT = 0, + RIGHT = 1 + }; + + enum VR_PROPERTY_ENUM + { + CURRENT_POSE_QUATERNION, // outputs float[4], rw + EYE_BUFFER_COUNT, // int, number of buffers ( 1 buffer for both eyes ), rw + + // render target by data structure + EYE_RENDER_TARGETS, // [VrEngineRenderTargetInfo*] + + EYE_BUFFER_WIDTH, // [int] width of single eye renderable area + EYE_BUFFER_HEIGHT, // [int] height of single eye renderable area + + EYE_CURRENT_POSE, // [ structure VrEngineEyePose ] + + /** + * Framebuffers per eye getter properties + */ + EYE_LEFT_CURRENT_TEXTURE_ID, // [int] ro, texture id to be written to ( updated with frame index ) + EYE_LEFT_TEXTURE_ID = 1000, // [int] rw, left eye texture id for buffer ( must be passed as EYE_LEFT_TEXTURE_ID+N ) + // helper enums + EYE_LEFT_TEXTURE0_ID = EYE_LEFT_TEXTURE_ID, + EYE_LEFT_TEXTURE1_ID = EYE_LEFT_TEXTURE_ID+1, + EYE_LEFT_TEXTURE2_ID = EYE_LEFT_TEXTURE_ID+2, + EYE_LEFT_TEXTURE3_ID = EYE_LEFT_TEXTURE_ID+3, + + EYE_RIGHT_CURRENT_TEXTURE_ID, // [int] ro, texture id to be written to ( updated with frame index ) + EYE_RIGHT_TEXTURE_ID = 1065, // [int] rw, right eye texture id for buffer ( must be passed as EYE_RIGHT_TEXTURE_ID+N ) + // helper enums + EYE_RIGHT_TEXTURE0_ID = EYE_RIGHT_TEXTURE_ID, + EYE_RIGHT_TEXTURE1_ID = EYE_RIGHT_TEXTURE_ID+1, + EYE_RIGHT_TEXTURE2_ID = EYE_RIGHT_TEXTURE_ID+2, + EYE_RIGHT_TEXTURE3_ID = EYE_RIGHT_TEXTURE_ID+3, + + EYE_LEFT_CURRENT_FBO_ID = 1999, + EYE_LEFT_FBO_ID = 2000, // [int] left eye fbo for buffer (EYE_LEFT_FBO_ID+N) + EYE_RIGHT_CURRENT_FBO_ID = 2099, + EYE_RIGHT_FBO_ID = 2100,// [int] right eye fbo for buffer (EYE_RIGHT_FBO_ID+N) + + EYE_LEFT_DEPTH_TEXTURE_ID = 3000, // [int] left eye depth texture for buffer (EYE_LEFT_FBO_ID+N) + EYE_RIGHT_DEPTH_TEXTURE_ID = 3064,// [int] right eye depth texture for buffer (EYE_RIGHT_FBO_ID+N) + }; + + VrEngine() {} + virtual ~VrEngine() {} + + virtual bool Initialize( Vr::VrEngineInitParams* initParams ) = 0; + virtual void Start() = 0; + virtual void Stop() = 0; + virtual void PreRender() = 0; + virtual void PostRender() = 0; + virtual void SubmitFrame() = 0; + + // client must perform output validation if necessary + virtual bool Get( const int property, void* output, int count ) = 0; + virtual bool Set( const int property, const void* input, int count ) = 0; + + // helper functions + bool Get( int property, void* output ) + { + return Get( property, output, 1 ); + } + + bool Set( int property, void* input ) + { + return Set( property, input, 1 ); + } + + inline bool Get( const int* properties, void** outputs, int count ) + { + // fill output array + for( int i = 0; i < count; ++i ) + { + Get( properties[i], outputs[i], 1 ); + } + return true; + } + + inline bool Set( const int* properties, const void** inputs, int count ) + { + // fill output array + for( int i = 0; i < count; ++i ) + { + return Set( properties[i], inputs[i], 1 ); + } + return true; + } +}; + +} // Integration + +} // Dali + +#endif diff --git a/dali/internal/common/core-impl.cpp b/dali/internal/common/core-impl.cpp index 2074216..f58d612 100644 --- a/dali/internal/common/core-impl.cpp +++ b/dali/internal/common/core-impl.cpp @@ -27,6 +27,9 @@ #include #include +// TODOVR +#include + #include #include #include @@ -83,11 +86,11 @@ using Integration::GlAbstraction; using Integration::Event; using Integration::UpdateStatus; using Integration::RenderStatus; -using Integration::GyroscopeSensor; - +using Integration::VrEngine; Core::Core( RenderController& renderController, PlatformAbstraction& platform, GlAbstraction& glAbstraction, GlSyncAbstraction& glSyncAbstraction, - GestureManager& gestureManager, GyroscopeSensor* gyroscopeSensor, ResourcePolicy::DataRetention dataRetentionPolicy) + GestureManager& gestureManager, ResourcePolicy::DataRetention dataRetentionPolicy, + VrEngine* vrEngine ) : mRenderController( renderController ), mPlatform(platform), mGestureEventProcessor(NULL), @@ -119,7 +122,13 @@ Core::Core( RenderController& renderController, PlatformAbstraction& platform, mGeometryBatcher = new SceneGraph::GeometryBatcher(); - mRenderManager = RenderManager::New( glAbstraction, glSyncAbstraction, *mGeometryBatcher, *mTextureUploadedQueue ); + mRenderManager = RenderManager::New( + glAbstraction, + glSyncAbstraction, + *mGeometryBatcher, + *mTextureUploadedQueue ); + + mRenderManager->SetVrEngine( vrEngine ); RenderQueue& renderQueue = mRenderManager->GetRenderQueue(); TextureCache& textureCache = mRenderManager->GetTextureCache(); @@ -161,7 +170,7 @@ Core::Core( RenderController& renderController, PlatformAbstraction& platform, mRelayoutController = IntrusivePtr< RelayoutController >( new RelayoutController( mRenderController ) ); mStage->Initialize(); - mStage->SetGyroscopeSensor( gyroscopeSensor ); + mStage->SetVrEngine( vrEngine ); mResourceClient = new ResourceClient( *mResourceManager, *mStage ); mGestureEventProcessor = new GestureEventProcessor(*mStage, gestureManager, mRenderController); @@ -170,7 +179,6 @@ Core::Core( RenderController& renderController, PlatformAbstraction& platform, mImageFactory = new ImageFactory( *mResourceClient ); mShaderFactory = new ShaderFactory(); mUpdateManager->SetShaderSaver( *mShaderFactory ); - mUpdateManager->SetGyroscopeSensor( *gyroscopeSensor ); mShaderFactory->LoadDefaultShaders(); GetImplementation(Dali::TypeRegistry::Get()).CallInitFunctions(); diff --git a/dali/internal/common/core-impl.h b/dali/internal/common/core-impl.h index 0f34230..b418514 100644 --- a/dali/internal/common/core-impl.h +++ b/dali/internal/common/core-impl.h @@ -41,7 +41,7 @@ class GlSyncAbstraction; class SystemOverlay; class UpdateStatus; class RenderStatus; -class GyroscopeSensor; +class VrEngine; struct Event; struct TouchData; } @@ -85,8 +85,8 @@ public: Integration::GlAbstraction& glAbstraction, Integration::GlSyncAbstraction& glSyncAbstraction, Integration::GestureManager& gestureManager, - Integration::GyroscopeSensor* gyroscopeSensor, - ResourcePolicy::DataRetention dataRetentionPolicy ); + ResourcePolicy::DataRetention dataRetentionPolicy, + Integration::VrEngine* vrEngine); /** * Destructor diff --git a/dali/internal/event/common/stage-impl.cpp b/dali/internal/event/common/stage-impl.cpp index 1b098b5..27a7241 100644 --- a/dali/internal/event/common/stage-impl.cpp +++ b/dali/internal/event/common/stage-impl.cpp @@ -41,7 +41,11 @@ #include #include //TODOVR +#include + using Dali::Internal::SceneGraph::Node; +using Dali::Integration::VrEngine; +using namespace Dali::Integration::Vr; namespace Dali { @@ -59,47 +63,37 @@ enum Eye RIGHT }; -//TODOVR: Gyroscope constraints -struct GyroEyeConstraint +//TODOVR: Sensor constraints +struct VrEyeConstraint { - GyroEyeConstraint( Dali::Internal::Stage* stage ) + VrEyeConstraint( Dali::Internal::Stage* stage ) : stage( stage ) { - pitch = Radian(Degree(0.0f)); - yaw = Radian(Degree(180.0f)); - roll = Radian(Degree(0.0f)); } void operator()( Quaternion& current, const PropertyInputContainer& inputs ) { // TODO: get gyro data, update rotation - // get data from gyroscope - Dali::Integration::GyroscopeSensor* sensor( stage->GetGyroscopeSensor() ); - if( !sensor->IsEnabled() ) + // get data from sensor + Dali::Integration::VrEngine* vrEngine( stage->GetVrEngine() ); + if( !vrEngine ) + { + return; + } + + VrEngineEyePose eyePose; + eyePose.rotation = current; + if( vrEngine->Get( VrEngine::EYE_CURRENT_POSE, &eyePose ) ) { - sensor->Enable(); - current.SetEuler( Radian((pitch)), Radian((yaw)), Radian((roll)) ); + current = eyePose.rotation; } else { - const int packets = 16; - Dali::Vector4 accumulated; - sensor->ReadPackets( &accumulated, packets ); - pitch = -accumulated.y; - yaw = accumulated.x; - roll = accumulated.z; - Quaternion rot; - rot.SetEuler( Radian((Degree(pitch))), Radian(Degree(yaw)), Radian(Degree(roll)) ); - current *= rot; + current = Quaternion( 1.0f, 0.0f, 0.0f, 0.0f ); } - //current = Dali::Quaternion() - } - Dali::Internal::Stage* stage; - float pitch; - float yaw; - float roll; + Dali::Internal::Stage* stage; }; //TODOVR @@ -410,7 +404,8 @@ void Stage::UpdateCameras() { const float pixelAspect = GetDpi().y / GetDpi().x; float stereoBase( 0.05f ); - + int L = LEFT; + int R = RIGHT; if( mSize.width > mSize.height ) { // Stereo mode with horizontal split is for landscape mode. That's the reason for the cameras being rotated @@ -477,32 +472,28 @@ void Stage::UpdateCameras() const float near = IPD+0.1f; //stereoBase = 0.0f; fov = Radian( Degree(106) ); - mStereoInfo[LEFT].camera->SetPerspectiveProjectionFovY( fov, cameraAspect, near, far, Vector2( 0.0f, +stereoBase ) ); + + mStereoInfo[L].camera->SetPerspectiveProjectionFovY( fov, cameraAspect, near, far, Vector2( +stereoBase, 0.0f ) ); //mStereoInfo[LEFT].camera->SetPerspectiveProjection( Size( mSize.width, sizeY ), Vector2::ZERO ); //mStereoInfo[LEFT].camera->SetPerspectiveProjection( Size( mSize.width, sizeY ), Vector2( 0.0f, stereoBase ) ); //mStereoInfo[LEFT].camera->SetAspectRatio( cameraAspect ); - //mStereoInfo[LEFT].camera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS ); + mStereoInfo[L].camera->SetOrientation( Dali::ANGLE_90, Vector3::ZAXIS ); //mStereoInfo[LEFT].camera->SetFieldOfView( fov ); - mStereoInfo[LEFT].renderTask.SetViewport( Viewport( 0, viewPortHeight, mSize.width, viewPortHeight ) ); + mStereoInfo[L].renderTask.SetViewport( Viewport( 0, 0, 1024, 1024 ) ); //mStereoInfo[RIGHT].camera->SetPerspectiveProjection( Size( mSize.width, sizeY ), Vector2::ZERO ); //mStereoInfo[RIGHT].camera->SetPerspectiveProjection( Size( mSize.width, sizeY ), Vector2( 0.0, -stereoBase ) ); - mStereoInfo[RIGHT].camera->SetPerspectiveProjectionFovY( fov, cameraAspect, near, far, Vector2( 0.0f, -stereoBase ) ); + mStereoInfo[R].camera->SetPerspectiveProjectionFovY( fov, cameraAspect, near, far, Vector2( -stereoBase, 0.0f ) ); //mStereoInfo[RIGHT].camera->SetAspectRatio( cameraAspect ); - //mStereoInfo[RIGHT].camera->SetOrientation( -Dali::ANGLE_90, Vector3::ZAXIS ); + mStereoInfo[R].camera->SetOrientation( Dali::ANGLE_90, Vector3::ZAXIS ); //mStereoInfo[RIGHT].camera->SetFieldOfView( fov ); - mStereoInfo[RIGHT].renderTask.SetViewport( Viewport( 0, 0, mSize.width, viewPortHeight ) ); + mStereoInfo[R].renderTask.SetViewport( Viewport( 0, 0, 1024, 1024 ) ); } - // VR camera will be feed from gyroscope input, for now using constraints - // Camera needs to check gyroscope state every update, simple constraint will - // solve the problem, however we need to keep that 'fake' update running, so that - // there's 'infinite' animation running. This way we are able to hit the constraint - // every frame and update orientation. mVRGyroEyeConstraint = Constraint::New( mDefaultCamera.Get(), Dali::Actor::Property::ORIENTATION, - GyroEyeConstraint( this )); + VrEyeConstraint( this )); mVRGyroEyeConstraint.Apply(); Dali::Actor actor( mDefaultCamera.Get() ); Quaternion quaternion( Radian(Degree(0)), Vector3( 0.0f, 0.0f, 0.0f )); @@ -511,13 +502,12 @@ void Stage::UpdateCameras() mVRDefaultCameraAnimation.SetLooping( true ); mVRDefaultCameraAnimation.Play(); - mStereoInfo[LEFT].camera->SetType( Camera::FREE_LOOK ); - mStereoInfo[RIGHT].camera->SetType( Camera::FREE_LOOK ); - //mDefaultCamera->SetType( Camera::VIRTUAL_REALITY ); + mStereoInfo[L].camera->SetType( Camera::VR_EYE_LEFT ); + mStereoInfo[R].camera->SetType( Camera::VR_EYE_RIGHT ); // Same settings regardless of orientation: //stereoBase = 0; - mStereoInfo[LEFT].camera->SetPosition( Vector3( 0.0f, -stereoBase, 0.0f ) ); - mStereoInfo[RIGHT].camera->SetPosition( Vector3( 0.f, +stereoBase, 0.0f ) ); + mStereoInfo[L].camera->SetPosition( Vector3( 0.0f, -stereoBase, 0.0f ) ); + mStereoInfo[R].camera->SetPosition( Vector3( 0.f, +stereoBase, 0.0f ) ); break; } diff --git a/dali/internal/event/common/stage-impl.h b/dali/internal/event/common/stage-impl.h index c36fc75..9658d0d 100644 --- a/dali/internal/event/common/stage-impl.h +++ b/dali/internal/event/common/stage-impl.h @@ -37,8 +37,6 @@ #include #include -#include - namespace Dali { @@ -47,7 +45,7 @@ struct Vector2; namespace Integration { class SystemOverlay; -class GyroscopeSensor; +class VrEngine; } namespace Internal @@ -432,16 +430,17 @@ public: // Implementation of EventThreadServices public: // VR - void SetGyroscopeSensor( Dali::Integration::GyroscopeSensor* sensor ) + void SetVrEngine( Dali::Integration::VrEngine* vrEngine ) { - mGyroscopeSensor = sensor; + mVrEngine = vrEngine; } - Dali::Integration::GyroscopeSensor* GetGyroscopeSensor() + Dali::Integration::VrEngine* GetVrEngine() { - return mGyroscopeSensor; + return mVrEngine; } + private: /** @@ -499,7 +498,7 @@ private: // The list of render-tasks IntrusivePtr mRenderTaskList; - Dali::Integration::GyroscopeSensor* mGyroscopeSensor; + Dali::Integration::VrEngine* mVrEngine; //TODOVR struct StereoInfo diff --git a/dali/internal/render/common/render-algorithms.cpp b/dali/internal/render/common/render-algorithms.cpp index 02353f3..d296903 100644 --- a/dali/internal/render/common/render-algorithms.cpp +++ b/dali/internal/render/common/render-algorithms.cpp @@ -127,7 +127,9 @@ inline void SetRenderFlags( const RenderList& renderList, Context& context, bool // Clear Depth and/or stencil buffers as required. // Note: The buffers will only be cleared if written to since a previous clear. - context.Clear( clearMask, Context::CHECK_CACHED_VALUES ); + // TODOVR: if vr force + context.Clear( clearMask, Context::FORCE_CLEAR ); + //context.Clear( clearMask, Context::CHECK_CACHED_VALUES ); } /** diff --git a/dali/internal/render/common/render-instruction.h b/dali/internal/render/common/render-instruction.h index 536f28d..9ddde0f 100644 --- a/dali/internal/render/common/render-instruction.h +++ b/dali/internal/render/common/render-instruction.h @@ -144,9 +144,9 @@ public: // Data unsigned int mOffscreenTextureId; ///< Optional offscreen target Render::FrameBuffer* mFrameBuffer; + Camera* mCamera; ///< camera that is used private: // Data - Camera* mCamera; ///< camera that is used RenderListContainer mRenderLists; ///< container of all render lists RenderListContainer::SizeType mNextFreeRenderList; ///< index for the next free render list diff --git a/dali/internal/render/common/render-manager.cpp b/dali/internal/render/common/render-manager.cpp index 0494ce0..19e4e8d 100644 --- a/dali/internal/render/common/render-manager.cpp +++ b/dali/internal/render/common/render-manager.cpp @@ -44,11 +44,16 @@ //TODOVR #include +#include #include +#include //TODOVR //#define DEBUG_DISABLE_BARREL_DISTORTION +using namespace Dali::Integration::Vr; +using Dali::Integration::VrEngine; + namespace Dali { @@ -80,43 +85,23 @@ typedef OwnerContainer< Render::RenderTracker* > RenderTrackerContainer; typedef RenderTrackerContainer::Iterator RenderTrackerIter; typedef RenderTrackerContainer::ConstIterator RenderTrackerConstIter; +#define GL(x) { x; int err = mImpl->context.GetError(); if(err) { DALI_LOG_ERROR( "GL_ERROR: [%d] '%s', %x\n", __LINE__, #x, (unsigned)err);fflush(stderr);fflush(stdout);} else { /*DALI_LOG_ERROR("GL Call: %s\n", #x); fflush(stdout);*/} } + /** * Structure to contain VR rendering data */ struct VrImpl { VrImpl() - : mainFrameBufferAttachments( ), - mainFrameBuffer( 0 ), - mainVRProgramGL( 0 ), - vrModeEnabled( true ) //TODOVR + : vrEngine( NULL ), + vrModeEnabled( true ), + initialised( false )//TODOVR { } - enum VrUniform - { - VR_UNIFORM_TEXTURE = 0, - VR_UNIFORM_MVP = 1, - VR_UNIFORM_MAX - }; - - struct Vertex - { - float aPosition[3]; - float aTexCoord[2]; - }; - - // in case of VR rendering to texture first then applying barrel distortion - unsigned int mainFrameBufferAttachments[2]; - unsigned int mainFrameBuffer; - unsigned int mainVRProgramGL; - unsigned int vertexBuffer; // contains 'cage' data, vec3, vec2 - unsigned int indexBuffer; // contains indices - unsigned int indicesCount; - Matrix MVP; - int uniformLocations[VR_UNIFORM_MAX]; - + Dali::Integration::VrEngine* vrEngine; bool vrModeEnabled; + bool initialised; }; /** @@ -267,6 +252,7 @@ void RenderManager::ContextCreated() mImpl->context.GlContextCreated(); mImpl->programController.GlContextCreated(); + // renderers, textures and gpu buffers cannot reinitialize themselves // so they rely on someone reloading the data for them } @@ -560,8 +546,6 @@ ProgramCache* RenderManager::GetProgramCache() return &(mImpl->programController); } -#define GL(x) { x; int err = mImpl->context.GetError(); if(err) { DALI_LOG_ERROR( "GL_ERROR: '%s', %x\n", #x, (unsigned)err);fflush(stderr);fflush(stdout);} else { /*DALI_LOG_ERROR("GL Call: %s\n", #x); fflush(stdout);*/} } - bool RenderManager::Render( Integration::RenderStatus& status ) { DALI_PRINT_RENDER_START( mImpl->renderBufferIndex ); @@ -582,41 +566,56 @@ bool RenderManager::Render( Integration::RenderStatus& status ) { // check if vr, if true create new main framebuffer, it's not the // right place to do it, but will do for now - if( mImpl->vrImpl.vrModeEnabled ) + if( mImpl->vrImpl.vrModeEnabled/* && !mImpl->vrImpl.vrEngine*/ ) { - if( !vr.mainFrameBuffer ) + if( mImpl->vrImpl.vrEngine && !mImpl->vrImpl.initialised ) { - SetupVRMode(); + // initialise VR engine + VrEngineInitParams params; + memset( ¶ms, 0, sizeof( VrEngineInitParams ) ); + params.screenWidth = mImpl->defaultSurfaceRect.width; + params.screenHeight = mImpl->defaultSurfaceRect.height; + mImpl->vrImpl.vrEngine->Initialize( ¶ms ); + mImpl->vrImpl.initialised = true; + + // start VR engine + mImpl->vrImpl.vrEngine->Start(); } } - // switch rendering to adaptor provided (default) buffer - GL( mImpl->context.BindFramebuffer( GL_FRAMEBUFFER, vr.vrModeEnabled ? vr.mainFrameBuffer : 0 ) ); - - int err = mImpl->context.GetError(); - err = err; - mImpl->context.Viewport( mImpl->defaultSurfaceRect.x, - mImpl->defaultSurfaceRect.y, - mImpl->defaultSurfaceRect.width, - mImpl->defaultSurfaceRect.height ); - - mImpl->context.ClearColor( mImpl->backgroundColor.r, - mImpl->backgroundColor.g, - mImpl->backgroundColor.b, - mImpl->backgroundColor.a ); - - mImpl->context.ClearStencil( 0 ); - - // Clear the entire color, depth and stencil buffers for the default framebuffer. - // It is important to clear all 3 buffers, for performance on deferred renderers like Mali - // e.g. previously when the depth & stencil buffers were NOT cleared, it caused the DDK to exceed a "vertex count limit", - // and then stall. That problem is only noticeable when rendering a large number of vertices per frame. - mImpl->context.SetScissorTest( false ); - mImpl->context.ColorMask( true ); - mImpl->context.DepthMask( true ); - mImpl->context.StencilMask( 0xFF ); // 8 bit stencil mask, all 1's - mImpl->context.Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, Context::FORCE_CLEAR ); + // prerender + if( mImpl->vrImpl.vrModeEnabled && mImpl->vrImpl.vrEngine ) + { + mImpl->vrImpl.vrEngine->PreRender(); + } + if( !mImpl->vrImpl.vrModeEnabled ) + { + // switch rendering to adaptor provided (default) buffer + GL( mImpl->context.BindFramebuffer( GL_FRAMEBUFFER, 0 ) ); + + mImpl->context.Viewport( mImpl->defaultSurfaceRect.x, + mImpl->defaultSurfaceRect.y, + mImpl->defaultSurfaceRect.width, + mImpl->defaultSurfaceRect.height ); + + mImpl->context.ClearColor( mImpl->backgroundColor.r, + mImpl->backgroundColor.g, + mImpl->backgroundColor.b, + mImpl->backgroundColor.a ); + + mImpl->context.ClearStencil( 0 ); + + // Clear the entire color, depth and stencil buffers for the default framebuffer. + // It is important to clear all 3 buffers, for performance on deferred renderers like Mali + // e.g. previously when the depth & stencil buffers were NOT cleared, it caused the DDK to exceed a "vertex count limit", + // and then stall. That problem is only noticeable when rendering a large number of vertices per frame. + mImpl->context.SetScissorTest( false ); + mImpl->context.ColorMask( true ); + mImpl->context.DepthMask( true ); + mImpl->context.StencilMask( 0xFF ); // 8 bit stencil mask, all 1's + mImpl->context.Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, Context::FORCE_CLEAR ); + } // reset the program matrices for all programs once per frame // this ensures we will set view and projection matrix once per program per camera mImpl->programController.ResetProgramMatrices(); @@ -641,7 +640,11 @@ bool RenderManager::Render( Integration::RenderStatus& status ) if( vr.vrModeEnabled ) { - RenderVR(); + if( mImpl->vrImpl.vrEngine ) + { + mImpl->context.Flush(); + vr.vrEngine->SubmitFrame(); + } } } @@ -679,7 +682,7 @@ void RenderManager::DoRender( RenderInstruction& instruction, Shader& defaultSha } FrameBufferTexture* offscreen = NULL; - + bool vrEye( false ); if ( instruction.mOffscreenTextureId != 0 ) { offscreen = mImpl->textureCache.GetFramebuffer( instruction.mOffscreenTextureId ); @@ -722,25 +725,69 @@ void RenderManager::DoRender( RenderInstruction& instruction, Shader& defaultSha } else // !(instruction.mOffscreenTexture) { + VrEngine* vr = mImpl->vrImpl.vrEngine; + if( vr ) + { + mImpl->context.GetError(); + + // will read all vr properties at once + int lfbo(-1), rfbo(-1), ltex(-1), rtex(-1), bufwidth(-1), bufheight(-1); + int properties[] = + { + VrEngine::EYE_LEFT_CURRENT_FBO_ID, VrEngine::EYE_RIGHT_CURRENT_FBO_ID, + VrEngine::EYE_LEFT_CURRENT_TEXTURE_ID, VrEngine::EYE_RIGHT_CURRENT_TEXTURE_ID, + VrEngine::EYE_BUFFER_WIDTH, VrEngine::EYE_BUFFER_HEIGHT + }; + void* values[] = + { + &lfbo, &rfbo, <ex, &rtex, &bufwidth, &bufheight + }; + if( instruction.mCamera->mType == Dali::Camera::VR_EYE_LEFT ) + { + vrEye = true; + vr->Get( properties, values, 6 ); + //DALI_LOG_ERROR("This is Left VR camera!\n"); + GL( mImpl->context.BindFramebuffer( GL_FRAMEBUFFER, lfbo ) ); + GL( mImpl->context.Bind2dTexture( ltex ) ); + GL( mImpl->context.TexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, bufwidth, bufheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ) ); + } + else if( instruction.mCamera->mType == Dali::Camera::VR_EYE_RIGHT ) + { + vrEye = true; + vr->Get( properties, values, 6 ); + //DALI_LOG_ERROR("This is Right VR camera!\n"); + GL( mImpl->context.BindFramebuffer( GL_FRAMEBUFFER, rfbo) ); + GL( mImpl->context.Bind2dTexture( rtex ) ); + GL( mImpl->context.TexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, bufwidth, bufheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL ) ); + } + } + else + { + GL( mImpl->context.BindFramebuffer( GL_FRAMEBUFFER, 0 ) ); + } // switch rendering to adaptor provided (default) buffer - mImpl->context.BindFramebuffer( GL_FRAMEBUFFER, mImpl->vrImpl.vrModeEnabled ? mImpl->vrImpl.mainFrameBuffer : 0 ); + // Check whether a viewport is specified, otherwise the full surface size is used if ( instruction.mIsViewportSet ) { // For glViewport the lower-left corner is (0,0) - const int y = ( mImpl->defaultSurfaceRect.height - instruction.mViewport.height ) - instruction.mViewport.y; - viewportRect.Set( instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height ); + // TODOVR: using 2 buffers, vieport Y starts with 0 + //const int y = 0;//( mImpl->defaultSurfaceRect.height - instruction.mViewport.height ) - instruction.mViewport.y; + //viewportRect.Set( instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height ); + viewportRect.Set( 0, 0, 1024, 1024 ); } else { viewportRect = mImpl->defaultSurfaceRect; } + + } mImpl->context.Viewport(viewportRect.x, viewportRect.y, viewportRect.width, viewportRect.height); - if ( instruction.mIsClearColorSet ) + if ( vrEye || instruction.mIsClearColorSet ) { mImpl->context.ClearColor( clearColor.r, clearColor.g, @@ -751,7 +798,14 @@ void RenderManager::DoRender( RenderInstruction& instruction, Shader& defaultSha mImpl->context.SetScissorTest( true ); mImpl->context.Scissor( viewportRect.x, viewportRect.y, viewportRect.width, viewportRect.height ); mImpl->context.ColorMask( true ); - mImpl->context.Clear( GL_COLOR_BUFFER_BIT , Context::CHECK_CACHED_VALUES ); + if( vrEye ) + { + mImpl->context.Clear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT, Context::FORCE_CLEAR ); + } + else + { + mImpl->context.Clear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT, Context::FORCE_CLEAR); + } mImpl->context.SetScissorTest( false ); } @@ -762,7 +816,7 @@ void RenderManager::DoRender( RenderInstruction& instruction, Shader& defaultSha mImpl->geometryBatcher, mImpl->renderBufferIndex ); - if(instruction.mOffscreenTextureId != 0) + if(instruction.mOffscreenTextureId != 0 || vrEye) { GLenum attachments[] = { GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT }; mImpl->context.InvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments); @@ -778,267 +832,9 @@ void RenderManager::DoRender( RenderInstruction& instruction, Shader& defaultSha } } -namespace { -inline void Orthographic(Matrix& result, float left, float right, float bottom, float top, float near, float far, bool invertYAxis) +void RenderManager::SetVrEngine( Integration::VrEngine* vrEngine ) { - if ( Equals(right, left) || Equals(top, bottom) || Equals(far, near) ) - { - DALI_LOG_ERROR( "Cannot create orthographic projection matrix with a zero dimension.\n" ); - DALI_ASSERT_DEBUG( "Cannot create orthographic projection matrix with a zero dimension." ); - return; - } - - float deltaX = right - left; - float deltaY = invertYAxis ? bottom - top : top - bottom; - float deltaZ = far - near; - - float *m = result.AsFloat(); - m[0] = -2.0f / deltaX; - m[1] = 0.0f; - m[2] = 0.0f; - m[3] = 0.0f; - - m[4] = 0.0f; - m[5] = -2.0f / deltaY; - m[6] = 0.0f; - m[7] = 0.0f; - - m[8] = 0.0f; - m[9] = 0.0f; - m[10] = 2.0f / deltaZ; - m[11] = 0.0f; - m[12] = -(right + left) / deltaX; - m[13] = -(top + bottom) / deltaY; - m[14] = -(near + far) / deltaZ; - m[15] = 1.0f; -} - -/* -void LookAt(Matrix& result, const Vector3& eye, const Vector3& target, const Vector3& up) -{ - Vector3 vZ = target - eye; - vZ.Normalize(); - - Vector3 vX = up.Cross(vZ); - vX.Normalize(); - - Vector3 vY = vZ.Cross(vX); - vY.Normalize(); - - result.SetInverseTransformComponents(vX, vY, vZ, eye); -} -*/ -} - -void RenderManager::SetupVRMode() -{ - VrImpl& vr = mImpl->vrImpl; - Context& ctx =mImpl->context; - Integration::GlAbstraction& gl = ctx.GetAbstraction(); - - GL( ctx.GenFramebuffers( 1, &vr.mainFrameBuffer ) ); - GL( ctx.GenTextures( 1, &vr.mainFrameBufferAttachments[0] ) ); - GL( ctx.BindFramebuffer( GL_FRAMEBUFFER, vr.mainFrameBuffer ) ); - - // color attachment - GL( ctx.Bind2dTexture( vr.mainFrameBufferAttachments[0] ) ); - GL( ctx.TexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, - mImpl->defaultSurfaceRect.width, - mImpl->defaultSurfaceRect.height, - 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 ) ); - GL( ctx.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ) ); - GL( ctx.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ) ); - GL( ctx.FramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, vr.mainFrameBufferAttachments[0], 0 ) ); - - // depth/stencil attachment - // if gles3 render depth to the texture -#if 0 - GL( mImpl->context.GenTextures( 1, &mImpl->mainFrameBufferAttachments[1] ) ); - GL( mImpl->context.Bind2dTexture( mImpl->mainFrameBufferAttachments[1] ) ); - GL( mImpl->context.TexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, - mImpl->defaultSurfaceRect.width, - mImpl->defaultSurfaceRect.height, - 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0 ) ); - GL( mImpl->context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ) ); - GL( mImpl->context.TexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ) ); - GL( mImpl->context.FramebufferTexture2D( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, mImpl->mainFrameBufferAttachments[1], 0 ) ); -#else - GL( ctx.GenRenderbuffers( 1, &vr.mainFrameBufferAttachments[1] ) ); - GL( ctx.BindRenderbuffer( GL_RENDERBUFFER, vr.mainFrameBufferAttachments[1] ) ); - GL( ctx.RenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, - mImpl->defaultSurfaceRect.width, - mImpl->defaultSurfaceRect.height ) ); - GL( ctx.FramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, vr.mainFrameBufferAttachments[1] ) ); -#endif - - GLenum drawBuffers[1] = { GL_COLOR_ATTACHMENT0 }; - gl.DrawBuffers( 1, drawBuffers ); - - // prepare shader and buffer to render barrel distortion in one go ( with time warp it may need to do with 2 goes ) - const char* shaderSource[2] = - { - // vertex shader - "attribute vec3 aPosition;\n" - "attribute vec2 aTexCoord;\n" - "uniform highp mat4 mvp;\n" - "varying mediump vec2 vTexCoord;\n" - "void main()\n" - "{" - " vec3 pos = aPosition;\n" - //" pos.y -= 1.0;\n" - " gl_Position = mvp * vec4( pos, 1.0 );\n" - " mediump vec2 uvs = vec2( aTexCoord );\n" -// " uvs.r = 1.0 - uvs.r;\n" - " vTexCoord = uvs;\n" - "}\n\0", - - // fragment shader - "uniform sampler2D texSampler;\n" - "\n" - "varying mediump vec2 vTexCoord;\n" - "void main()\n" - "{ \n" -#ifdef DEBUG_DISABLE_BARREL_DISTORTION -#ifdef DEBUG_VR_TINT_EACH_EYE - " mediump vec4 mulcol = vec4( 1.0, 0.0, 0.0, 1.0 );\n" - " if( vTexCoord.y < 0.5 ) { mulcol = vec4( 0.0, 1.0, 0.0, 1.0 ); }\n" - " gl_FragColor = texture2D( texSampler, vTexCoord ) * mulcol;\n" -#else - " gl_FragColor = texture2D( texSampler, vTexCoord );\n" -#endif -#else - " gl_FragColor = texture2D( texSampler, vTexCoord );\n" -#endif - "}\n\0", - }; - - // using GL explicitly in order to create shaders and program - GLuint shaders[2]; - GLuint program; - for( int i = 0; i < 2; ++i ) - { - GL( shaders[ i ] = ctx.CreateShader( i ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER ) ); - GL( ctx.ShaderSource( shaders[i], 1, &shaderSource[i], NULL ) ); - GL( ctx.CompileShader( shaders[i] ) ); - } - - GL( program = mImpl->context.CreateProgram() ); - GL( mImpl->context.AttachShader( program, shaders[0] ) ); - GL( mImpl->context.AttachShader( program, shaders[1] ) ); - GL( mImpl->context.LinkProgram( program) ); - - vr.mainVRProgramGL = program; - -#ifdef DEBUG_DISABLE_BARREL_DISTORTION - const float w = 1.0f;//(float)mImpl->defaultSurfaceRect.width; - const float h = 1.0f;//(float)mImpl->defaultSurfaceRect.height; - - // create vertex buffer - VrImpl::Vertex vertices[] = - { - { { -w, -h, 0.0f }, { 0.0f, 0.0f } }, - { { w, -h, 0.0f }, { 1.0f, 0.0f } }, - { { w, h, 0.0f }, { 1.0f, 1.0f } }, - { { -w, -h, 0.0f }, { 0.0f, 0.0f } }, - { { w, h, 0.0f }, { 1.0f, 1.0f } }, - { { -w, h, 0.0f }, { 0.0f, 1.0f } }, - }; - - GL( ctx.GenBuffers( 1, &vr.vertexBuffer ) ); - GL( ctx.BindArrayBuffer( vr.vertexBuffer ) ); - GL( ctx.BufferData( GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW ) ); -#else - // create vertex buffer - std::vector vertices; - std::vector indices; - GenerateGridVertexBuffer( vertices ); - GenerateGridIndexBuffer( indices ); - - // vertex buffer - GL( ctx.GenBuffers( 1, &vr.vertexBuffer ) ); - GL( ctx.BindArrayBuffer( vr.vertexBuffer ) ); - GL( ctx.BufferData( GL_ARRAY_BUFFER, vertices.size()*sizeof(float), vertices.data(), GL_STATIC_DRAW ) ); - - // index buffer - GL( ctx.GenBuffers( 1, &vr.indexBuffer ) ); - GL( ctx.BindArrayBuffer( vr.indexBuffer ) ); - GL( ctx.BufferData( GL_ARRAY_BUFFER, indices.size()*sizeof(uint16_t), indices.data(), GL_STATIC_DRAW ) ); - vr.indicesCount = indices.size(); -#endif - - GL( vr.uniformLocations[ VrImpl::VR_UNIFORM_MVP ] = ctx.GetUniformLocation( program, "mvp" ) ); - GL( vr.uniformLocations[ VrImpl::VR_UNIFORM_TEXTURE ] = ctx.GetUniformLocation( program, "texSampler" ) ); - - // mvp - Matrix proj, view; - - //float asp = (float)mImpl->defaultSurfaceRect.height / (float)mImpl->defaultSurfaceRect.width; - - float shift = 0.016f; - Orthographic( proj, -1.0f, 1.0f, 1.0f+shift, -1.0f+shift, -1.0f, 1.0f, false ); - //LookAt( view, Vector3( 0.0f, 0.0f, 0.0f ), Vector3( 0.0f, 0.0f, 1.0f ), Vector3( 0.0f, 1.0f, 0.0f ) ); - //mat.SetTranslation( Vector3(0.0f, 0.0f, 1.0f ) ); - Matrix::Multiply( vr.MVP, view, proj ); - vr.MVP = proj; - - //vr.MVP.Multiply( vr.MVP, vp, mat ); - return; -} - -void RenderManager::RenderVR() -{ - static float f = 1.0f; - VrImpl& vr = mImpl->vrImpl; - Context& ctx = mImpl->context; - Integration::GlAbstraction& gl = ctx.GetAbstraction(); - GL( ctx.BindFramebuffer( GL_FRAMEBUFFER, 0 ) ); - gl.Viewport( 0, 0, mImpl->defaultSurfaceRect.width, mImpl->defaultSurfaceRect.height ); - ctx.Scissor( 0, 0, mImpl->defaultSurfaceRect.width, mImpl->defaultSurfaceRect.height ); - //DALI_LOG_ERROR("VR: %d, %d\n", (int) mImpl->defaultSurfaceRect.width, (int) mImpl->defaultSurfaceRect.height); - - gl.Disable( GL_SCISSOR_TEST ); - //gl.Disable( GL_DEPTH_TEST ); - gl.ClearColor( 1.0f, 0.0f, 0.0f, 1.0f ); - //gl.Clear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); - f -= 0.2f; - if( f < 0 ) - f = 1.0f; - //GL( gl.Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ); - // store old program - Program* program = GetProgramCache()->GetCurrentProgram(); - GetProgramCache()->SetCurrentProgram( NULL ); - GL( ctx.UseProgram( vr.mainVRProgramGL ) ); - - // attributes - GL( ctx.BindArrayBuffer( vr.vertexBuffer ) ); - GL( ctx.VertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, sizeof(VrImpl::Vertex), 0 ) ); - GL( ctx.VertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, sizeof(VrImpl::Vertex), (const void*)(sizeof(float)*3)) ); - GL( gl.EnableVertexAttribArray( 0 ) ); - GL( gl.EnableVertexAttribArray( 1 ) ); - -#ifndef DEBUG_DISABLE_BARREL_DISTORTION - GL( ctx.BindElementArrayBuffer( vr.indexBuffer ) ); -#endif - - // uniforms - // texture - GL( ctx.ActiveTexture( TEXTURE_UNIT_IMAGE ) ); - GL( ctx.Bind2dTexture( vr.mainFrameBufferAttachments[0] ) ); - GL( gl.Uniform1i( vr.uniformLocations[ VrImpl::VR_UNIFORM_TEXTURE], 0 ) ); - - // matrix - GL( gl.UniformMatrix4fv( vr.uniformLocations[ VrImpl::VR_UNIFORM_MVP ], - 1, GL_FALSE, vr.MVP.AsFloat() ) ); - -#ifdef DEBUG_DISABLE_BARREL_DISTORTION - GL( gl.DrawArrays( GL_TRIANGLES, 0, 6 ) ); -#else - GL( gl.DrawElements( GL_TRIANGLES, vr.indicesCount, GL_UNSIGNED_SHORT, 0 ) ); - -#endif - - if( program ) - program->Use(); + mImpl->vrImpl.vrEngine = vrEngine; } } // namespace SceneGraph diff --git a/dali/internal/render/common/render-manager.h b/dali/internal/render/common/render-manager.h index f489876..fe02664 100644 --- a/dali/internal/render/common/render-manager.h +++ b/dali/internal/render/common/render-manager.h @@ -35,6 +35,7 @@ namespace Integration class GlAbstraction; class GlSyncAbstraction; class RenderStatus; +class VrEngine; } struct Vector4; @@ -359,8 +360,9 @@ private: */ void DoRender( RenderInstruction& instruction, Shader& defaultShader ); - void SetupVRMode(); - void RenderVR(); +public: + + void SetVrEngine( Dali::Integration::VrEngine* vrEngine ); private: diff --git a/dali/internal/render/gl-resources/context.h b/dali/internal/render/gl-resources/context.h index 1026ce4..556134a 100644 --- a/dali/internal/render/gl-resources/context.h +++ b/dali/internal/render/gl-resources/context.h @@ -414,8 +414,10 @@ public: void Clear(GLbitfield mask, ClearMode mode ) { bool forceClear = (mode == FORCE_CLEAR ); - mask = mFrameBufferStateCache.GetClearMask( mask, forceClear , mScissorTestEnabled ); - + if( !forceClear ) + { + mask = mFrameBufferStateCache.GetClearMask( mask, forceClear , mScissorTestEnabled ); + } if( mask > 0 ) { LOG_GL("Clear %d\n", mask); diff --git a/dali/internal/update/manager/update-manager.cpp b/dali/internal/update/manager/update-manager.cpp index fade246..3b45ab6 100644 --- a/dali/internal/update/manager/update-manager.cpp +++ b/dali/internal/update/manager/update-manager.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include @@ -163,8 +162,7 @@ struct UpdateManager::Impl previousUpdateScene( false ), frameCounter( 0 ), renderSortingHelper(), - renderTaskWaiting( false ), - gyroscopeSensor( NULL ) + renderTaskWaiting( false ) { sceneController = new SceneControllerImpl( renderMessageDispatcher, renderQueue, discardQueue ); @@ -276,8 +274,6 @@ struct UpdateManager::Impl GestureContainer gestures; ///< A container of owned gesture detectors bool renderTaskWaiting; ///< A REFRESH_ONCE render task is waiting to be rendered - - GyroscopeSensor* gyroscopeSensor; }; UpdateManager::UpdateManager( NotificationManager& notificationManager, @@ -634,11 +630,6 @@ void UpdateManager::RemoveGesture( PanGesture* gesture ) DALI_ASSERT_DEBUG(false); } -void UpdateManager::SetGyroscopeSensor( Dali::Integration::GyroscopeSensor& sensor ) -{ - mImpl->gyroscopeSensor = &sensor; -} - void UpdateManager::AddTextureSet( TextureSet* textureSet ) { DALI_ASSERT_DEBUG( NULL != textureSet ); diff --git a/dali/internal/update/manager/update-manager.h b/dali/internal/update/manager/update-manager.h index 117bef6..ca1de09 100644 --- a/dali/internal/update/manager/update-manager.h +++ b/dali/internal/update/manager/update-manager.h @@ -46,7 +46,6 @@ namespace Integration { class GlSyncAbstraction; class RenderController; -class GyroscopeSensor; } // namespace Integration namespace Internal @@ -333,11 +332,7 @@ public: */ void RemoveGesture( PanGesture* gesture ); - // Sensors - - void SetGyroscopeSensor( Dali::Integration::GyroscopeSensor& sensor ); - -// Message queue handling + // Message queue handling /** * Reserve space for another message in the queue; this must then be initialized by the caller. diff --git a/dali/internal/update/render-tasks/scene-graph-camera.cpp b/dali/internal/update/render-tasks/scene-graph-camera.cpp index d1d60db..a7a0ad9 100644 --- a/dali/internal/update/render-tasks/scene-graph-camera.cpp +++ b/dali/internal/update/render-tasks/scene-graph-camera.cpp @@ -286,12 +286,6 @@ const PropertyInputImpl* Camera::GetViewMatrix() const void Camera::Update( BufferIndex updateBufferIndex, const Node& owningNode ) { - if( mType == Dali::Camera::VIRTUAL_REALITY ) - { - mUpdateViewFlag = UPDATE_COUNT; - - } - else { // if owning node has changes in world position we need to update camera for next 2 frames if( owningNode.IsLocalMatrixDirty() ) @@ -351,7 +345,8 @@ unsigned int Camera::UpdateViewMatrix( BufferIndex updateBufferIndex, const Node { // camera orientation taken from node - i.e. look in abitrary, unconstrained direction case Dali::Camera::FREE_LOOK: - case Dali::Camera::VIRTUAL_REALITY: + case Dali::Camera::VR_EYE_LEFT: + case Dali::Camera::VR_EYE_RIGHT: { Matrix& viewMatrix = mViewMatrix.Get( updateBufferIndex ); viewMatrix = owningNode.GetWorldMatrix( updateBufferIndex ); diff --git a/dali/public-api/actors/camera-actor.h b/dali/public-api/actors/camera-actor.h index 66464b9..5abe9c6 100644 --- a/dali/public-api/actors/camera-actor.h +++ b/dali/public-api/actors/camera-actor.h @@ -46,7 +46,8 @@ enum Type { FREE_LOOK, ///< Camera orientation is taken from CameraActor @SINCE_1_0.0 LOOK_AT_TARGET, ///< Camera is oriented to always look at a target @SINCE_1_0.0 - VIRTUAL_REALITY ///< Camera uses senseors in order to maintain the orientation + VR_EYE_LEFT, ///< Camera uses senseors in order to maintain the orientation + VR_EYE_RIGHT, ///< Camera uses senseors in order to maintain the orientation }; /** -- 2.7.4