2011-10-25 05:03:10 +00:00
//
2012-12-20 22:08:41 +00:00
// KRCamera.cpp
2011-10-25 05:03:10 +00:00
// KREngine
//
2012-03-15 20:09:01 +00:00
// Copyright 2012 Kearwood Gilbert. All rights reserved.
2011-10-25 06:16:47 +00:00
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
2012-11-15 22:05:25 +00:00
//
2011-10-25 06:16:47 +00:00
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
2011-10-25 05:03:10 +00:00
//
2013-01-11 03:21:19 +00:00
# include "KREngine-common.h"
# include "KRVector2.h"
# include "KRCamera.h"
# include "KRStockGeometry.h"
# include "KRDirectionalLight.h"
2011-10-25 05:03:10 +00:00
2012-12-20 22:08:41 +00:00
KRCamera : : KRCamera ( KRScene & scene , std : : string name ) : KRNode ( scene , name ) {
2013-03-22 17:17:12 -07:00
m_last_frame_start = 0 ;
2012-11-02 20:50:45 +00:00
m_particlesAbsoluteTime = 0.0f ;
2014-04-29 00:30:14 -07:00
m_backingWidth = 0 ;
m_backingHeight = 0 ;
2012-11-14 21:46:30 +00:00
volumetricBufferWidth = 0 ;
volumetricBufferHeight = 0 ;
2012-12-20 22:08:41 +00:00
m_pSkyBoxTexture = NULL ;
2012-08-16 20:44:33 +00:00
2012-10-17 19:43:15 +00:00
compositeDepthTexture = 0 ;
compositeColorTexture = 0 ;
lightAccumulationTexture = 0 ;
compositeFramebuffer = 0 ;
lightAccumulationBuffer = 0 ;
2012-11-09 20:55:23 +00:00
volumetricLightAccumulationBuffer = 0 ;
volumetricLightAccumulationTexture = 0 ;
2013-03-22 17:17:12 -07:00
m_frame_times_filled = 0 ;
2014-04-29 00:30:14 -07:00
m_downsample = KRVector2 : : One ( ) ;
2014-06-25 00:45:00 -07:00
m_fade_color = KRVector4 : : Zero ( ) ;
2011-10-25 05:03:10 +00:00
}
KRCamera : : ~ KRCamera ( ) {
2012-08-15 21:26:06 +00:00
destroyBuffers ( ) ;
2011-10-25 05:03:10 +00:00
}
2013-05-24 12:20:47 -07:00
std : : string KRCamera : : getElementName ( ) {
return " camera " ;
}
tinyxml2 : : XMLElement * KRCamera : : saveXML ( tinyxml2 : : XMLNode * parent )
{
tinyxml2 : : XMLElement * e = KRNode : : saveXML ( parent ) ;
2014-11-26 22:24:35 -08:00
e - > SetAttribute ( " skybox " , m_skyBox . c_str ( ) ) ;
2013-05-24 12:20:47 -07:00
return e ;
}
void KRCamera : : loadXML ( tinyxml2 : : XMLElement * e )
{
KRNode : : loadXML ( e ) ;
2014-11-26 22:24:35 -08:00
const char * szSkyBoxName = e - > Attribute ( " skybox " ) ;
m_skyBox = szSkyBoxName ? szSkyBoxName : " " ;
2013-05-24 12:20:47 -07:00
}
2014-11-26 22:24:35 -08:00
void KRCamera : : setSkyBox ( const std : : string & skyBox )
2014-03-18 12:27:08 -07:00
{
2014-11-26 22:24:35 -08:00
m_pSkyBoxTexture = NULL ;
m_skyBox = skyBox ;
}
const std : : string KRCamera : : getSkyBox ( ) const
{
return m_skyBox ;
2014-03-18 12:27:08 -07:00
}
2013-02-08 17:28:17 -08:00
void KRCamera : : renderFrame ( float deltaTime , GLint renderBufferWidth , GLint renderBufferHeight )
2014-04-29 00:30:14 -07:00
{
2013-03-22 17:17:12 -07:00
// ----====---- Record timing information for measuring FPS ----====----
uint64_t current_time = m_pContext - > getAbsoluteTimeMilliseconds ( ) ;
if ( m_last_frame_start ! = 0 ) {
m_frame_times [ m_pContext - > getCurrentFrame ( ) % KRAKEN_FPS_AVERAGE_FRAME_COUNT ] = ( current_time - m_last_frame_start ) ;
if ( m_frame_times_filled < KRAKEN_FPS_AVERAGE_FRAME_COUNT ) m_frame_times_filled + + ;
}
m_last_frame_start = current_time ;
2016-01-30 20:13:23 -08:00
GLint defaultFBO = - 1 ;
2013-02-06 11:59:24 -08:00
GLDEBUG ( glGetIntegerv ( GL_FRAMEBUFFER_BINDING , & defaultFBO ) ) ;
2013-02-08 17:28:17 -08:00
createBuffers ( renderBufferWidth , renderBufferHeight ) ;
2012-12-28 03:20:06 +00:00
KRScene & scene = getScene ( ) ;
2013-02-06 11:59:24 -08:00
2013-05-24 12:20:47 -07:00
KRMat4 modelMatrix = getModelMatrix ( ) ;
KRMat4 viewMatrix = KRMat4 : : LookAt ( KRMat4 : : Dot ( modelMatrix , KRVector3 : : Zero ( ) ) , KRMat4 : : Dot ( modelMatrix , KRVector3 : : Forward ( ) ) , KRVector3 : : Normalize ( KRMat4 : : DotNoTranslate ( modelMatrix , KRVector3 : : Up ( ) ) ) ) ;
//KRMat4 viewMatrix = KRMat4::Invert(getModelMatrix());
2012-10-03 19:29:37 +00:00
2014-04-29 00:30:14 -07:00
settings . setViewportSize ( KRVector2 ( m_backingWidth , m_backingHeight ) ) ;
2012-12-20 22:08:41 +00:00
KRMat4 projectionMatrix ;
projectionMatrix . perspective ( settings . perspective_fov , settings . m_viewportSize . x / settings . m_viewportSize . y , settings . perspective_nearz , settings . perspective_farz ) ;
m_viewport = KRViewport ( settings . getViewportSize ( ) , viewMatrix , projectionMatrix ) ;
2013-04-04 17:53:39 -07:00
m_viewport . setLODBias ( settings . getLODBias ( ) ) ;
2012-12-22 00:40:37 +00:00
2012-10-26 19:31:27 +00:00
KRVector3 vecCameraDirection = m_viewport . getCameraDirection ( ) ;
2012-09-21 08:24:55 +00:00
2013-04-04 12:50:53 -07:00
scene . updateOctree ( m_viewport ) ;
2014-04-23 01:43:00 -07:00
// ----====---- Pre-stream resources ----====----
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_PRESTREAM , true ) ;
2013-04-17 13:39:37 -07:00
// ----====---- Generate Shadowmaps for Lights ----====----
if ( settings . m_cShadowBuffers > 0 ) {
GL_PUSH_GROUP_MARKER ( " Generate Shadowmaps " ) ;
2014-04-23 01:43:00 -07:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_GENERATE_SHADOWMAPS , false /*settings.bEnableDeferredLighting*/ ) ;
2013-04-17 13:39:37 -07:00
GLDEBUG ( glViewport ( 0 , 0 , m_viewport . getSize ( ) . x , m_viewport . getSize ( ) . y ) ) ;
GL_POP_GROUP_MARKER ;
}
2012-12-20 22:08:41 +00:00
if ( settings . bEnableDeferredLighting ) {
2013-04-17 13:39:37 -07:00
2012-08-15 21:26:06 +00:00
// ----====---- Opaque Geometry, Deferred rendering Pass 1 ----====----
2013-04-17 13:39:37 -07:00
GL_PUSH_GROUP_MARKER ( " Deferred Lighting - Pass 1 (Opaque) " ) ;
2012-08-15 21:26:06 +00:00
// Set render target
2012-09-13 20:09:19 +00:00
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , compositeFramebuffer ) ) ;
2013-05-13 13:16:25 -07:00
# if GL_EXT_discard_framebuffer
GLenum attachments [ 2 ] = { GL_DEPTH_ATTACHMENT , GL_COLOR_ATTACHMENT0 } ;
GLDEBUG ( glDiscardFramebufferEXT ( GL_FRAMEBUFFER , 2 , attachments ) ) ;
# endif
// Enable z-buffer write
GLDEBUG ( glDepthMask ( GL_TRUE ) ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glClearColor ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ;
GLDEBUG ( glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ) ;
2012-08-15 21:26:06 +00:00
// Enable backface culling
2012-09-13 20:09:19 +00:00
GLDEBUG ( glCullFace ( GL_BACK ) ) ;
GLDEBUG ( glEnable ( GL_CULL_FACE ) ) ;
2012-08-15 21:26:06 +00:00
// Enable z-buffer test
2012-09-13 20:09:19 +00:00
GLDEBUG ( glEnable ( GL_DEPTH_TEST ) ) ;
GLDEBUG ( glDepthFunc ( GL_LEQUAL ) ) ;
GLDEBUG ( glDepthRangef ( 0.0 , 1.0 ) ) ;
2012-08-15 21:26:06 +00:00
// Disable alpha blending
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDisable ( GL_BLEND ) ) ;
2012-08-15 21:26:06 +00:00
// Render the geometry
2014-04-23 01:43:00 -07:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_DEFERRED_GBUFFER , false ) ;
2012-11-15 22:05:25 +00:00
2013-04-17 13:39:37 -07:00
GL_POP_GROUP_MARKER ;
2012-08-15 21:26:06 +00:00
// ----====---- Opaque Geometry, Deferred rendering Pass 2 ----====----
2013-04-17 13:39:37 -07:00
GL_PUSH_GROUP_MARKER ( " Deferred Lighting - Pass 2 (Opaque) " ) ;
2012-08-15 21:26:06 +00:00
// Set render target
2012-09-13 20:09:19 +00:00
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , lightAccumulationBuffer ) ) ;
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , compositeDepthTexture , 0 ) ) ;
2014-04-29 00:30:14 -07:00
GLDEBUG ( glViewport ( 0 , 0 , m_viewport . getSize ( ) . x * m_downsample . x , m_viewport . getSize ( ) . y * m_downsample . y ) ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glClearColor ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ;
GLDEBUG ( glClear ( GL_COLOR_BUFFER_BIT ) ) ;
2012-08-15 21:26:06 +00:00
// Enable additive blending
2012-09-13 20:09:19 +00:00
GLDEBUG ( glEnable ( GL_BLEND ) ) ;
GLDEBUG ( glBlendFunc ( GL_ONE , GL_ONE ) ) ;
2012-08-15 21:26:06 +00:00
// Disable z-buffer write
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDepthMask ( GL_FALSE ) ) ;
2012-08-15 21:26:06 +00:00
// Set source to buffers from pass 1
2014-06-01 00:58:28 -07:00
m_pContext - > getTextureManager ( ) - > selectTexture ( GL_TEXTURE_2D , 6 , compositeColorTexture ) ;
m_pContext - > getTextureManager ( ) - > selectTexture ( GL_TEXTURE_2D , 7 , compositeDepthTexture ) ;
2012-08-15 21:26:06 +00:00
// Render the geometry
2012-11-22 09:02:25 +00:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_DEFERRED_LIGHTS , false ) ;
2012-09-11 08:15:05 +00:00
2013-04-17 13:39:37 -07:00
GL_POP_GROUP_MARKER ;
2012-08-15 21:26:06 +00:00
// ----====---- Opaque Geometry, Deferred rendering Pass 3 ----====----
2013-04-17 13:39:37 -07:00
GL_PUSH_GROUP_MARKER ( " Deferred Lighting - Pass 3 (Opaque) " ) ;
2012-08-15 21:26:06 +00:00
// Set render target
2012-09-13 20:09:19 +00:00
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , compositeFramebuffer ) ) ;
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , compositeDepthTexture , 0 ) ) ;
2012-08-15 21:26:06 +00:00
// Disable alpha blending
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDisable ( GL_BLEND ) ) ;
2012-08-15 21:26:06 +00:00
2012-09-13 20:09:19 +00:00
GLDEBUG ( glClearColor ( 0.0f , 0.0f , 0.0f , 1.0f ) ) ;
GLDEBUG ( glClear ( GL_COLOR_BUFFER_BIT ) ) ;
2012-08-15 21:26:06 +00:00
// Set source to buffers from pass 2
2014-06-01 00:58:28 -07:00
m_pContext - > getTextureManager ( ) - > selectTexture ( GL_TEXTURE_2D , 6 , lightAccumulationTexture ) ;
2012-08-15 21:26:06 +00:00
// Enable backface culling
2012-09-13 20:09:19 +00:00
GLDEBUG ( glCullFace ( GL_BACK ) ) ;
GLDEBUG ( glEnable ( GL_CULL_FACE ) ) ;
2012-08-15 21:26:06 +00:00
// Enable z-buffer test
2012-09-13 20:09:19 +00:00
GLDEBUG ( glEnable ( GL_DEPTH_TEST ) ) ;
GLDEBUG ( glDepthFunc ( GL_LEQUAL ) ) ;
GLDEBUG ( glDepthRangef ( 0.0 , 1.0 ) ) ;
2012-08-15 21:26:06 +00:00
// Enable z-buffer write
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDepthMask ( GL_TRUE ) ) ;
2012-08-15 21:26:06 +00:00
// Render the geometry
2012-11-17 05:20:26 +00:00
// TODO: At this point, we only want to render octree nodes that produced fragments during the 1st pass into the GBuffer
2012-11-17 07:57:28 +00:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_DEFERRED_OPAQUE , false ) ;
2012-08-15 21:26:06 +00:00
// Deactivate source buffer texture units
2014-06-01 00:58:28 -07:00
m_pContext - > getTextureManager ( ) - > selectTexture ( GL_TEXTURE_2D , 6 , 0 ) ;
m_pContext - > getTextureManager ( ) - > selectTexture ( GL_TEXTURE_2D , 7 , 0 ) ;
2013-04-17 13:39:37 -07:00
GL_POP_GROUP_MARKER ;
2012-08-15 21:26:06 +00:00
} else {
// ----====---- Opaque Geometry, Forward Rendering ----====----
2013-04-17 13:39:37 -07:00
GL_PUSH_GROUP_MARKER ( " Forward Rendering - Opaque " ) ;
2012-08-15 21:26:06 +00:00
// Set render target
2012-09-13 20:09:19 +00:00
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , compositeFramebuffer ) ) ;
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , compositeDepthTexture , 0 ) ) ;
2014-04-29 00:30:14 -07:00
GLDEBUG ( glViewport ( 0 , 0 , m_viewport . getSize ( ) . x * m_downsample . x , m_viewport . getSize ( ) . y * m_downsample . y ) ) ;
2012-08-15 21:26:06 +00:00
// Disable alpha blending
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDisable ( GL_BLEND ) ) ;
2012-08-15 21:26:06 +00:00
2012-09-13 20:09:19 +00:00
GLDEBUG ( glClearColor ( 0.0f , 0.0f , 0.0f , 1.0f ) ) ;
2013-05-13 13:16:25 -07:00
// Enable z-buffer write
GLDEBUG ( glDepthMask ( GL_TRUE ) ) ;
2012-10-03 19:29:37 +00:00
2012-08-15 21:26:06 +00:00
2013-05-13 13:16:25 -07:00
# if GL_EXT_discard_framebuffer
GLenum attachments [ 2 ] = { GL_DEPTH_ATTACHMENT , GL_COLOR_ATTACHMENT0 } ;
GLDEBUG ( glDiscardFramebufferEXT ( GL_FRAMEBUFFER , 2 , attachments ) ) ;
# endif
2014-05-31 23:46:55 -07:00
GLDEBUG ( glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ) ;
2012-08-15 21:26:06 +00:00
// Enable backface culling
2012-09-13 20:09:19 +00:00
GLDEBUG ( glCullFace ( GL_BACK ) ) ;
GLDEBUG ( glEnable ( GL_CULL_FACE ) ) ;
2012-08-15 21:26:06 +00:00
2013-05-13 13:16:25 -07:00
2012-08-15 21:26:06 +00:00
// Enable z-buffer test
2012-09-13 20:09:19 +00:00
GLDEBUG ( glEnable ( GL_DEPTH_TEST ) ) ;
GLDEBUG ( glDepthFunc ( GL_LEQUAL ) ) ;
GLDEBUG ( glDepthRangef ( 0.0 , 1.0 ) ) ;
2012-08-15 21:26:06 +00:00
// Render the geometry
2014-04-23 01:43:00 -07:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_FORWARD_OPAQUE , false ) ;
2013-04-17 13:39:37 -07:00
GL_POP_GROUP_MARKER ;
2012-08-15 21:26:06 +00:00
}
2012-10-10 22:09:28 +00:00
// ----====---- Sky Box ----====----
2012-08-15 21:26:06 +00:00
2013-04-17 13:39:37 -07:00
GL_PUSH_GROUP_MARKER ( " Sky Box " ) ;
2012-08-15 21:26:06 +00:00
// Set render target
2012-09-13 20:09:19 +00:00
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , compositeFramebuffer ) ) ;
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , compositeDepthTexture , 0 ) ) ;
2012-08-15 21:26:06 +00:00
// Disable backface culling
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDisable ( GL_CULL_FACE ) ) ;
2012-08-15 21:26:06 +00:00
// Disable z-buffer write
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDepthMask ( GL_FALSE ) ) ;
2012-08-15 21:26:06 +00:00
// Enable z-buffer test
2012-09-13 20:09:19 +00:00
GLDEBUG ( glEnable ( GL_DEPTH_TEST ) ) ;
GLDEBUG ( glDepthFunc ( GL_LEQUAL ) ) ;
GLDEBUG ( glDepthRangef ( 0.0 , 1.0 ) ) ;
2012-08-15 21:26:06 +00:00
2014-11-26 22:24:35 -08:00
if ( ! m_pSkyBoxTexture & & m_skyBox . length ( ) ) {
m_pSkyBoxTexture = getContext ( ) . getTextureManager ( ) - > getTextureCube ( m_skyBox . c_str ( ) ) ;
2012-10-10 22:09:28 +00:00
}
if ( m_pSkyBoxTexture ) {
2014-06-25 00:45:00 -07:00
getContext ( ) . getShaderManager ( ) - > selectShader ( " sky_box " , * this , std : : vector < KRPointLight * > ( ) , std : : vector < KRDirectionalLight * > ( ) , std : : vector < KRSpotLight * > ( ) , 0 , m_viewport , KRMat4 ( ) , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , KRNode : : RENDER_PASS_FORWARD_OPAQUE , KRVector3 : : Zero ( ) , 0.0f , KRVector4 : : Zero ( ) ) ;
2012-11-15 23:20:59 +00:00
2014-04-11 01:15:40 -07:00
getContext ( ) . getTextureManager ( ) - > selectTexture ( 0 , m_pSkyBoxTexture , 0.0f , KRTexture : : TEXTURE_USAGE_SKY_CUBE ) ;
2012-10-10 22:09:28 +00:00
// Render a full screen quad
2014-05-27 22:51:52 -07:00
m_pContext - > getMeshManager ( ) - > bindVBO ( & getContext ( ) . getMeshManager ( ) - > KRENGINE_VBO_DATA_2D_SQUARE_VERTICES , 1.0f ) ;
2012-10-10 22:09:28 +00:00
GLDEBUG ( glDrawArrays ( GL_TRIANGLE_STRIP , 0 , 4 ) ) ;
}
2013-04-17 13:39:37 -07:00
GL_POP_GROUP_MARKER ;
2012-10-10 22:09:28 +00:00
// ----====---- Transparent Geometry, Forward Rendering ----====----
2013-04-17 13:39:37 -07:00
GL_PUSH_GROUP_MARKER ( " Forward Rendering - Transparent " ) ;
2012-10-10 22:09:28 +00:00
// Note: These parameters have already been set up by the skybox render above
//
// // Set render target
// GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
// GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
//
// // Disable backface culling
// GLDEBUG(glDisable(GL_CULL_FACE));
2014-04-12 23:42:26 -07:00
//
// Enable backface culling
GLDEBUG ( glCullFace ( GL_BACK ) ) ;
GLDEBUG ( glEnable ( GL_CULL_FACE ) ) ;
2013-02-08 17:28:17 -08:00
// Disable z-buffer write
GLDEBUG ( glDepthMask ( GL_FALSE ) ) ;
2012-10-10 22:09:28 +00:00
//
// // Enable z-buffer test
// GLDEBUG(glEnable(GL_DEPTH_TEST));
// GLDEBUG(glDepthFunc(GL_LEQUAL));
// GLDEBUG(glDepthRangef(0.0, 1.0));
2012-08-15 21:26:06 +00:00
// Enable alpha blending
2012-09-13 20:09:19 +00:00
GLDEBUG ( glEnable ( GL_BLEND ) ) ;
2013-05-02 13:32:36 -07:00
GLDEBUG ( glBlendFunc ( GL_ONE , GL_ONE_MINUS_SRC_ALPHA ) ) ;
2012-08-15 21:26:06 +00:00
// Render all transparent geometry
2012-11-17 07:57:28 +00:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_FORWARD_TRANSPARENT , false ) ;
2012-08-15 21:26:06 +00:00
2013-04-17 13:39:37 -07:00
GL_POP_GROUP_MARKER ;
2013-01-17 19:27:17 -08:00
// ----====---- Particle Occlusion Tests ----====----
2013-04-17 13:39:37 -07:00
GL_PUSH_GROUP_MARKER ( " Particle Occlusion Tests " ) ;
2013-01-17 19:27:17 -08:00
// Set render target
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , compositeFramebuffer ) ) ;
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , compositeDepthTexture , 0 ) ) ;
// Disable backface culling
GLDEBUG ( glDisable ( GL_CULL_FACE ) ) ;
// Disable z-buffer write
GLDEBUG ( glDepthMask ( GL_FALSE ) ) ;
// Enable z-buffer test
GLDEBUG ( glEnable ( GL_DEPTH_TEST ) ) ;
GLDEBUG ( glDepthFunc ( GL_LEQUAL ) ) ;
GLDEBUG ( glDepthRangef ( 0.0 , 1.0 ) ) ;
// Enable additive blending
GLDEBUG ( glEnable ( GL_BLEND ) ) ;
GLDEBUG ( glBlendFunc ( GL_ONE , GL_ONE ) ) ;
// ----====---- Perform Occlusion Tests ----====----
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , RENDER_PASS_PARTICLE_OCCLUSION , false ) ;
2012-09-05 18:14:08 +00:00
2013-04-17 13:39:37 -07:00
GL_POP_GROUP_MARKER ;
2012-08-15 21:26:06 +00:00
// ----====---- Flares ----====----
2013-04-17 13:39:37 -07:00
GL_PUSH_GROUP_MARKER ( " Additive Particles " ) ;
2012-08-15 21:26:06 +00:00
// Set render target
2012-09-13 20:09:19 +00:00
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , compositeFramebuffer ) ) ;
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , compositeDepthTexture , 0 ) ) ;
2012-08-15 21:26:06 +00:00
// Disable backface culling
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDisable ( GL_CULL_FACE ) ) ;
2012-08-15 21:26:06 +00:00
// Disable z-buffer write
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDepthMask ( GL_FALSE ) ) ;
2012-08-15 21:26:06 +00:00
// Disable z-buffer test
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDisable ( GL_DEPTH_TEST ) ) ;
GLDEBUG ( glDepthRangef ( 0.0 , 1.0 ) ) ;
2012-08-15 21:26:06 +00:00
// Enable additive blending
2012-09-13 20:09:19 +00:00
GLDEBUG ( glEnable ( GL_BLEND ) ) ;
GLDEBUG ( glBlendFunc ( GL_ONE , GL_ONE ) ) ;
2012-08-15 21:26:06 +00:00
2012-08-24 00:06:38 +00:00
// Render all flares
2012-11-17 07:57:28 +00:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_ADDITIVE_PARTICLES , false ) ;
2012-11-02 20:50:45 +00:00
2013-04-17 13:39:37 -07:00
GL_POP_GROUP_MARKER ;
2012-11-09 20:55:23 +00:00
// ----====---- Volumetric Lighting ----====----
2012-12-20 22:08:41 +00:00
if ( settings . volumetric_environment_enable ) {
2013-04-17 13:39:37 -07:00
GL_PUSH_GROUP_MARKER ( " Volumetric Lighting " ) ;
2012-11-15 22:05:25 +00:00
KRViewport volumetricLightingViewport = KRViewport ( KRVector2 ( volumetricBufferWidth , volumetricBufferHeight ) , m_viewport . getViewMatrix ( ) , m_viewport . getProjectionMatrix ( ) ) ;
2012-11-09 20:55:23 +00:00
2012-12-20 22:08:41 +00:00
if ( settings . volumetric_environment_downsample ! = 0 ) {
2012-11-10 00:51:03 +00:00
// Set render target
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , volumetricLightAccumulationBuffer ) ) ;
GLDEBUG ( glClearColor ( 0.0f , 0.0f , 0.0f , 0.0f ) ) ;
GLDEBUG ( glClear ( GL_COLOR_BUFFER_BIT ) ) ;
2012-11-09 20:55:23 +00:00
2012-11-10 00:51:03 +00:00
// Disable z-buffer test
GLDEBUG ( glDisable ( GL_DEPTH_TEST ) ) ;
2014-06-01 00:58:28 -07:00
m_pContext - > getTextureManager ( ) - > selectTexture ( GL_TEXTURE_2D , 0 , compositeDepthTexture ) ;
2012-11-15 22:05:25 +00:00
2012-11-22 09:02:25 +00:00
GLDEBUG ( glViewport ( 0 , 0 , volumetricLightingViewport . getSize ( ) . x , volumetricLightingViewport . getSize ( ) . y ) ) ;
2012-11-10 00:51:03 +00:00
} else {
2012-11-09 20:55:23 +00:00
// Enable z-buffer test
GLDEBUG ( glEnable ( GL_DEPTH_TEST ) ) ;
GLDEBUG ( glDepthFunc ( GL_LEQUAL ) ) ;
GLDEBUG ( glDepthRangef ( 0.0 , 1.0 ) ) ;
2012-11-10 00:51:03 +00:00
}
2012-11-17 07:57:28 +00:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , volumetricLightingViewport , KRNode : : RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE , false ) ;
2012-11-09 20:55:23 +00:00
2012-12-20 22:08:41 +00:00
if ( settings . volumetric_environment_downsample ! = 0 ) {
2012-11-10 00:51:03 +00:00
// Set render target
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , compositeFramebuffer ) ) ;
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , compositeDepthTexture , 0 ) ) ;
2012-11-22 09:02:25 +00:00
GLDEBUG ( glViewport ( 0 , 0 , m_viewport . getSize ( ) . x , m_viewport . getSize ( ) . y ) ) ;
2012-11-10 00:51:03 +00:00
}
2013-04-17 13:39:37 -07:00
GL_POP_GROUP_MARKER ;
2012-11-09 20:55:23 +00:00
}
2012-08-15 21:26:06 +00:00
2012-09-05 18:14:08 +00:00
// ----====---- Debug Overlay ----====----
2013-04-17 13:39:37 -07:00
GL_PUSH_GROUP_MARKER ( " Debug Overlays " ) ;
2013-05-01 12:32:16 -07:00
if ( settings . debug_display = = KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_OCTREE ) {
2012-09-05 18:14:08 +00:00
// Enable z-buffer test
2012-09-13 20:09:19 +00:00
GLDEBUG ( glEnable ( GL_DEPTH_TEST ) ) ;
GLDEBUG ( glDepthRangef ( 0.0 , 1.0 ) ) ;
2012-09-05 18:14:08 +00:00
2012-09-11 03:06:35 +00:00
2012-09-05 18:14:08 +00:00
// Enable backface culling
2012-09-13 20:09:19 +00:00
GLDEBUG ( glCullFace ( GL_BACK ) ) ;
GLDEBUG ( glEnable ( GL_CULL_FACE ) ) ;
2012-09-05 18:14:08 +00:00
2012-10-27 00:50:17 +00:00
// Enable additive blending
GLDEBUG ( glEnable ( GL_BLEND ) ) ;
GLDEBUG ( glBlendFunc ( GL_ONE , GL_ONE ) ) ;
2012-09-11 03:06:35 +00:00
2013-04-25 16:21:28 -07:00
KRShader * pVisShader = getContext ( ) . getShaderManager ( ) - > getShader ( " visualize_overlay " , this , std : : vector < KRPointLight * > ( ) , std : : vector < KRDirectionalLight * > ( ) , std : : vector < KRSpotLight * > ( ) , 0 , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , KRNode : : RENDER_PASS_FORWARD_TRANSPARENT ) ;
2012-09-05 18:14:08 +00:00
2014-05-27 22:51:52 -07:00
m_pContext - > getMeshManager ( ) - > bindVBO ( & getContext ( ) . getMeshManager ( ) - > KRENGINE_VBO_DATA_3D_CUBE_VERTICES , 1.0f ) ;
2013-04-25 17:23:36 -07:00
for ( unordered_map < KRAABB , int > : : iterator itr = m_viewport . getVisibleBounds ( ) . begin ( ) ; itr ! = m_viewport . getVisibleBounds ( ) . end ( ) ; itr + + ) {
2012-09-05 18:14:08 +00:00
KRMat4 matModel = KRMat4 ( ) ;
2013-04-24 12:48:55 -07:00
matModel . scale ( ( * itr ) . first . size ( ) * 0.5f ) ;
2012-11-17 05:20:26 +00:00
matModel . translate ( ( * itr ) . first . center ( ) ) ;
2014-06-25 00:45:00 -07:00
if ( getContext ( ) . getShaderManager ( ) - > selectShader ( * this , pVisShader , m_viewport , matModel , std : : vector < KRPointLight * > ( ) , std : : vector < KRDirectionalLight * > ( ) , std : : vector < KRSpotLight * > ( ) , 0 , KRNode : : RENDER_PASS_FORWARD_TRANSPARENT , KRVector3 : : Zero ( ) , 0.0f , KRVector4 : : Zero ( ) ) ) {
2012-09-20 09:32:20 +00:00
GLDEBUG ( glDrawArrays ( GL_TRIANGLE_STRIP , 0 , 14 ) ) ;
}
2012-09-05 18:14:08 +00:00
}
}
2012-08-30 22:37:44 +00:00
2012-09-05 18:14:08 +00:00
// Re-enable z-buffer write
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDepthMask ( GL_TRUE ) ) ;
2012-09-11 03:06:35 +00:00
2013-04-17 13:39:37 -07:00
GL_POP_GROUP_MARKER ;
2012-08-15 21:26:06 +00:00
2014-05-13 21:56:06 -07:00
// fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i/%i Kbyte (active/total) Shader Handles: %i Visible Bounds: %i Max Texture LOD: %i\n", (int)m_pContext->getMeshManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getActiveMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024, (int)m_pContext->getShaderManager()->getShaderHandlesUsed(), (int)m_visibleBounds.size(), m_pContext->getTextureManager()->getLODDimCap());
2013-04-17 13:39:37 -07:00
GL_PUSH_GROUP_MARKER ( " Post Processing " ) ;
2012-12-28 03:20:06 +00:00
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , defaultFBO ) ) ;
renderPost ( ) ;
2014-05-13 21:56:06 -07:00
m_pContext - > getMeshManager ( ) - > unbindVBO ( ) ;
2013-04-17 13:39:37 -07:00
GL_POP_GROUP_MARKER ;
2013-05-13 13:16:25 -07:00
# if GL_EXT_discard_framebuffer
GLenum attachments [ 2 ] = { GL_DEPTH_ATTACHMENT , GL_COLOR_ATTACHMENT0 } ;
GLDEBUG ( glDiscardFramebufferEXT ( GL_FRAMEBUFFER , 2 , attachments ) ) ;
# endif
2012-08-15 21:26:06 +00:00
}
2013-02-08 17:28:17 -08:00
void KRCamera : : createBuffers ( GLint renderBufferWidth , GLint renderBufferHeight ) {
2013-01-23 12:43:43 -08:00
2014-04-29 00:30:14 -07:00
if ( renderBufferWidth ! = m_backingWidth | | renderBufferHeight ! = m_backingHeight ) {
m_backingWidth = renderBufferWidth ;
m_backingHeight = renderBufferHeight ;
2012-11-14 21:46:30 +00:00
if ( compositeDepthTexture ) {
GLDEBUG ( glDeleteTextures ( 1 , & compositeDepthTexture ) ) ;
compositeDepthTexture = 0 ;
}
if ( compositeColorTexture ) {
GLDEBUG ( glDeleteTextures ( 1 , & compositeColorTexture ) ) ;
compositeColorTexture = 0 ;
}
if ( lightAccumulationTexture ) {
GLDEBUG ( glDeleteTextures ( 1 , & lightAccumulationTexture ) ) ;
lightAccumulationTexture = 0 ;
}
if ( compositeFramebuffer ) {
GLDEBUG ( glDeleteFramebuffers ( 1 , & compositeFramebuffer ) ) ;
compositeFramebuffer = 0 ;
}
if ( lightAccumulationBuffer ) {
GLDEBUG ( glDeleteFramebuffers ( 1 , & lightAccumulationBuffer ) ) ;
lightAccumulationBuffer = 0 ;
}
2012-10-17 19:43:15 +00:00
// ===== Create offscreen compositing framebuffer object =====
GLDEBUG ( glGenFramebuffers ( 1 , & compositeFramebuffer ) ) ;
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , compositeFramebuffer ) ) ;
// ----- Create texture color buffer for compositeFramebuffer -----
GLDEBUG ( glGenTextures ( 1 , & compositeColorTexture ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , compositeColorTexture ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ) ) ; // This is necessary for non-power-of-two textures
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ) ) ; // This is necessary for non-power-of-two textures
2014-04-29 00:30:14 -07:00
GLDEBUG ( glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , m_backingWidth , m_backingHeight , 0 , GL_BGRA , GL_UNSIGNED_BYTE , NULL ) ) ;
2012-10-17 19:43:15 +00:00
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , compositeColorTexture , 0 ) ) ;
// ----- Create Depth Texture for compositeFramebuffer -----
GLDEBUG ( glGenTextures ( 1 , & compositeDepthTexture ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , compositeDepthTexture ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ) ) ; // This is necessary for non-power-of-two textures
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ) ) ; // This is necessary for non-power-of-two textures
2014-04-29 00:30:14 -07:00
GLDEBUG ( glTexImage2D ( GL_TEXTURE_2D , 0 , GL_DEPTH_COMPONENT , m_backingWidth , m_backingHeight , 0 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT , NULL ) ) ;
//GLDEBUG(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, m_backingWidth, m_backingHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL));
//GLDEBUG(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, m_backingWidth, m_backingHeight));
2012-10-17 19:43:15 +00:00
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_TEXTURE_2D , compositeDepthTexture , 0 ) ) ;
// ===== Create offscreen compositing framebuffer object =====
GLDEBUG ( glGenFramebuffers ( 1 , & lightAccumulationBuffer ) ) ;
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , lightAccumulationBuffer ) ) ;
// ----- Create texture color buffer for compositeFramebuffer -----
GLDEBUG ( glGenTextures ( 1 , & lightAccumulationTexture ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , lightAccumulationTexture ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ) ) ; // This is necessary for non-power-of-two textures
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ) ) ; // This is necessary for non-power-of-two textures
2014-04-29 00:30:14 -07:00
GLDEBUG ( glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , m_backingWidth , m_backingHeight , 0 , GL_BGRA , GL_UNSIGNED_BYTE , NULL ) ) ;
2012-10-17 19:43:15 +00:00
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , lightAccumulationTexture , 0 ) ) ;
2012-11-14 21:46:30 +00:00
}
2013-02-06 11:59:24 -08:00
2012-11-14 21:46:30 +00:00
int targetVolumetricBufferWidth = 0 ;
int targetVolumetricBufferHeight = 0 ;
2012-12-20 22:08:41 +00:00
if ( settings . volumetric_environment_enable & & settings . volumetric_environment_downsample ! = 0 ) {
targetVolumetricBufferWidth = renderBufferWidth > > settings . volumetric_environment_downsample ;
targetVolumetricBufferHeight = renderBufferHeight > > settings . volumetric_environment_downsample ;
2012-11-14 21:46:30 +00:00
}
if ( targetVolumetricBufferWidth ! = volumetricBufferWidth | | targetVolumetricBufferHeight ! = volumetricBufferHeight ) {
volumetricBufferWidth = targetVolumetricBufferWidth ;
volumetricBufferHeight = targetVolumetricBufferHeight ;
2012-11-09 20:55:23 +00:00
2012-11-14 21:46:30 +00:00
if ( volumetricLightAccumulationTexture ) {
GLDEBUG ( glDeleteTextures ( 1 , & volumetricLightAccumulationTexture ) ) ;
volumetricLightAccumulationTexture = 0 ;
}
2012-11-09 20:55:23 +00:00
2012-11-14 21:46:30 +00:00
if ( volumetricLightAccumulationBuffer ) {
GLDEBUG ( glDeleteFramebuffers ( 1 , & volumetricLightAccumulationBuffer ) ) ;
volumetricLightAccumulationBuffer = 0 ;
}
2012-11-09 20:55:23 +00:00
2013-02-06 11:59:24 -08:00
2012-11-14 21:46:30 +00:00
if ( targetVolumetricBufferWidth ! = 0 & & targetVolumetricBufferHeight ! = 0 ) {
// ===== Create offscreen compositing framebuffer object for volumetric lighting =====
GLDEBUG ( glGenFramebuffers ( 1 , & volumetricLightAccumulationBuffer ) ) ;
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , volumetricLightAccumulationBuffer ) ) ;
// ----- Create texture color buffer for compositeFramebuffer for volumetric lighting -----
GLDEBUG ( glGenTextures ( 1 , & volumetricLightAccumulationTexture ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , volumetricLightAccumulationTexture ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ) ;
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ) ) ; // This is necessary for non-power-of-two textures
GLDEBUG ( glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ) ) ; // This is necessary for non-power-of-two textures
GLDEBUG ( glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , volumetricBufferWidth , volumetricBufferHeight , 0 , GL_BGRA , GL_UNSIGNED_BYTE , NULL ) ) ;
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , volumetricLightAccumulationTexture , 0 ) ) ;
}
2012-10-17 19:43:15 +00:00
}
2012-08-15 21:26:06 +00:00
}
void KRCamera : : destroyBuffers ( )
{
if ( compositeDepthTexture ) {
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDeleteTextures ( 1 , & compositeDepthTexture ) ) ;
2012-08-15 21:26:06 +00:00
compositeDepthTexture = 0 ;
}
if ( compositeColorTexture ) {
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDeleteTextures ( 1 , & compositeColorTexture ) ) ;
2012-08-15 21:26:06 +00:00
compositeColorTexture = 0 ;
}
if ( lightAccumulationTexture ) {
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDeleteTextures ( 1 , & lightAccumulationTexture ) ) ;
2012-08-15 21:26:06 +00:00
lightAccumulationTexture = 0 ;
}
if ( compositeFramebuffer ) {
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDeleteFramebuffers ( 1 , & compositeFramebuffer ) ) ;
2012-08-15 21:26:06 +00:00
compositeFramebuffer = 0 ;
}
if ( lightAccumulationBuffer ) {
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDeleteFramebuffers ( 1 , & lightAccumulationBuffer ) ) ;
2012-08-15 21:26:06 +00:00
lightAccumulationBuffer = 0 ;
}
2012-11-09 20:55:23 +00:00
if ( volumetricLightAccumulationTexture ) {
GLDEBUG ( glDeleteTextures ( 1 , & volumetricLightAccumulationTexture ) ) ;
volumetricLightAccumulationTexture = 0 ;
}
if ( volumetricLightAccumulationBuffer ) {
GLDEBUG ( glDeleteFramebuffers ( 1 , & volumetricLightAccumulationBuffer ) ) ;
volumetricLightAccumulationBuffer = 0 ;
}
2012-08-15 21:26:06 +00:00
}
2012-08-23 16:55:46 +00:00
void KRCamera : : renderPost ( )
2012-08-15 21:26:06 +00:00
{
// Disable alpha blending
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDisable ( GL_BLEND ) ) ;
2012-08-15 21:26:06 +00:00
2012-09-19 20:26:30 +00:00
2012-08-15 21:26:06 +00:00
static const GLfloat squareVerticesShadow [ 3 ] [ 8 ] = { {
- 1.0f , - 1.0f ,
- 0.60f , - 1.0f ,
- 1.0f , - 0.60f ,
- 0.60f , - 0.60f ,
} , {
- 0.50f , - 1.0f ,
- 0.10f , - 1.0f ,
- 0.50f , - 0.60f ,
- 0.10f , - 0.60f ,
} , {
0.00f , - 1.0f ,
0.40f , - 1.0f ,
0.00f , - 0.60f ,
0.40f , - 0.60f ,
} } ;
2012-09-19 20:26:30 +00:00
2014-04-29 00:30:14 -07:00
GLDEBUG ( glViewport ( 0 , 0 , m_viewport . getSize ( ) . x , m_viewport . getSize ( ) . y ) ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDisable ( GL_DEPTH_TEST ) ) ;
2013-04-25 16:21:28 -07:00
KRShader * postShader = m_pContext - > getShaderManager ( ) - > getShader ( " PostShader " , this , std : : vector < KRPointLight * > ( ) , std : : vector < KRDirectionalLight * > ( ) , std : : vector < KRSpotLight * > ( ) , 0 , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , KRNode : : RENDER_PASS_FORWARD_TRANSPARENT ) ;
2013-12-05 01:09:31 -08:00
KRVector3 rim_color ;
2014-06-25 00:45:00 -07:00
getContext ( ) . getShaderManager ( ) - > selectShader ( * this , postShader , m_viewport , KRMat4 ( ) , std : : vector < KRPointLight * > ( ) , std : : vector < KRDirectionalLight * > ( ) , std : : vector < KRSpotLight * > ( ) , 0 , KRNode : : RENDER_PASS_FORWARD_TRANSPARENT , rim_color , 0.0f , m_fade_color ) ;
2012-08-15 21:26:06 +00:00
2014-06-01 00:58:28 -07:00
m_pContext - > getTextureManager ( ) - > selectTexture ( GL_TEXTURE_2D , 0 , compositeDepthTexture ) ;
m_pContext - > getTextureManager ( ) - > selectTexture ( GL_TEXTURE_2D , 1 , compositeColorTexture ) ;
2012-12-20 22:08:41 +00:00
if ( settings . volumetric_environment_enable ) {
2014-06-01 00:58:28 -07:00
m_pContext - > getTextureManager ( ) - > selectTexture ( GL_TEXTURE_2D , 2 , volumetricLightAccumulationTexture ) ;
2012-11-14 21:46:30 +00:00
}
2012-08-15 21:26:06 +00:00
// Update attribute values.
2014-05-27 22:51:52 -07:00
m_pContext - > getMeshManager ( ) - > bindVBO ( & getContext ( ) . getMeshManager ( ) - > KRENGINE_VBO_DATA_2D_SQUARE_VERTICES , 1.0f ) ;
2012-08-15 21:26:06 +00:00
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDrawArrays ( GL_TRIANGLE_STRIP , 0 , 4 ) ) ;
2012-08-15 21:26:06 +00:00
2014-06-01 00:58:28 -07:00
m_pContext - > getTextureManager ( ) - > selectTexture ( GL_TEXTURE_2D , 0 , 0 ) ;
m_pContext - > getTextureManager ( ) - > selectTexture ( GL_TEXTURE_2D , 1 , 0 ) ;
2012-08-15 21:26:06 +00:00
2012-11-15 22:05:25 +00:00
// if(bShowShadowBuffer) {
// KRShader *blitShader = m_pContext->getShaderManager()->getShader("simple_blit", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
//
// for(int iShadow=0; iShadow < m_cShadowBuffers; iShadow++) {
// KRMat4 viewMatrix = KRMat4();
// viewMatrix.scale(0.20, 0.20, 0.20);
// viewMatrix.translate(-0.70, 0.70 - 0.45 * iShadow, 0.0);
2012-11-15 23:20:59 +00:00
// getContext().getShaderManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, KRMat4()), shadowViewports, KRMat4(), KRVector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
2012-11-17 00:15:52 +00:00
// m_pContext->getTextureManager()->selectTexture(1, NULL);
2014-05-15 23:33:01 -07:00
// m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES);
2013-04-24 15:51:57 -07:00
// m_pContext->getTextureManager()->_setActiveTexture(0);
2012-11-15 22:05:25 +00:00
// GLDEBUG(glBindTexture(GL_TEXTURE_2D, shadowDepthTexture[iShadow]));
//#if GL_EXT_shadow_samplers
// GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_EXT, GL_NONE)); // TODO - Detect GL_EXT_shadow_samplers and only activate if available
//#endif
// GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
//#if GL_EXT_shadow_samplers
// GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_EXT, GL_COMPARE_REF_TO_TEXTURE_EXT)); // TODO - Detect GL_EXT_shadow_samplers and only activate if available
//#endif
// }
//
2012-11-17 00:15:52 +00:00
// m_pContext->getTextureManager()->selectTexture(0, NULL);
2013-04-24 15:51:57 -07:00
// m_pContext->getTextureManager()->_setActiveTexture(0);
2012-11-15 22:05:25 +00:00
// GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
// }
2012-08-15 21:26:06 +00:00
2012-12-20 22:08:41 +00:00
const char * szText = settings . m_debug_text . c_str ( ) ;
2013-03-21 13:21:04 -07:00
2013-03-22 18:16:44 -07:00
std : : string debug_text ;
if ( settings . debug_display ! = KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_NONE ) {
debug_text = getDebugText ( ) ; ;
if ( debug_text . length ( ) > 0 ) {
szText = debug_text . c_str ( ) ;
}
2013-03-21 13:21:04 -07:00
}
2013-03-21 17:32:26 -07:00
2013-03-21 13:21:04 -07:00
if ( * szText ) {
int row_count = 1 ;
2013-03-21 17:32:26 -07:00
const int MAX_TABS = 5 ;
const int TAB_EXTRA = 2 ;
int tab_cols [ MAX_TABS ] = { 0 , 0 , 0 , 0 , 0 } ;
2013-03-21 13:21:04 -07:00
int iCol = 0 ;
2013-03-21 17:32:26 -07:00
int iTab = 0 ;
2012-08-15 21:26:06 +00:00
const char * pChar = szText ;
2013-03-21 13:21:04 -07:00
while ( * pChar ) {
char c = * pChar + + ;
if ( c = = ' \n ' ) {
row_count + + ;
iCol = 0 ;
2013-03-21 17:32:26 -07:00
iTab = 0 ;
} else if ( c = = ' \t ' ) {
iCol = 0 ;
iTab + + ;
2013-03-21 13:21:04 -07:00
} else {
iCol + + ;
2013-03-21 17:32:26 -07:00
if ( iCol > tab_cols [ iTab ] ) tab_cols [ iTab ] = iCol ;
2013-03-21 13:21:04 -07:00
}
}
2013-03-21 17:32:26 -07:00
iCol = 0 ;
for ( iTab = 0 ; iTab < MAX_TABS ; iTab + + ) {
iCol + = tab_cols [ iTab ] + TAB_EXTRA ;
tab_cols [ iTab ] = iCol ;
}
2013-03-21 13:21:04 -07:00
const int DEBUG_TEXT_COLUMNS = 256 ;
const int DEBUG_TEXT_ROWS = 128 ;
2013-11-09 16:08:08 -08:00
if ( m_debug_text_vertices . getSize ( ) = = 0 ) {
m_debug_text_vertices . expand ( sizeof ( DebugTextVertexData ) * DEBUG_TEXT_COLUMNS * DEBUG_TEXT_ROWS * 6 ) ;
2013-03-21 13:21:04 -07:00
}
int vertex_count = 0 ;
2013-11-09 16:08:08 -08:00
m_debug_text_vertices . lock ( ) ;
DebugTextVertexData * vertex_data = ( DebugTextVertexData * ) m_debug_text_vertices . getStart ( ) ;
2013-03-21 13:21:04 -07:00
pChar = szText ;
2013-03-21 17:32:26 -07:00
float dScaleX = 2.0 / ( 1024 / 16 ) ;
float dScaleY = 2.0 / ( 768 / 16 ) ;
2012-10-20 02:15:48 +00:00
float dTexScale = 1.0 / 16.0 ;
2013-03-21 17:32:26 -07:00
int iRow = row_count - 1 ; iCol = 0 , iTab = 0 ;
2012-08-15 21:26:06 +00:00
while ( * pChar ) {
2013-03-21 13:21:04 -07:00
char c = * pChar + + ;
2013-03-21 17:32:26 -07:00
if ( c = = ' \n ' ) {
2013-03-21 13:21:04 -07:00
iCol = 0 ;
2013-03-21 17:32:26 -07:00
iTab = 0 ;
2013-03-21 13:21:04 -07:00
iRow - - ;
2013-03-21 17:32:26 -07:00
} else if ( c = = ' \t ' ) {
iCol = tab_cols [ iTab + + ] ;
2013-03-21 13:21:04 -07:00
} else {
if ( iCol < DEBUG_TEXT_COLUMNS & & iRow < DEBUG_TEXT_ROWS ) {
int iChar = c - ' \0 ' ;
int iTexCol = iChar % 16 ;
int iTexRow = 15 - ( iChar - iTexCol ) / 16 ;
KRVector2 top_left_pos = KRVector2 ( - 1.0f + dScaleX * iCol , dScaleY * iRow - 1.0 ) ;
KRVector2 bottom_right_pos = KRVector2 ( - 1.0 + dScaleX * ( iCol + 1 ) , dScaleY * iRow + dScaleY - 1.0 ) ;
top_left_pos + = KRVector2 ( 1.0f / 2048.0f * 0.5f , 1.0f / 1536.0f * 0.5f ) ;
bottom_right_pos + = KRVector2 ( 1.0f / 2048.0f * 0.5f , 1.0f / 1536.0f * 0.5f ) ;
KRVector2 top_left_uv = KRVector2 ( dTexScale * iTexCol , dTexScale * iTexRow ) ;
KRVector2 bottom_right_uv = KRVector2 ( dTexScale * iTexCol + dTexScale , dTexScale * iTexRow + dTexScale ) ;
2013-11-09 16:08:08 -08:00
vertex_data [ vertex_count ] . x = top_left_pos . x ;
vertex_data [ vertex_count ] . y = top_left_pos . y ;
vertex_data [ vertex_count ] . z = 0.0f ;
vertex_data [ vertex_count ] . u = top_left_uv . x ;
vertex_data [ vertex_count ] . v = top_left_uv . y ;
2013-03-21 13:21:04 -07:00
vertex_count + + ;
2013-11-09 16:08:08 -08:00
vertex_data [ vertex_count ] . x = bottom_right_pos . x ;
vertex_data [ vertex_count ] . y = bottom_right_pos . y ;
vertex_data [ vertex_count ] . z = 0.0f ;
vertex_data [ vertex_count ] . u = bottom_right_uv . x ;
vertex_data [ vertex_count ] . v = bottom_right_uv . y ;
2013-03-21 13:21:04 -07:00
vertex_count + + ;
2013-11-09 16:08:08 -08:00
vertex_data [ vertex_count ] . x = top_left_pos . x ;
vertex_data [ vertex_count ] . y = bottom_right_pos . y ;
vertex_data [ vertex_count ] . z = 0.0f ;
vertex_data [ vertex_count ] . u = top_left_uv . x ;
vertex_data [ vertex_count ] . v = bottom_right_uv . y ;
2013-03-21 13:21:04 -07:00
vertex_count + + ;
2013-11-09 16:08:08 -08:00
vertex_data [ vertex_count ] . x = top_left_pos . x ;
vertex_data [ vertex_count ] . y = top_left_pos . y ;
vertex_data [ vertex_count ] . z = 0.0f ;
vertex_data [ vertex_count ] . u = top_left_uv . x ;
vertex_data [ vertex_count ] . v = top_left_uv . y ;
2013-03-21 13:21:04 -07:00
vertex_count + + ;
2013-11-09 16:08:08 -08:00
vertex_data [ vertex_count ] . x = bottom_right_pos . x ;
vertex_data [ vertex_count ] . y = top_left_pos . y ;
vertex_data [ vertex_count ] . z = 0.0f ;
vertex_data [ vertex_count ] . u = bottom_right_uv . x ;
vertex_data [ vertex_count ] . v = top_left_uv . y ;
2013-03-21 13:21:04 -07:00
vertex_count + + ;
2013-11-09 16:08:08 -08:00
vertex_data [ vertex_count ] . x = bottom_right_pos . x ;
vertex_data [ vertex_count ] . y = bottom_right_pos . y ;
vertex_data [ vertex_count ] . z = 0.0f ;
vertex_data [ vertex_count ] . u = bottom_right_uv . x ;
vertex_data [ vertex_count ] . v = bottom_right_uv . y ;
2013-03-21 13:21:04 -07:00
vertex_count + + ;
}
iCol + + ;
}
2012-08-15 21:26:06 +00:00
}
2013-03-21 13:21:04 -07:00
// Disable backface culling
GLDEBUG ( glDisable ( GL_CULL_FACE ) ) ;
// Disable z-buffer write
GLDEBUG ( glDepthMask ( GL_FALSE ) ) ;
// Disable z-buffer test
GLDEBUG ( glDisable ( GL_DEPTH_TEST ) ) ;
// GLDEBUG(glDepthRangef(0.0, 1.0));
// Enable alpha blending
GLDEBUG ( glEnable ( GL_BLEND ) ) ;
2013-05-02 13:32:36 -07:00
GLDEBUG ( glBlendFunc ( GL_ONE , GL_ONE_MINUS_SRC_ALPHA ) ) ;
2013-03-21 13:21:04 -07:00
2013-04-25 16:21:28 -07:00
KRShader * fontShader = m_pContext - > getShaderManager ( ) - > getShader ( " debug_font " , this , std : : vector < KRPointLight * > ( ) , std : : vector < KRDirectionalLight * > ( ) , std : : vector < KRSpotLight * > ( ) , 0 , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , KRNode : : RENDER_PASS_FORWARD_TRANSPARENT ) ;
2014-06-25 00:45:00 -07:00
getContext ( ) . getShaderManager ( ) - > selectShader ( * this , fontShader , m_viewport , KRMat4 ( ) , std : : vector < KRPointLight * > ( ) , std : : vector < KRDirectionalLight * > ( ) , std : : vector < KRSpotLight * > ( ) , 0 , KRNode : : RENDER_PASS_FORWARD_TRANSPARENT , KRVector3 : : Zero ( ) , 0.0f , KRVector4 : : Zero ( ) ) ;
2013-03-21 13:21:04 -07:00
2014-04-11 01:15:40 -07:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 0 , m_pContext - > getTextureManager ( ) - > getTexture ( " font " ) , 0.0f , KRTexture : : TEXTURE_USAGE_UI ) ;
2013-03-21 13:21:04 -07:00
2013-11-09 16:08:08 -08:00
KRDataBlock index_data ;
2014-05-27 22:51:52 -07:00
m_pContext - > getMeshManager ( ) - > bindVBO ( m_debug_text_vertices , index_data , ( 1 < < KRMesh : : KRENGINE_ATTRIB_VERTEX ) | ( 1 < < KRMesh : : KRENGINE_ATTRIB_TEXUVA ) , true , 1.0f ) ;
2013-03-21 13:21:04 -07:00
GLDEBUG ( glDrawArrays ( GL_TRIANGLES , 0 , vertex_count ) ) ;
// Re-enable z-buffer write
GLDEBUG ( glDepthMask ( GL_TRUE ) ) ;
2013-11-09 16:08:08 -08:00
m_debug_text_vertices . unlock ( ) ;
2013-03-21 13:21:04 -07:00
} else {
2013-11-09 16:08:08 -08:00
if ( m_debug_text_vertices . getSize ( ) > 0 ) {
m_debug_text_vertices = KRDataBlock ( ) ;
2013-03-21 13:21:04 -07:00
}
2012-08-15 21:26:06 +00:00
}
}
2013-03-21 17:32:26 -07:00
std : : string KRCamera : : getDebugText ( )
{
std : : stringstream stream ;
stream . precision ( std : : numeric_limits < long double > : : digits10 ) ;
2013-03-22 17:17:12 -07:00
uint64_t fps = 0 ;
if ( m_frame_times_filled = = KRAKEN_FPS_AVERAGE_FRAME_COUNT ) {
for ( int i = 0 ; i < KRAKEN_FPS_AVERAGE_FRAME_COUNT ; i + + ) {
fps + = m_frame_times [ i ] ;
}
}
fps = 1000000 / ( fps / KRAKEN_FPS_AVERAGE_FRAME_COUNT ) ; // Order of division chosen to prevent overflow
2013-03-21 17:32:26 -07:00
switch ( settings . debug_display ) {
2013-03-22 17:17:12 -07:00
case KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_NONE : // ----====---- No debug display ----====----
2013-03-21 17:32:26 -07:00
break ;
2013-03-22 17:17:12 -07:00
case KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_TIME : // ----====---- Time / FPS ----====----
2013-03-21 17:32:26 -07:00
{
2013-03-22 17:17:12 -07:00
if ( fps > 0 ) {
stream < < " FPS \t " < < fps ;
}
}
break ;
case KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_MEMORY : // ----====---- Memory Utilization ----=====----
{
2016-07-10 03:33:58 -07:00
# if defined(__APPLE__)
2013-03-22 17:17:12 -07:00
// ---- CPU Memory ----
struct task_basic_info info ;
mach_msg_type_number_t size = sizeof ( info ) ;
kern_return_t kerr = task_info ( mach_task_self ( ) ,
TASK_BASIC_INFO ,
( task_info_t ) & info ,
& size ) ;
if ( kerr = = KERN_SUCCESS ) {
stream < < " \t Resident \t Virtual \t Total " ;
stream < < " \n CPU \t " < < ( info . resident_size / 1024 / 1024 ) < < " MB \t " < < ( info . virtual_size / 1024 / 1024 ) < < " MB \t " < < ( ( info . resident_size + info . virtual_size ) / 1024 / 1024 ) < < " MB " ;
} else {
stream < < " \n ERROR: Could not get CPU memory utilization. " ;
}
mach_port_t host_port = mach_host_self ( ) ;
mach_msg_type_number_t host_size = sizeof ( vm_statistics_data_t ) / sizeof ( integer_t ) ;
vm_size_t pagesize = 0 ;
vm_statistics_data_t vm_stat ;
if ( host_page_size ( host_port , & pagesize ) ! = KERN_SUCCESS ) {
stream < < " \n \n ERROR: Could not get VM page size. " ;
} else if ( host_statistics ( host_port , HOST_VM_INFO , ( host_info_t ) & vm_stat , & host_size ) ! = KERN_SUCCESS ) {
stream < < " \n \n ERROR: Could not get VM stats. " ;
} else {
stream < < " \n \n \n \t Wired \t Active \t Inactive \t Free \t Total " ;
stream < < " \n VM \t " ;
stream < < ( vm_stat . wire_count * pagesize / 1024 / 1024 ) < < " MB \t " ;
stream < < ( vm_stat . active_count * pagesize / 1024 / 1024 ) < < " MB \t " ;
stream < < ( vm_stat . inactive_count * pagesize / 1024 / 1024 ) < < " MB \t " ;
stream < < ( vm_stat . free_count * pagesize / 1024 / 1024 ) < < " MB \t " ;
stream < < ( ( vm_stat . wire_count + vm_stat . active_count + vm_stat . inactive_count ) * pagesize / 1024 / 1024 ) < < " MB " ;
}
2016-07-10 03:33:58 -07:00
# endif // defined(__APPLE__)
2013-03-22 17:17:12 -07:00
// ---- GPU Memory ----
2013-03-21 17:32:26 -07:00
int texture_count_active = m_pContext - > getTextureManager ( ) - > getActiveTextures ( ) . size ( ) ;
2014-04-11 01:15:40 -07:00
int texture_count = texture_count_active ;
2013-03-21 17:32:26 -07:00
long texture_mem_active = m_pContext - > getTextureManager ( ) - > getMemActive ( ) ;
long texture_mem_used = m_pContext - > getTextureManager ( ) - > getMemUsed ( ) ;
long texture_mem_throughput = m_pContext - > getTextureManager ( ) - > getMemoryTransferedThisFrame ( ) ;
2014-05-13 21:56:06 -07:00
int vbo_count_active = m_pContext - > getMeshManager ( ) - > getActiveVBOCount ( ) ;
long vbo_mem_active = m_pContext - > getMeshManager ( ) - > getMemActive ( ) ;
long vbo_mem_used = m_pContext - > getMeshManager ( ) - > getMemUsed ( ) ;
long vbo_mem_throughput = m_pContext - > getMeshManager ( ) - > getMemoryTransferedThisFrame ( ) ;
2013-03-21 17:32:26 -07:00
long total_mem_active = texture_mem_active + vbo_mem_active ;
long total_mem_used = texture_mem_used + vbo_mem_used ;
long total_mem_throughput = texture_mem_throughput + vbo_mem_throughput ;
2013-03-22 17:17:12 -07:00
stream < < " \n \n \n \t # Active \t # Used \t Active \t Used \t Throughput \n " ;
2013-03-21 17:32:26 -07:00
2013-03-22 17:17:12 -07:00
stream < < " Textures \t " < < texture_count_active < < " \t " < < texture_count < < " \t " < < ( texture_mem_active / 1024 ) < < " KB \t " < < ( texture_mem_used / 1024 ) < < " KB \t " < < ( texture_mem_throughput / 1024 ) < < " KB / frame \n " ;
2014-05-27 22:51:52 -07:00
stream < < " VBO's \t " < < vbo_count_active < < " \t " < < vbo_count_active < < " \t " < < ( vbo_mem_active / 1024 ) < < " KB \t " < < ( vbo_mem_used / 1024 ) < < " KB \t " < < ( vbo_mem_throughput / 1024 ) < < " KB / frame \n " ;
2013-03-22 17:17:12 -07:00
stream < < " \n GPU Total \t \t \t " < < ( total_mem_active / 1024 ) < < " KB \t " < < ( total_mem_used / 1024 ) < < " KB \t " < < ( total_mem_throughput / 1024 ) < < " KB / frame " ;
2013-03-21 17:32:26 -07:00
}
break ;
2013-03-22 17:17:12 -07:00
case KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_TEXTURES : // ----====---- List Active Textures ----====----
2013-03-21 17:32:26 -07:00
{
bool first = true ;
int texture_count = 0 ;
std : : set < KRTexture * > active_textures = m_pContext - > getTextureManager ( ) - > getActiveTextures ( ) ;
for ( std : : set < KRTexture * > : : iterator itr = active_textures . begin ( ) ; itr ! = active_textures . end ( ) ; itr + + ) {
KRTexture * texture = * itr ;
if ( first ) {
first = false ;
} else {
stream < < " \n " ;
}
stream < < texture - > getName ( ) ;
stream < < " \t " ;
stream < < texture - > getMemSize ( ) / 1024 ;
2013-03-22 17:17:12 -07:00
stream < < " KB " ;
2013-03-21 17:32:26 -07:00
stream < < " \t " ;
stream < < texture - > getMaxMipMap ( ) ;
2013-03-21 19:58:35 -07:00
if ( texture - > hasMipmaps ( ) & & texture - > getCurrentLodMaxDim ( ) ! = texture - > getMaxMipMap ( ) ) {
stream < < " px => " ;
2013-03-21 17:32:26 -07:00
stream < < texture - > getCurrentLodMaxDim ( ) ;
}
2013-03-21 19:58:35 -07:00
stream < < " px " ;
2013-03-21 17:32:26 -07:00
texture_count + + ;
}
stream < < " \n \n TOTAL: " ;
stream < < texture_count ;
stream < < " textures \t " ;
2013-03-22 17:17:12 -07:00
stream < < ( m_pContext - > getTextureManager ( ) - > getMemActive ( ) / 1024 ) < < " KB " ;
2013-03-21 19:58:35 -07:00
}
break ;
2013-03-22 17:17:12 -07:00
case KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_DRAW_CALLS : // ----====---- List Draw Calls ----====----
2013-03-21 19:58:35 -07:00
{
2014-05-13 21:56:06 -07:00
std : : vector < KRMeshManager : : draw_call_info > draw_calls = m_pContext - > getMeshManager ( ) - > getDrawCalls ( ) ;
2013-03-21 19:58:35 -07:00
long draw_call_count = 0 ;
long vertex_count = 0 ;
stream < < " \t Verts \t Pass \t Object \t Material " ;
for ( std : : vector < KRMeshManager : : draw_call_info > : : iterator itr = draw_calls . begin ( ) ; itr ! = draw_calls . end ( ) ; itr + + ) {
draw_call_count + + ;
stream < < " \n " < < draw_call_count < < " \t " < < ( * itr ) . vertex_count < < " \t " ;
switch ( ( * itr ) . pass ) {
case KRNode : : RENDER_PASS_FORWARD_OPAQUE :
stream < < " opaq " ;
break ;
case KRNode : : RENDER_PASS_DEFERRED_GBUFFER :
stream < < " d gb " ;
break ;
case KRNode : : RENDER_PASS_DEFERRED_LIGHTS :
stream < < " d light " ;
break ;
case KRNode : : RENDER_PASS_DEFERRED_OPAQUE :
stream < < " d opaq " ;
break ;
case KRNode : : RENDER_PASS_FORWARD_TRANSPARENT :
stream < < " trans " ;
break ;
case KRNode : : RENDER_PASS_PARTICLE_OCCLUSION :
stream < < " p occl " ;
break ;
case KRNode : : RENDER_PASS_ADDITIVE_PARTICLES :
stream < < " a part " ;
break ;
case KRNode : : RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE :
stream < < " vol add " ;
break ;
case KRNode : : RENDER_PASS_GENERATE_SHADOWMAPS :
stream < < " g shadow " ;
break ;
case KRNode : : RENDER_PASS_SHADOWMAP :
stream < < " shadow " ;
break ;
}
stream < < " \t " < < ( * itr ) . object_name < < " \t " < < ( * itr ) . material_name ;
vertex_count + = ( * itr ) . vertex_count ;
}
stream < < " \n \n \t \t TOTAL: \t " < < draw_call_count < < " draw calls \t " < < vertex_count < < " vertices " ;
2013-03-21 17:32:26 -07:00
}
break ;
2013-05-01 12:32:16 -07:00
case KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_OCTREE :
stream < < " Octree Visualization " ;
break ;
case KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_COLLIDERS :
stream < < " Collider Visualization " ;
break ;
2013-05-13 13:16:25 -07:00
case KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_BONES :
stream < < " Bone Visualization " ;
2013-12-09 22:29:13 -08:00
case KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_SIREN_REVERB_ZONES :
stream < < " Siren - Reverb Zones " ;
break ;
case KRRenderSettings : : KRENGINE_DEBUG_DISPLAY_SIREN_AMBIENT_ZONES :
stream < < " Siren - Ambient Zones " ;
2013-05-13 13:16:25 -07:00
break ;
2013-03-21 17:32:26 -07:00
}
return stream . str ( ) ;
}
2013-04-30 01:18:36 -07:00
2014-03-10 22:32:49 -07:00
const KRViewport & KRCamera : : getViewport ( ) const
2013-04-30 01:18:36 -07:00
{
return m_viewport ;
}
2014-04-29 00:30:14 -07:00
KRVector2 KRCamera : : getDownsample ( )
{
return m_downsample ;
}
void KRCamera : : setDownsample ( float v )
{
m_downsample = v ;
}
2014-06-25 00:45:00 -07:00
void KRCamera : : setFadeColor ( const KRVector4 & fade_color )
{
m_fade_color = fade_color ;
}
KRVector4 KRCamera : : getFadeColor ( )
{
return m_fade_color ;
}