Performance optimizations, reducing redundant GL calls
This commit is contained in:
@@ -159,10 +159,10 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende
|
||||
|
||||
// Set source to buffers from pass 1
|
||||
m_pContext->getTextureManager()->selectTexture(6, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE6));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(6);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeColorTexture));
|
||||
m_pContext->getTextureManager()->selectTexture(7, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE7));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(7);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeDepthTexture));
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende
|
||||
|
||||
// Set source to buffers from pass 2
|
||||
m_pContext->getTextureManager()->selectTexture(6, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE6));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(6);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, lightAccumulationTexture));
|
||||
|
||||
// Enable backface culling
|
||||
@@ -208,10 +208,10 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende
|
||||
|
||||
// Deactivate source buffer texture units
|
||||
m_pContext->getTextureManager()->selectTexture(6, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE6));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(6);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||
m_pContext->getTextureManager()->selectTexture(7, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE7));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(7);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||
|
||||
GL_POP_GROUP_MARKER;
|
||||
@@ -392,7 +392,7 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(0);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeDepthTexture));
|
||||
|
||||
GLDEBUG(glViewport(0, 0, volumetricLightingViewport.getSize().x, volumetricLightingViewport.getSize().y));
|
||||
@@ -651,16 +651,16 @@ void KRCamera::renderPost()
|
||||
getContext().getShaderManager()->selectShader(*this, postShader, m_viewport, KRMat4(), std::vector<KRLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(0);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeDepthTexture));
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE1));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(1);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeColorTexture));
|
||||
|
||||
if(settings.volumetric_environment_enable) {
|
||||
m_pContext->getTextureManager()->selectTexture(2, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE2));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(2);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, volumetricLightAccumulationTexture));
|
||||
}
|
||||
|
||||
@@ -670,11 +670,11 @@ void KRCamera::renderPost()
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(0);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(1, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE1));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(1);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||
|
||||
|
||||
@@ -688,7 +688,7 @@ void KRCamera::renderPost()
|
||||
// getContext().getShaderManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, KRMat4()), shadowViewports, KRMat4(), KRVector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
// m_pContext->getTextureManager()->selectTexture(1, NULL);
|
||||
// m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, true, false, false, true, false, true);
|
||||
// GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||
// m_pContext->getTextureManager()->_setActiveTexture(0);
|
||||
// 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
|
||||
@@ -700,7 +700,7 @@ void KRCamera::renderPost()
|
||||
// }
|
||||
//
|
||||
// m_pContext->getTextureManager()->selectTexture(0, NULL);
|
||||
// GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||
// m_pContext->getTextureManager()->_setActiveTexture(0);
|
||||
// GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||
// }
|
||||
|
||||
|
||||
@@ -122,10 +122,12 @@ void KRDirectionalLight::render(KRCamera *pCamera, std::vector<KRLight *> &light
|
||||
light_direction_view_space.setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE]);
|
||||
m_color.setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR]);
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
||||
m_intensity / 100.0f
|
||||
));
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY] != -1) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
||||
m_intensity / 100.0f
|
||||
));
|
||||
}
|
||||
|
||||
// Disable z-buffer write
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
|
||||
@@ -172,29 +172,28 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
||||
@"debug_enable_diffuse" : @25,
|
||||
@"debug_enable_specular" : @26,
|
||||
@"debug_enable_reflection" : @27,
|
||||
@"debug_super_shiny" : @28,
|
||||
@"debug_octree" : @29,
|
||||
@"debug_deferred" : @30,
|
||||
@"enable_deferred_lighting" : @31,
|
||||
@"near_clip" : @32,
|
||||
@"far_clip" : @33,
|
||||
@"volumetric_environment_enable" : @34,
|
||||
@"volumetric_environment_downsample" : @35,
|
||||
@"volumetric_environment_max_distance" : @36,
|
||||
@"volumetric_environment_slices" : @37,
|
||||
@"volumetric_environment_intensity" : @38,
|
||||
@"fog_type": @39,
|
||||
@"fog_near": @40,
|
||||
@"fog_far": @41,
|
||||
@"fog_density": @42,
|
||||
@"fog_color_r": @43,
|
||||
@"fog_color_g": @44,
|
||||
@"fog_color_b": @45,
|
||||
@"dust_enable" : @46,
|
||||
@"dust_intensity" : @47,
|
||||
@"lod_bias" : @48,
|
||||
@"enable_realtime_occlusion" : @49,
|
||||
@"debug_display" : @50
|
||||
@"debug_octree" : @28,
|
||||
@"debug_deferred" : @29,
|
||||
@"enable_deferred_lighting" : @30,
|
||||
@"near_clip" : @31,
|
||||
@"far_clip" : @32,
|
||||
@"volumetric_environment_enable" : @33,
|
||||
@"volumetric_environment_downsample" : @34,
|
||||
@"volumetric_environment_max_distance" : @35,
|
||||
@"volumetric_environment_slices" : @36,
|
||||
@"volumetric_environment_intensity" : @37,
|
||||
@"fog_type": @38,
|
||||
@"fog_near": @39,
|
||||
@"fog_far": @40,
|
||||
@"fog_density": @41,
|
||||
@"fog_color_r": @42,
|
||||
@"fog_color_g": @43,
|
||||
@"fog_color_b": @44,
|
||||
@"dust_enable" : @45,
|
||||
@"dust_intensity" : @46,
|
||||
@"lod_bias" : @47,
|
||||
@"enable_realtime_occlusion" : @48,
|
||||
@"debug_display" : @49
|
||||
|
||||
} copy];
|
||||
[self loadShaders];
|
||||
@@ -267,7 +266,7 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
||||
|
||||
-(int)getParameterCount
|
||||
{
|
||||
return 51;
|
||||
return 50;
|
||||
}
|
||||
|
||||
|
||||
@@ -283,7 +282,7 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
||||
|
||||
-(NSString *)getParameterLabelWithIndex: (int)i
|
||||
{
|
||||
NSString *parameter_labels[51] = {
|
||||
NSString *parameter_labels[50] = {
|
||||
@"Camera FOV",
|
||||
@"Shadow Quality (0 - 2)",
|
||||
@"Enable per-pixel lighting",
|
||||
@@ -312,7 +311,6 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
||||
@"Debug - Enable Diffuse",
|
||||
@"Debug - Enable Specular",
|
||||
@"Debug - Enable Reflections",
|
||||
@"Debug - Super Shiny",
|
||||
@"Debug - Octree Visualize",
|
||||
@"Debug - Deferred Lights Visualize",
|
||||
@"Enable Deferred Lighting",
|
||||
@@ -340,7 +338,7 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
||||
}
|
||||
-(KREngineParameterType)getParameterTypeWithIndex: (int)i
|
||||
{
|
||||
KREngineParameterType types[51] = {
|
||||
KREngineParameterType types[50] = {
|
||||
|
||||
KRENGINE_PARAMETER_FLOAT,
|
||||
KRENGINE_PARAMETER_INT,
|
||||
@@ -373,7 +371,6 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
||||
KRENGINE_PARAMETER_BOOL,
|
||||
KRENGINE_PARAMETER_BOOL,
|
||||
KRENGINE_PARAMETER_BOOL,
|
||||
KRENGINE_PARAMETER_BOOL,
|
||||
KRENGINE_PARAMETER_FLOAT,
|
||||
KRENGINE_PARAMETER_FLOAT,
|
||||
KRENGINE_PARAMETER_BOOL,
|
||||
@@ -398,7 +395,7 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
||||
}
|
||||
-(float)getParameterValueWithIndex: (int)i
|
||||
{
|
||||
float values[51] = {
|
||||
float values[50] = {
|
||||
_settings.perspective_fov,
|
||||
(float)_settings.m_cShadowBuffers,
|
||||
_settings.bEnablePerPixel ? 1.0f : 0.0f,
|
||||
@@ -427,7 +424,6 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
||||
_settings.bEnableDiffuse ? 1.0f : 0.0f,
|
||||
_settings.bEnableSpecular ? 1.0f : 0.0f,
|
||||
_settings.bEnableReflection ? 1.0f : 0.0f,
|
||||
_settings.bDebugSuperShiny ? 1.0f : 0.0f,
|
||||
_settings.bShowOctree ? 1.0f : 0.0f,
|
||||
_settings.bShowDeferred ? 1.0f : 0.0f,
|
||||
_settings.bEnableDeferredLighting ? 1.0f : 0.0f,
|
||||
@@ -575,80 +571,75 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
||||
}
|
||||
break;
|
||||
case 28:
|
||||
if(_settings.bDebugSuperShiny != bNewBoolVal) {
|
||||
_settings.bDebugSuperShiny = bNewBoolVal;
|
||||
}
|
||||
break;
|
||||
case 29:
|
||||
if(_settings.bShowOctree != bNewBoolVal) {
|
||||
_settings.bShowOctree = bNewBoolVal;
|
||||
}
|
||||
break;
|
||||
case 30:
|
||||
case 29:
|
||||
if(_settings.bShowDeferred != bNewBoolVal) {
|
||||
_settings.bShowDeferred = bNewBoolVal;
|
||||
}
|
||||
break;
|
||||
case 31:
|
||||
case 30:
|
||||
if(_settings.bEnableDeferredLighting != bNewBoolVal) {
|
||||
_settings.bEnableDeferredLighting = bNewBoolVal;
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
case 31:
|
||||
_settings.setPerspectiveNear(v);
|
||||
break;
|
||||
case 33:
|
||||
case 32:
|
||||
_settings.setPerpsectiveFarZ(v);
|
||||
break;
|
||||
case 34:
|
||||
case 33:
|
||||
_settings.volumetric_environment_enable = bNewBoolVal;
|
||||
break;
|
||||
case 35:
|
||||
case 34:
|
||||
_settings.volumetric_environment_downsample = 5 - (int)v;
|
||||
break;
|
||||
case 36:
|
||||
case 35:
|
||||
_settings.volumetric_environment_max_distance = v;
|
||||
break;
|
||||
case 37:
|
||||
case 36:
|
||||
_settings.volumetric_environment_quality = v;
|
||||
break;
|
||||
case 38:
|
||||
case 37:
|
||||
_settings.volumetric_environment_intensity = v;
|
||||
break;
|
||||
case 39:
|
||||
case 38:
|
||||
_settings.fog_type = v;
|
||||
break;
|
||||
case 40:
|
||||
case 39:
|
||||
_settings.fog_near = v;
|
||||
break;
|
||||
case 41:
|
||||
case 40:
|
||||
_settings.fog_far = v;
|
||||
break;
|
||||
case 42:
|
||||
case 41:
|
||||
_settings.fog_density = v;
|
||||
break;
|
||||
case 43:
|
||||
case 42:
|
||||
_settings.fog_color.x = v;
|
||||
break;
|
||||
case 44:
|
||||
case 43:
|
||||
_settings.fog_color.y = v;
|
||||
break;
|
||||
case 45:
|
||||
case 44:
|
||||
_settings.fog_color.z = v;
|
||||
break;
|
||||
case 46:
|
||||
case 45:
|
||||
_settings.dust_particle_enable = bNewBoolVal;
|
||||
break;
|
||||
case 47:
|
||||
case 46:
|
||||
_settings.dust_particle_intensity = v;
|
||||
break;
|
||||
case 48:
|
||||
case 47:
|
||||
_settings.setLODBias(v);
|
||||
break;
|
||||
case 49:
|
||||
case 48:
|
||||
_settings.setEnableRealtimeOcclusion(bNewBoolVal);
|
||||
break;
|
||||
case 50:
|
||||
case 49:
|
||||
_settings.debug_display = (KRRenderSettings::debug_display_type)v;
|
||||
break;
|
||||
}
|
||||
@@ -656,10 +647,10 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
||||
|
||||
-(float)getParameterMinWithIndex: (int)i
|
||||
{
|
||||
float minValues[51] = {
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
float minValues[50] = {
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.01f, 50.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -10.0f, 0.0f, 0.0f
|
||||
};
|
||||
@@ -669,10 +660,10 @@ void kraken::set_parameter(const std::string ¶meter_name, float parameter_va
|
||||
|
||||
-(float)getParameterMaxWithIndex: (int)i
|
||||
{
|
||||
float maxValues[51] = {
|
||||
float maxValues[50] = {
|
||||
PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f,
|
||||
1.0f, 10.0f, 2.0f, 1.0f, 1.0f, 1.0f, 5.0f, 1.0f, 0.5f, 1.0f,
|
||||
2.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
||||
2.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
||||
1.0f, 1.0f, 10.0f, 1000.0f, 1.0f, 5.0f, 1000.0f, 1.0f, 5.0f, 3.0f,
|
||||
1000.0f, 1000.0f, 0.01f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f, 1.0f, (float)(KRRenderSettings::KRENGINE_DEBUG_DISPLAY_NUMBER - 1)
|
||||
};
|
||||
|
||||
@@ -209,8 +209,9 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KR
|
||||
(m_color * pCamera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity).setUniform(pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR]);
|
||||
|
||||
KRMat4::DotWDiv(KRMat4::Invert(particleModelMatrix), KRVector3::Zero()).setUniform(pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_PARTICLE_ORIGIN]);
|
||||
|
||||
GLDEBUG(glUniform1f(pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE], m_dust_particle_size));
|
||||
if(pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE] != -1) {
|
||||
GLDEBUG(glUniform1f(pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE], m_dust_particle_size));
|
||||
}
|
||||
|
||||
m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), KRMeshManager::KRENGINE_MAX_RANDOM_PARTICLES * 3 * sizeof(KRMeshManager::RandomParticleVertexData), NULL, 0, true, false, false, true, false, false, false, true);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3));
|
||||
@@ -310,10 +311,12 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRLight *> &lights, const KR
|
||||
// Render light flare on transparency pass
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("flare", pCamera, lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), lights, 0, renderPass)) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
m_flareSize
|
||||
));
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE] != -1) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
m_flareSize
|
||||
));
|
||||
}
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture);
|
||||
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, NULL, 0, true, false, false, true, false, false, false, true);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
@@ -357,8 +360,8 @@ void KRLight::allocateShadowBuffers(int cBuffers) {
|
||||
GLDEBUG( glBindTexture(GL_TEXTURE_2D, shadowDepthTexture[iShadow]));
|
||||
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));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
|
||||
m_pContext->getTextureManager()->_setWrapModeS(shadowDepthTexture[iShadow], GL_CLAMP_TO_EDGE);
|
||||
m_pContext->getTextureManager()->_setWrapModeT(shadowDepthTexture[iShadow], GL_CLAMP_TO_EDGE);
|
||||
#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
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_EXT, GL_LEQUAL)); // TODO - Detect GL_EXT_shadow_samplers and only activate if available
|
||||
|
||||
@@ -259,7 +259,6 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
||||
|
||||
strcpy(szPrevShaderKey, pShader->getKey());
|
||||
}
|
||||
GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS], pCamera->settings.bDebugSuperShiny ? 20.0 : m_ns ));
|
||||
|
||||
// Bind bones
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_BONE_TRANSFORMS] != -1) {
|
||||
@@ -284,7 +283,9 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
||||
*bone_mat_component++ = t[i];
|
||||
}
|
||||
}
|
||||
glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_BONE_TRANSFORMS], bones.size(), GL_FALSE, bone_mats);
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_BONE_TRANSFORMS] != -1) {
|
||||
glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_BONE_TRANSFORMS], bones.size(), GL_FALSE, bone_mats);
|
||||
}
|
||||
}
|
||||
|
||||
bool bSameAmbient = false;
|
||||
@@ -301,11 +302,13 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
||||
bool bSameSpecularOffset = false;
|
||||
bool bSameReflectionOffset = false;
|
||||
bool bSameNormalOffset = false;
|
||||
bool bSameShininess = false;
|
||||
|
||||
if(*prevBoundMaterial && bSameShader) {
|
||||
bSameAmbient = (*prevBoundMaterial)->m_ambientColor == m_ambientColor;
|
||||
bSameDiffuse = (*prevBoundMaterial)->m_diffuseColor == m_diffuseColor;
|
||||
bSameSpecular = (*prevBoundMaterial)->m_specularColor == m_specularColor;
|
||||
bSameShininess = (*prevBoundMaterial)->m_ns == m_ns;
|
||||
bSameReflection = (*prevBoundMaterial)->m_reflectionColor == m_reflectionColor;
|
||||
bSameAmbientScale = (*prevBoundMaterial)->m_ambientMapScale == m_ambientMapScale;
|
||||
bSameDiffuseScale = (*prevBoundMaterial)->m_diffuseMapScale == m_diffuseMapScale;
|
||||
@@ -341,6 +344,12 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
||||
}
|
||||
}
|
||||
|
||||
if(!bSameShininess) {
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS] != -1) {
|
||||
GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS], m_ns));
|
||||
}
|
||||
}
|
||||
|
||||
if(!bSameReflection) {
|
||||
m_reflectionColor.setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_REFLECTION]);
|
||||
}
|
||||
@@ -377,7 +386,9 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
||||
m_normalMapOffset.setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_NORMALTEXTURE_OFFSET]);
|
||||
}
|
||||
|
||||
GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], m_tr));
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA] != -1) {
|
||||
GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], m_tr));
|
||||
}
|
||||
|
||||
if(bDiffuseMap) {
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pDiffuseMap);
|
||||
|
||||
@@ -75,10 +75,12 @@ void KRParticleSystemNewtonian::render(KRCamera *pCamera, std::vector<KRLight *>
|
||||
KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("dust_particle", pCamera, lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, getModelMatrix(), lights, 0, renderPass)) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
1.0f
|
||||
));
|
||||
if(pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE] != -1) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
1.0f
|
||||
));
|
||||
}
|
||||
|
||||
m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getRandomParticles(), particle_count * 3 * sizeof(KRMeshManager::RandomParticleVertexData), NULL, 0, true, false, false, true, false, false, false, false);
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, particle_count*3));
|
||||
|
||||
@@ -76,22 +76,29 @@ void KRPointLight::render(KRCamera *pCamera, std::vector<KRLight *> &lights, con
|
||||
|
||||
m_color.setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR]);
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
||||
m_intensity / 100.0f
|
||||
));
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY] != -1) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
||||
m_intensity / 100.0f
|
||||
));
|
||||
}
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DECAY_START],
|
||||
getDecayStart()
|
||||
));
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DECAY_START] != -1) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DECAY_START],
|
||||
getDecayStart()
|
||||
));
|
||||
}
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_CUTOFF] != -1) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_CUTOFF],
|
||||
KRLIGHT_MIN_INFLUENCE
|
||||
));
|
||||
}
|
||||
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_CUTOFF],
|
||||
KRLIGHT_MIN_INFLUENCE
|
||||
));
|
||||
|
||||
light_position.setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION]);
|
||||
if(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION] != -1) {
|
||||
light_position.setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION]);
|
||||
}
|
||||
|
||||
if(bVisualize) {
|
||||
// Enable additive blending
|
||||
|
||||
@@ -26,7 +26,6 @@ KRRenderSettings::KRRenderSettings()
|
||||
bEnableDiffuse = true;
|
||||
bEnableSpecular = true;
|
||||
bEnableLightMap = true;
|
||||
bDebugSuperShiny = false;
|
||||
bEnableDeferredLighting = false;
|
||||
|
||||
ambient_intensity = KRVector3::Zero();
|
||||
@@ -94,7 +93,6 @@ KRRenderSettings& KRRenderSettings::operator=(const KRRenderSettings &s)
|
||||
bEnableReflection=s.bEnableReflection;
|
||||
bEnableLightMap=s.bEnableLightMap;
|
||||
bDebugPSSM=s.bDebugPSSM;
|
||||
bDebugSuperShiny=s.bDebugSuperShiny;
|
||||
bShowShadowBuffer=s.bShowShadowBuffer;
|
||||
bShowOctree=s.bShowOctree;
|
||||
bShowDeferred=s.bShowDeferred;
|
||||
|
||||
@@ -39,7 +39,6 @@ public:
|
||||
bool bEnableReflection;
|
||||
bool bEnableLightMap;
|
||||
bool bDebugPSSM;
|
||||
bool bDebugSuperShiny;
|
||||
bool bShowShadowBuffer;
|
||||
bool bShowOctree;
|
||||
bool bShowDeferred;
|
||||
|
||||
@@ -232,7 +232,9 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
|
||||
|
||||
GLDEBUG(glUseProgram(m_iProgram));
|
||||
|
||||
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_ABSOLUTE_TIME], getContext().getAbsoluteTime()));
|
||||
if(m_uniforms[KRENGINE_UNIFORM_ABSOLUTE_TIME] != -1) {
|
||||
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_ABSOLUTE_TIME], getContext().getAbsoluteTime()));
|
||||
}
|
||||
|
||||
int light_directional_count = 0;
|
||||
int light_point_count = 0;
|
||||
@@ -249,32 +251,34 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
|
||||
int cShadowBuffers = directional_light->getShadowBufferCount();
|
||||
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1] != -1 && cShadowBuffers > 0) {
|
||||
m_pContext->getTextureManager()->selectTexture(3, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE3));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(3);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, directional_light->getShadowTextures()[0]));
|
||||
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));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
|
||||
|
||||
m_pContext->getTextureManager()->_setWrapModeS(3, GL_CLAMP_TO_EDGE);
|
||||
m_pContext->getTextureManager()->_setWrapModeT(3, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] != -1 && cShadowBuffers > 1 && camera.settings.m_cShadowBuffers > 1) {
|
||||
m_pContext->getTextureManager()->selectTexture(4, NULL);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE4));
|
||||
m_pContext->getTextureManager()->_setActiveTexture(4);
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, directional_light->getShadowTextures()[1]));
|
||||
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));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
|
||||
m_pContext->getTextureManager()->_setWrapModeS(4, GL_CLAMP_TO_EDGE);
|
||||
m_pContext->getTextureManager()->_setWrapModeT(4, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] != -1 && cShadowBuffers > 2 && camera.settings.m_cShadowBuffers > 2) {
|
||||
m_pContext->getTextureManager()->selectTexture(5, NULL);
|
||||
m_pContext->getTextureManager()->_setActiveTexture(5);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE5));
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, directional_light->getShadowTextures()[2]));
|
||||
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));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
|
||||
m_pContext->getTextureManager()->_setWrapModeS(5, GL_CLAMP_TO_EDGE);
|
||||
m_pContext->getTextureManager()->_setWrapModeT(5, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
KRMat4 matBias;
|
||||
@@ -389,10 +393,18 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
|
||||
}
|
||||
|
||||
// Fog parameters
|
||||
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_NEAR], camera.settings.fog_near));
|
||||
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_FAR], camera.settings.fog_far));
|
||||
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_DENSITY], camera.settings.fog_density));
|
||||
camera.settings.fog_color.setUniform(m_uniforms[KRENGINE_UNIFORM_FOG_COLOR]);
|
||||
if(m_uniforms[KRENGINE_UNIFORM_FOG_NEAR] != -1) {
|
||||
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_NEAR], camera.settings.fog_near));
|
||||
}
|
||||
if(m_uniforms[KRENGINE_UNIFORM_FOG_FAR] != -1) {
|
||||
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_FAR], camera.settings.fog_far));
|
||||
}
|
||||
if(m_uniforms[KRENGINE_UNIFORM_FOG_DENSITY] != -1) {
|
||||
GLDEBUG(glUniform1f(m_uniforms[KRENGINE_UNIFORM_FOG_DENSITY], camera.settings.fog_density));
|
||||
}
|
||||
if(m_uniforms[KRENGINE_UNIFORM_FOG_COLOR] != -1) {
|
||||
camera.settings.fog_color.setUniform(m_uniforms[KRENGINE_UNIFORM_FOG_COLOR]);
|
||||
}
|
||||
|
||||
|
||||
if(m_uniforms[KRENGINE_UNIFORM_FOG_SCALE] != -1) {
|
||||
@@ -406,30 +418,58 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
|
||||
}
|
||||
|
||||
// Sets the diffuseTexture variable to the first texture unit
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE], 0));
|
||||
if(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE], 0));
|
||||
}
|
||||
|
||||
// Sets the specularTexture variable to the second texture unit
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE], 1));
|
||||
if(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE], 1));
|
||||
}
|
||||
|
||||
// Sets the normalTexture variable to the third texture unit
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE], 2));
|
||||
if(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE], 2));
|
||||
}
|
||||
|
||||
// Sets the shadowTexture variable to the fourth texture unit
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1], 3));
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2], 4));
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3], 5));
|
||||
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE1], 3));
|
||||
}
|
||||
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2], 4));
|
||||
}
|
||||
if(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3], 5));
|
||||
}
|
||||
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_REFLECTIONCUBETEXTURE], 4));
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_LIGHTMAPTEXTURE], 5));
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME], 6));
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH], 7)); // Texture unit 7 is used for reading the depth buffer in gBuffer pass #2 and in post-processing pass
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE], 7)); // Texture unit 7 is used for the reflection map textures in gBuffer pass #3 and when using forward rendering
|
||||
if(m_uniforms[KRENGINE_UNIFORM_REFLECTIONCUBETEXTURE] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_REFLECTIONCUBETEXTURE], 4));
|
||||
}
|
||||
if(m_uniforms[KRENGINE_UNIFORM_LIGHTMAPTEXTURE] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_LIGHTMAPTEXTURE], 5));
|
||||
}
|
||||
if(m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME], 6));
|
||||
}
|
||||
if(m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH], 7)); // Texture unit 7 is used for reading the depth buffer in gBuffer pass #2 and in post-processing pass
|
||||
}
|
||||
if(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE], 7)); // Texture unit 7 is used for the reflection map textures in gBuffer pass #3 and when using forward rendering
|
||||
}
|
||||
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_DEPTH_FRAME], 0));
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_RENDER_FRAME], 1));
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_VOLUMETRIC_ENVIRONMENT_FRAME], 2));
|
||||
if(m_uniforms[KRENGINE_UNIFORM_DEPTH_FRAME] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_DEPTH_FRAME], 0));
|
||||
}
|
||||
if(m_uniforms[KRENGINE_UNIFORM_RENDER_FRAME] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_RENDER_FRAME], 1));
|
||||
}
|
||||
if(m_uniforms[KRENGINE_UNIFORM_VOLUMETRIC_ENVIRONMENT_FRAME] != -1) {
|
||||
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_VOLUMETRIC_ENVIRONMENT_FRAME], 2));
|
||||
}
|
||||
|
||||
#if defined(DEBUG)
|
||||
#if DEBUG
|
||||
GLint logLength;
|
||||
|
||||
GLint validate_status = GL_FALSE;
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
KRTexture(KRContext &context, std::string name);
|
||||
virtual ~KRTexture();
|
||||
|
||||
virtual void bind() = 0;
|
||||
virtual void bind(GLuint texture_unit) = 0;
|
||||
void releaseHandle();
|
||||
long getMemSize();
|
||||
virtual long getReferencedMemSize();
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
KRTexture2D::KRTexture2D(KRContext &context, KRDataBlock *data, std::string name) : KRTexture(context, name) {
|
||||
m_current_lod_max_dim = 0;
|
||||
m_pData = data;
|
||||
}
|
||||
}
|
||||
|
||||
KRTexture2D::~KRTexture2D() {
|
||||
delete m_pData;
|
||||
@@ -67,15 +67,15 @@ bool KRTexture2D::createGLTexture(int lod_max_dim) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void KRTexture2D::bind() {
|
||||
void KRTexture2D::bind(GLuint texture_unit) {
|
||||
GLuint handle = getHandle();
|
||||
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, handle));
|
||||
if(handle) {
|
||||
// TODO - These texture parameters should be assigned by the material or texture parameters
|
||||
GLDEBUG(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT));
|
||||
m_pContext->getTextureManager()->_setMaxAnisotropy(texture_unit, 1.0f);
|
||||
m_pContext->getTextureManager()->_setWrapModeS(texture_unit, GL_REPEAT);
|
||||
m_pContext->getTextureManager()->_setWrapModeT(texture_unit, GL_REPEAT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
virtual bool save(KRDataBlock &data);
|
||||
|
||||
virtual bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, long &textureMemUsed) = 0;
|
||||
virtual void bind();
|
||||
virtual void bind(GLuint texture_unit);
|
||||
|
||||
protected:
|
||||
KRDataBlock *m_pData;
|
||||
|
||||
@@ -112,12 +112,12 @@ void KRTextureAnimated::resetPoolExpiry()
|
||||
}
|
||||
}
|
||||
|
||||
void KRTextureAnimated::bind()
|
||||
void KRTextureAnimated::bind(GLuint texture_unit)
|
||||
{
|
||||
int frame_number = (int)floor(fmodf(getContext().getAbsoluteTime() * m_frame_rate,m_frame_count));
|
||||
KRTexture2D *frame_texture = textureForFrame(frame_number);
|
||||
if(frame_texture) {
|
||||
frame_texture->bind();
|
||||
frame_texture->bind(texture_unit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
virtual bool save(const std::string& path);
|
||||
virtual bool save(KRDataBlock &data);
|
||||
|
||||
virtual void bind();
|
||||
virtual void bind(GLuint texture_unit);
|
||||
virtual long getMemRequiredForSize(int max_dim);
|
||||
virtual void resetPoolExpiry();
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ void KRTextureCube::resetPoolExpiry()
|
||||
}
|
||||
}
|
||||
|
||||
void KRTextureCube::bind()
|
||||
void KRTextureCube::bind(GLuint texture_unit)
|
||||
{
|
||||
GLuint handle = getHandle();
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_CUBE_MAP, handle));
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
virtual bool save(const std::string& path);
|
||||
virtual bool save(KRDataBlock &data);
|
||||
|
||||
virtual void bind();
|
||||
virtual void bind(GLuint texture_unit);
|
||||
virtual long getMemRequiredForSize(int max_dim);
|
||||
virtual void resetPoolExpiry();
|
||||
|
||||
|
||||
@@ -46,6 +46,9 @@ KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context
|
||||
m_boundTextures[iTexture] = NULL;
|
||||
}
|
||||
m_memoryTransferredThisFrame = 0;
|
||||
|
||||
|
||||
_clearGLState();
|
||||
}
|
||||
|
||||
KRTextureManager::~KRTextureManager() {
|
||||
@@ -54,6 +57,52 @@ KRTextureManager::~KRTextureManager() {
|
||||
}
|
||||
}
|
||||
|
||||
void KRTextureManager::_clearGLState()
|
||||
{
|
||||
for(int i=0; i < KRENGINE_MAX_TEXTURE_UNITS; i++) {
|
||||
m_wrapModeS[i] = 0;
|
||||
m_wrapModeT[i] = 0;
|
||||
m_maxAnisotropy[i] = -1.0f;
|
||||
}
|
||||
|
||||
m_iActiveTexture = -1;
|
||||
}
|
||||
|
||||
void KRTextureManager::_setActiveTexture(int i)
|
||||
{
|
||||
if(m_iActiveTexture != i) {
|
||||
m_iActiveTexture = i;
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE0 + i));
|
||||
}
|
||||
}
|
||||
|
||||
void KRTextureManager::_setWrapModeS(GLuint i, GLuint wrap_mode)
|
||||
{
|
||||
if(m_wrapModeS[i] != wrap_mode) {
|
||||
_setActiveTexture(i);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_mode);
|
||||
m_wrapModeS[i] = wrap_mode;
|
||||
}
|
||||
}
|
||||
|
||||
void KRTextureManager::_setMaxAnisotropy(int i, float max_anisotropy)
|
||||
{
|
||||
if(m_maxAnisotropy[i] != max_anisotropy) {
|
||||
_setActiveTexture(i);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy);
|
||||
m_maxAnisotropy[i] = max_anisotropy;
|
||||
}
|
||||
}
|
||||
|
||||
void KRTextureManager::_setWrapModeT(GLuint i, GLuint wrap_mode)
|
||||
{
|
||||
if(m_wrapModeT[i] != wrap_mode) {
|
||||
_setActiveTexture(i);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_mode);
|
||||
m_wrapModeT[i] = wrap_mode;
|
||||
}
|
||||
}
|
||||
|
||||
KRTexture *KRTextureManager::loadTexture(const char *szName, const char *szExtension, KRDataBlock *data) {
|
||||
KRTexture *pTexture = NULL;
|
||||
|
||||
@@ -125,13 +174,13 @@ void KRTextureManager::selectTexture(int iTextureUnit, KRTexture *pTexture) {
|
||||
}
|
||||
|
||||
if(m_boundTextures[iTextureUnit] != pTexture || is_animated) {
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE0 + iTextureUnit));
|
||||
_setActiveTexture(iTextureUnit);
|
||||
if(pTexture != NULL) {
|
||||
m_poolTextures.erase(pTexture);
|
||||
if(m_activeTextures.find(pTexture) == m_activeTextures.end()) {
|
||||
m_activeTextures.insert(pTexture);
|
||||
}
|
||||
pTexture->bind();
|
||||
pTexture->bind(iTextureUnit);
|
||||
|
||||
} else {
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||
@@ -157,6 +206,7 @@ long KRTextureManager::getMemActive() {
|
||||
|
||||
void KRTextureManager::startFrame(float deltaTime)
|
||||
{
|
||||
_clearGLState();
|
||||
m_memoryTransferredThisFrame = 0;
|
||||
balanceTextureMemory();
|
||||
rotateBuffers();
|
||||
@@ -325,3 +375,4 @@ std::set<KRTexture *> &KRTextureManager::getPoolTextures()
|
||||
{
|
||||
return m_poolTextures;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,12 +69,24 @@ public:
|
||||
std::set<KRTexture *> &getActiveTextures();
|
||||
std::set<KRTexture *> &getPoolTextures();
|
||||
|
||||
void _setActiveTexture(int i);
|
||||
void _setWrapModeS(GLuint i, GLuint wrap_mode);
|
||||
void _setWrapModeT(GLuint i, GLuint wrap_mode);
|
||||
void _setMaxAnisotropy(int i, float max_anisotropy);
|
||||
|
||||
void _clearGLState();
|
||||
|
||||
private:
|
||||
int m_iActiveTexture;
|
||||
|
||||
long m_memoryTransferredThisFrame;
|
||||
|
||||
std::map<std::string, KRTexture *> m_textures;
|
||||
|
||||
KRTexture *m_boundTextures[KRENGINE_MAX_TEXTURE_UNITS];
|
||||
GLuint m_wrapModeS[KRENGINE_MAX_TEXTURE_UNITS];
|
||||
GLuint m_wrapModeT[KRENGINE_MAX_TEXTURE_UNITS];
|
||||
float m_maxAnisotropy[KRENGINE_MAX_TEXTURE_UNITS];
|
||||
std::set<KRTexture *> m_activeTextures;
|
||||
std::set<KRTexture *> m_poolTextures;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user