sceneRenderState.cpp
Engine/source/scene/sceneRenderState.cpp
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/platform.h" 25#include "scene/sceneRenderState.h" 26 27#include "renderInstance/renderPassManager.h" 28#include "math/util/matrixSet.h" 29 30//----------------------------------------------------------------------------- 31 32SceneRenderState::SceneRenderState( SceneManager* sceneManager, 33 ScenePassType passType, 34 const SceneCameraState& view, 35 RenderPassManager* renderPass /* = NULL */, 36 bool usePostEffects /* = true */ ) 37 : mSceneManager( sceneManager ), 38 mScenePassType( passType ), 39 mRenderPass( renderPass ? renderPass : sceneManager->getDefaultRenderPass() ), 40 mCullingState( sceneManager, view ), 41 mUsePostEffects( usePostEffects ), 42 mRenderLightmappedMeshes( true ), 43 mRenderNonLightmappedMeshes( true ), 44 mRenderArea( view.getFrustum().getBounds() ), 45 mDisableAdvancedLightingBins( false ), 46 mSceneRenderStyle( SRS_Standard ), 47 mAmbientLightColor( sceneManager->getAmbientLightColor() ) 48{ 49 // Setup the default parameters for the screen metrics methods. 50 mDiffuseCameraTransform = view.getHeadWorldViewMatrix(); 51 mDiffuseCameraTransform.inverse(); 52 53 // The vector eye is the camera vector with its 54 // length normalized to 1 / zFar. 55 getCameraTransform().getColumn( 1, &mVectorEye ); 56 mVectorEye.normalize( 1.0f / getFarPlane() ); 57 58 // TODO: What about ortho modes? Is near plane ok 59 // or do i need to remove it... maybe ortho has a near 60 // plane of 1 and it just works out? 61 62 const Frustum& frustum = view.getFrustum(); 63 const RectI& viewport = view.getViewport(); 64 65 mWorldToScreenScale.set( ( frustum.getNearDist() * viewport.extent.x ) / ( frustum.getNearRight() - frustum.getNearLeft() ), 66 ( frustum.getNearDist() * viewport.extent.y ) / ( frustum.getNearTop() - frustum.getNearBottom() ) ); 67 68 // Assign shared matrix data to the render pass. 69 70 mRenderPass->assignSharedXform( RenderPassManager::View, view.getWorldViewMatrix() ); 71 mRenderPass->assignSharedXform( RenderPassManager::Projection, view.getProjectionMatrix() ); 72} 73 74//----------------------------------------------------------------------------- 75 76SceneRenderState::~SceneRenderState() 77{ 78} 79 80//----------------------------------------------------------------------------- 81 82const MatrixF& SceneRenderState::getWorldViewMatrix() const 83{ 84 return getRenderPass()->getMatrixSet().getWorldToCamera(); 85} 86 87//----------------------------------------------------------------------------- 88 89const MatrixF& SceneRenderState::getProjectionMatrix() const 90{ 91 return getRenderPass()->getMatrixSet().getCameraToScreen(); 92} 93 94const MatrixF& SceneRenderState::getInvProjectionMatrix() const 95{ 96 return getRenderPass()->getMatrixSet().getScreenToCamera(); 97} 98 99//----------------------------------------------------------------------------- 100 101void SceneRenderState::renderObjects( SceneObject** objects, U32 numObjects ) 102{ 103 // Let the objects batch their stuff. 104 105 PROFILE_START( SceneRenderState_prepRenderImages ); 106 for( U32 i = 0; i < numObjects; ++ i ) 107 { 108 SceneObject* object = objects[ i ]; 109 object->prepRenderImage( this ); 110 } 111 112 PROFILE_END(); 113 114 // Render what the objects have batched. 115 116 getRenderPass()->renderPass( this ); 117} 118