2011-10-25 05:03:10 +00:00
//
// KRSettings.cpp
// 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
//
2012-08-15 21:26:06 +00:00
# import <string>
2011-10-25 05:03:10 +00:00
# include <iostream>
2012-08-15 21:26:06 +00:00
# include <sstream>
# include <fstream>
2012-09-13 20:09:19 +00:00
# import <assert.h>
2012-11-15 22:05:25 +00:00
# include <stack.h>
2011-10-25 05:03:10 +00:00
2012-04-19 23:39:32 +00:00
# import "KRVector2.h"
2011-10-25 05:03:10 +00:00
# import "KRCamera.h"
2012-09-19 20:26:30 +00:00
# import "KRStockGeometry.h"
2012-11-09 09:18:38 +00:00
# import "KRDirectionalLight.h"
2011-10-25 05:03:10 +00:00
2012-10-17 19:43:15 +00:00
KRCamera : : KRCamera ( KRContext & context ) : KRContextObject ( context ) {
2012-11-02 20:50:45 +00:00
m_particlesAbsoluteTime = 0.0f ;
2012-10-17 19:43:15 +00:00
backingWidth = 0 ;
backingHeight = 0 ;
2012-11-14 21:46:30 +00:00
volumetricBufferWidth = 0 ;
volumetricBufferHeight = 0 ;
2012-08-16 20:44:33 +00:00
2012-10-20 02:15:48 +00:00
float const PI = 3.141592653589793f ;
float const D2R = PI * 2 / 360 ;
2011-10-25 05:03:10 +00:00
bShowShadowBuffer = false ;
2012-09-11 03:06:35 +00:00
bShowOctree = false ;
2012-09-11 07:23:54 +00:00
bShowDeferred = false ;
2011-10-25 05:03:10 +00:00
bEnablePerPixel = true ;
bEnableDiffuseMap = true ;
bEnableNormalMap = true ;
bEnableSpecMap = true ;
2012-05-08 23:39:52 +00:00
bEnableReflectionMap = true ;
2012-10-12 00:02:24 +00:00
bEnableReflection = true ;
2011-10-25 05:03:10 +00:00
bDebugPSSM = false ;
bEnableAmbient = true ;
bEnableDiffuse = true ;
2012-10-19 18:28:18 +00:00
bEnableSpecular = true ;
2012-04-12 06:25:44 +00:00
bEnableLightMap = true ;
2011-10-25 05:03:10 +00:00
bDebugSuperShiny = false ;
2012-10-19 18:28:18 +00:00
bEnableDeferredLighting = true ;
2011-10-25 05:03:10 +00:00
2012-03-29 19:39:28 +00:00
2012-10-19 18:28:18 +00:00
dAmbientR = 0.0f ;
dAmbientG = 0.0f ;
dAmbientB = 0.0f ;
2011-10-25 05:03:10 +00:00
dSunR = 1.0f ;
dSunG = 1.0f ;
2012-04-20 02:02:33 +00:00
dSunB = 1.0f ;
2011-10-25 05:03:10 +00:00
2012-04-26 09:06:45 +00:00
perspective_fov = 45.0 * D2R ;
perspective_nearz = 5.0f ;
2011-10-25 05:03:10 +00:00
perspective_farz = 100.0f ;
dof_quality = 0 ;
dof_depth = 0.05f ;
dof_falloff = 0.05f ;
bEnableFlash = false ;
flash_intensity = 1.0f ;
flash_depth = 0.7f ;
flash_falloff = 0.5f ;
bEnableVignette = false ;
vignette_radius = 0.4f ;
vignette_falloff = 1.0f ;
2012-08-15 21:26:06 +00:00
m_cShadowBuffers = 0 ;
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 ;
2012-08-15 21:26:06 +00:00
2012-11-15 22:05:25 +00:00
2012-08-15 21:26:06 +00:00
m_iFrame = 0 ;
2012-08-16 20:44:33 +00:00
2012-10-10 22:09:28 +00:00
m_skyBoxName = " " ;
m_pSkyBoxTexture = NULL ;
2012-11-09 20:55:23 +00:00
2012-11-14 21:46:30 +00:00
volumetric_environment_enable = false ;
volumetric_environment_downsample = 2 ;
volumetric_environment_max_distance = 1000.0f ;
volumetric_environment_quality = ( 50 - 5.0 ) / 495.0f ;
2012-11-22 09:02:25 +00:00
volumetric_environment_intensity = 0.9f ;
2012-11-21 22:47:33 +00:00
fog_near = 500.0f ;
2012-11-22 09:02:25 +00:00
fog_far = 5000.0f ;
fog_density = 0.0005f ;
fog_color = KRVector3 ( 0.45 , 0.45 , 0.5 ) ;
2012-11-21 22:47:33 +00:00
fog_type = 0 ;
2012-11-23 01:02:22 +00:00
dust_particle_intensity = 0.25f ;
2012-11-23 01:13:35 +00:00
dust_particle_enable = false ;
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
}
KRMat4 KRCamera : : getProjectionMatrix ( ) {
KRMat4 projectionMatrix ;
2012-04-20 00:17:15 +00:00
projectionMatrix . perspective ( perspective_fov , m_viewportSize . x / m_viewportSize . y , perspective_nearz , perspective_farz ) ;
2011-10-25 05:03:10 +00:00
return projectionMatrix ;
2012-04-19 23:39:32 +00:00
}
const KRVector2 & KRCamera : : getViewportSize ( ) {
return m_viewportSize ;
}
void KRCamera : : setViewportSize ( const KRVector2 & size ) {
m_viewportSize = size ;
2012-06-15 00:05:56 +00:00
}
KRVector3 KRCamera : : getPosition ( ) const {
return m_position ;
}
2012-08-15 21:26:06 +00:00
2012-06-15 00:05:56 +00:00
void KRCamera : : setPosition ( const KRVector3 & position ) {
m_position = position ;
2012-08-15 21:26:06 +00:00
}
2012-11-02 20:50:45 +00:00
void KRCamera : : renderFrame ( KRScene & scene , KRMat4 & viewMatrix , float deltaTime )
2012-08-15 21:26:06 +00:00
{
2012-11-16 02:58:23 +00:00
if ( m_iFrame = = 0 ) {
if ( scene . getFirstLight ( ) = = NULL ) {
scene . addDefaultLights ( ) ;
}
}
2012-10-03 19:29:37 +00:00
GLint defaultFBO ;
GLDEBUG ( glGetIntegerv ( GL_FRAMEBUFFER_BINDING , & defaultFBO ) ) ;
2012-10-17 19:43:15 +00:00
createBuffers ( ) ;
2012-10-26 01:17:35 +00:00
setViewportSize ( KRVector2 ( backingWidth , backingHeight ) ) ;
m_viewport = KRViewport ( getViewportSize ( ) , viewMatrix , getProjectionMatrix ( ) ) ;
2012-08-15 21:26:06 +00:00
2012-11-16 02:58:23 +00:00
renderFrame ( scene , deltaTime ) ;
2012-10-03 19:29:37 +00:00
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , defaultFBO ) ) ;
2012-08-23 16:55:46 +00:00
renderPost ( ) ;
2012-08-15 21:26:06 +00:00
m_iFrame + + ;
}
2012-09-21 08:24:55 +00:00
2012-11-09 20:55:23 +00:00
2012-11-16 02:58:23 +00:00
void KRCamera : : renderFrame ( KRScene & scene , float deltaTime ) {
2012-08-15 21:26:06 +00:00
2012-10-26 19:31:27 +00:00
KRVector3 vecCameraDirection = m_viewport . getCameraDirection ( ) ;
2012-09-21 08:24:55 +00:00
2012-11-15 22:05:25 +00:00
// GLuint shadowDepthTexture[KRENGINE_MAX_SHADOW_BUFFERS];
// KRViewport shadowViewports[KRENGINE_MAX_SHADOW_BUFFERS];
// int cShadows = 0;
2012-08-15 21:26:06 +00:00
if ( bEnableDeferredLighting ) {
// ----====---- Opaque Geometry, Deferred rendering Pass 1 ----====----
// Set render target
2012-09-13 20:09:19 +00:00
GLDEBUG ( glBindFramebuffer ( GL_FRAMEBUFFER , compositeFramebuffer ) ) ;
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 write
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDepthMask ( GL_TRUE ) ) ;
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
2012-11-17 07:57:28 +00:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_DEFERRED_GBUFFER , true ) ;
2012-11-15 22:05:25 +00:00
// ----====---- Generate Shadowmaps for Lights ----====----
2012-11-17 07:57:28 +00:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_GENERATE_SHADOWMAPS , false ) ;
2012-11-15 22:05:25 +00:00
GLDEBUG ( glViewport ( 0 , 0 , m_viewport . getSize ( ) . x , m_viewport . getSize ( ) . y ) ) ;
2012-08-15 21:26:06 +00:00
// ----====---- Opaque Geometry, Deferred rendering Pass 2 ----====----
// 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 ) ) ;
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
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 6 , NULL ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE6 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , compositeColorTexture ) ) ;
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 7 , NULL ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE7 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , 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
2012-08-15 21:26:06 +00:00
// ----====---- Opaque Geometry, Deferred rendering Pass 3 ----====----
// 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
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 6 , NULL ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE6 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , 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
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 6 , NULL ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE6 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , 0 ) ) ;
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 7 , NULL ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE7 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , 0 ) ) ;
2012-08-15 21:26:06 +00:00
} else {
2012-11-15 22:05:25 +00:00
// ----====---- Generate Shadowmaps for Lights ----====----
2012-11-17 07:57:28 +00:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_GENERATE_SHADOWMAPS , true ) ;
2012-08-15 21:26:06 +00:00
// ----====---- Opaque Geometry, Forward Rendering ----====----
// 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-11-22 09:02:25 +00:00
GLDEBUG ( glViewport ( 0 , 0 , m_viewport . getSize ( ) . x , m_viewport . getSize ( ) . 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 ) ) ;
2012-10-03 19:29:37 +00: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
// Enable z-buffer write
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDepthMask ( GL_TRUE ) ) ;
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
2012-11-17 07:57:28 +00:00
scene . render ( this , m_viewport . getVisibleBounds ( ) , m_viewport , KRNode : : RENDER_PASS_FORWARD_OPAQUE , false ) ;
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
// 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
2012-10-10 22:09:28 +00:00
if ( ! m_pSkyBoxTexture & & m_skyBoxName . length ( ) ) {
m_pSkyBoxTexture = getContext ( ) . getTextureManager ( ) - > getTextureCube ( m_skyBoxName . c_str ( ) ) ;
}
if ( m_pSkyBoxTexture ) {
2012-11-21 22:47:33 +00:00
getContext ( ) . getShaderManager ( ) - > selectShader ( " sky_box " , * this , std : : vector < KRLight * > ( ) , m_viewport , KRMat4 ( ) , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , KRNode : : RENDER_PASS_FORWARD_OPAQUE ) ;
2012-11-15 23:20:59 +00:00
2012-11-17 00:15:52 +00:00
getContext ( ) . getTextureManager ( ) - > selectTexture ( 0 , m_pSkyBoxTexture ) ;
2012-10-10 22:09:28 +00:00
// Render a full screen quad
m_pContext - > getModelManager ( ) - > bindVBO ( ( void * ) KRENGINE_VBO_2D_SQUARE , KRENGINE_VBO_2D_SQUARE_SIZE , true , false , false , true , false ) ;
GLDEBUG ( glDrawArrays ( GL_TRIANGLE_STRIP , 0 , 4 ) ) ;
}
// ----====---- Transparent Geometry, Forward Rendering ----====----
// 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));
//
// // 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));
2012-08-15 21:26:06 +00:00
// Enable alpha blending
2012-09-13 20:09:19 +00:00
GLDEBUG ( glEnable ( GL_BLEND ) ) ;
GLDEBUG ( glBlendFunc ( GL_SRC_ALPHA , 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
2012-09-05 18:14:08 +00:00
2012-08-15 21:26:06 +00:00
// ----====---- Flares ----====----
// 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
2012-11-09 20:55:23 +00:00
// ----====---- Volumetric Lighting ----====----
2012-11-15 22:05:25 +00:00
if ( volumetric_environment_enable ) {
KRViewport volumetricLightingViewport = KRViewport ( KRVector2 ( volumetricBufferWidth , volumetricBufferHeight ) , m_viewport . getViewMatrix ( ) , m_viewport . getProjectionMatrix ( ) ) ;
2012-11-09 20:55:23 +00:00
2012-11-14 21:46:30 +00:00
if ( 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 ) ) ;
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 0 , NULL ) ;
2012-11-10 00:51:03 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE0 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , 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-11-14 21:46:30 +00:00
if ( 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
}
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 ----====----
2012-09-11 03:06:35 +00:00
if ( bShowOctree ) {
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
2012-11-16 02:58:23 +00:00
KRShader * pVisShader = getContext ( ) . getShaderManager ( ) - > getShader ( " visualize_overlay " , this , std : : vector < KRLight * > ( ) , 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
KRMat4 projectionMatrix = getProjectionMatrix ( ) ;
2012-09-19 20:26:30 +00:00
m_pContext - > getModelManager ( ) - > bindVBO ( ( void * ) KRENGINE_VBO_3D_CUBE , KRENGINE_VBO_3D_CUBE_SIZE , true , false , false , false , false ) ;
2012-11-17 05:20:26 +00:00
for ( std : : 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 ( ) ;
2012-11-17 05:20:26 +00:00
matModel . scale ( ( * itr ) . first . size ( ) / 2.0f ) ;
matModel . translate ( ( * itr ) . first . center ( ) ) ;
2012-11-15 23:20:59 +00:00
2012-11-21 22:47:33 +00:00
if ( getContext ( ) . getShaderManager ( ) - > selectShader ( * this , pVisShader , m_viewport , matModel , std : : vector < KRLight * > ( ) , KRNode : : RENDER_PASS_FORWARD_TRANSPARENT ) ) {
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
2012-08-15 21:26:06 +00:00
2012-10-18 21:20:38 +00: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->getModelManager()->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());
2012-08-15 21:26:06 +00:00
}
2012-08-23 16:55:46 +00:00
void KRCamera : : createBuffers ( ) {
2012-10-17 19:43:15 +00:00
GLint renderBufferWidth = 0 , renderBufferHeight = 0 ;
GLDEBUG ( glGetRenderbufferParameteriv ( GL_RENDERBUFFER , GL_RENDERBUFFER_WIDTH , & renderBufferWidth ) ) ;
GLDEBUG ( glGetRenderbufferParameteriv ( GL_RENDERBUFFER , GL_RENDERBUFFER_HEIGHT , & renderBufferHeight ) ) ;
2012-08-15 21:26:06 +00:00
2012-10-17 19:43:15 +00:00
if ( renderBufferWidth ! = backingWidth | | renderBufferHeight ! = backingHeight ) {
backingWidth = renderBufferWidth ;
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
GLDEBUG ( glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , backingWidth , backingHeight , 0 , GL_BGRA , GL_UNSIGNED_BYTE , NULL ) ) ;
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
GLDEBUG ( glTexImage2D ( GL_TEXTURE_2D , 0 , GL_DEPTH_COMPONENT , backingWidth , backingHeight , 0 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT , NULL ) ) ;
//GLDEBUG(glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, backingWidth, backingHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL));
//GLDEBUG(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24_OES, backingWidth, backingHeight));
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
GLDEBUG ( glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , backingWidth , backingHeight , 0 , GL_BGRA , GL_UNSIGNED_BYTE , NULL ) ) ;
GLDEBUG ( glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , lightAccumulationTexture , 0 ) ) ;
2012-11-14 21:46:30 +00:00
}
int targetVolumetricBufferWidth = 0 ;
int targetVolumetricBufferHeight = 0 ;
2012-11-15 23:20:59 +00:00
if ( volumetric_environment_enable & & volumetric_environment_downsample ! = 0 ) {
2012-11-14 21:46:30 +00:00
targetVolumetricBufferWidth = renderBufferWidth > > volumetric_environment_downsample ;
targetVolumetricBufferHeight = renderBufferHeight > > volumetric_environment_downsample ;
}
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
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
2012-08-15 21:26:06 +00:00
2012-09-13 20:09:19 +00:00
GLDEBUG ( glDisable ( GL_DEPTH_TEST ) ) ;
2012-11-16 02:58:23 +00:00
KRShader * postShader = m_pContext - > getShaderManager ( ) - > getShader ( " PostShader " , this , std : : vector < KRLight * > ( ) , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , KRNode : : RENDER_PASS_FORWARD_TRANSPARENT ) ;
2012-11-21 22:47:33 +00:00
getContext ( ) . getShaderManager ( ) - > selectShader ( * this , postShader , m_viewport , KRMat4 ( ) , std : : vector < KRLight * > ( ) , KRNode : : RENDER_PASS_FORWARD_TRANSPARENT ) ;
2012-08-15 21:26:06 +00:00
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 0 , NULL ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE0 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , compositeDepthTexture ) ) ;
2012-08-15 21:26:06 +00:00
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 1 , NULL ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE1 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , compositeColorTexture ) ) ;
2012-11-09 20:55:23 +00:00
2012-11-15 23:20:59 +00:00
if ( volumetric_environment_enable ) {
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 2 , NULL ) ;
2012-11-14 21:46:30 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE2 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , volumetricLightAccumulationTexture ) ) ;
}
2012-08-15 21:26:06 +00:00
// Update attribute values.
2012-09-19 20:26:30 +00:00
m_pContext - > getModelManager ( ) - > bindVBO ( ( void * ) KRENGINE_VBO_2D_SQUARE , KRENGINE_VBO_2D_SQUARE_SIZE , true , false , false , true , false ) ;
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
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 0 , NULL ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE0 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , 0 ) ) ;
2012-08-15 21:26:06 +00:00
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 1 , NULL ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE1 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , 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);
2012-11-15 22:05:25 +00:00
// m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
// GLDEBUG(glActiveTexture(GL_TEXTURE0));
// 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);
2012-11-15 22:05:25 +00:00
// GLDEBUG(glActiveTexture(GL_TEXTURE0));
// GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
// }
2012-08-15 21:26:06 +00:00
const char * szText = m_debug_text . c_str ( ) ;
if ( * szText ) {
2012-11-16 02:58:23 +00:00
KRShader * fontShader = m_pContext - > getShaderManager ( ) - > getShader ( " debug_font " , this , std : : vector < KRLight * > ( ) , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , false , KRNode : : RENDER_PASS_FORWARD_TRANSPARENT ) ;
2012-11-01 22:16:59 +00:00
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 0 , m_pContext - > getTextureManager ( ) - > getTexture ( " font " ) ) ;
2012-08-15 21:26:06 +00:00
const char * pChar = szText ;
int iPos = 0 ;
2012-10-20 02:15:48 +00:00
float dScale = 1.0 / 24.0 ;
float dTexScale = 1.0 / 16.0 ;
2012-08-15 21:26:06 +00:00
while ( * pChar ) {
int iChar = * pChar + + - ' \0 ' ;
int iCol = iChar % 16 ;
int iRow = 15 - ( iChar - iCol ) / 16 ;
GLfloat charVertices [ ] = {
- 1.0f , dScale * iPos - 1.0 ,
- 1.0 + dScale , dScale * iPos - 1.0 ,
- 1.0f , dScale * iPos + dScale - 1.0 ,
- 1.0 + dScale , dScale * iPos + dScale - 1.0 ,
} ;
GLfloat charTexCoords [ ] = {
dTexScale * iCol , dTexScale * iRow + dTexScale ,
dTexScale * iCol , dTexScale * iRow ,
dTexScale * iCol + dTexScale , dTexScale * iRow + dTexScale ,
dTexScale * iCol + dTexScale , dTexScale * iRow
} ;
2012-10-25 18:28:30 +00:00
# if GL_OES_vertex_array_object
GLDEBUG ( glBindVertexArrayOES ( 0 ) ) ;
# endif
2012-09-19 20:26:30 +00:00
m_pContext - > getModelManager ( ) - > configureAttribs ( true , false , false , true , false ) ;
2012-09-13 20:09:19 +00:00
GLDEBUG ( glVertexAttribPointer ( KRShader : : KRENGINE_ATTRIB_TEXUVA , 2 , GL_FLOAT , 0 , 0 , charTexCoords ) ) ;
GLDEBUG ( glVertexAttribPointer ( KRShader : : KRENGINE_ATTRIB_VERTEX , 2 , GL_FLOAT , 0 , 0 , charVertices ) ) ;
GLDEBUG ( glDrawArrays ( GL_TRIANGLE_STRIP , 0 , 4 ) ) ;
2012-08-15 21:26:06 +00:00
iPos + + ;
}
2012-09-13 20:09:19 +00:00
GLDEBUG ( glActiveTexture ( GL_TEXTURE0 ) ) ;
GLDEBUG ( glBindTexture ( GL_TEXTURE_2D , 0 ) ) ;
2012-08-15 21:26:06 +00:00
2012-11-17 00:15:52 +00:00
m_pContext - > getTextureManager ( ) - > selectTexture ( 1 , NULL ) ;
2012-08-15 21:26:06 +00:00
}
}
2012-10-10 22:09:28 +00:00
void KRCamera : : setSkyBox ( const std : : string & skyBoxName ) {
m_pSkyBoxTexture = NULL ;
m_skyBoxName = skyBoxName ;
}
2012-10-20 01:10:57 +00:00
float KRCamera : : getPerspectiveNearZ ( )
{
return perspective_nearz ;
}
float KRCamera : : getPerspectiveFarZ ( )
{
return perspective_farz ;
}
void KRCamera : : setPerspectiveNear ( float v )
{
if ( perspective_nearz ! = v ) {
perspective_nearz = v ;
}
}
void KRCamera : : setPerpsectiveFarZ ( float v )
{
if ( perspective_farz ! = v ) {
perspective_farz = v ;
}
}