Compare commits

..

1 Commits

Author SHA1 Message Date
Teejoon e000408593 Getting ShaderID one time per material in total instead of one time every frame 2016-03-11 11:03:09 +01:00
8 changed files with 51 additions and 62 deletions
+1 -2
View File
@@ -13,7 +13,6 @@
#include "Texture.h" #include "Texture.h"
#include "ShadowPass.h" #include "ShadowPass.h"
#include "BlurHUD.h" #include "BlurHUD.h"
#include "TextPass.h"
class DrawFinalPass class DrawFinalPass
{ {
@@ -23,7 +22,7 @@ public:
void InitializeTextures(); void InitializeTextures();
void InitializeFrameBuffers(); void InitializeFrameBuffers();
void InitializeShaderPrograms(); void InitializeShaderPrograms();
void Draw(RenderScene& scene, BlurHUD* blurHUDPass, TextPass* textPass); void Draw(RenderScene& scene, BlurHUD* blurHUDPass);
void ClearBuffer(); void ClearBuffer();
void OnWindowResize(); void OnWindowResize();
+1 -18
View File
@@ -26,24 +26,13 @@ struct ModelJob : RenderJob
ModelID = model->ResourceID; ModelID = model->ResourceID;
Type = matProp.type; Type = matProp.type;
::RawModel::MaterialBasic* matGroup = matProp.material; ::RawModel::MaterialBasic* matGroup = matProp.material;
ShaderID = matProp.ShaderID;
switch(matProp.type){ switch(matProp.type){
case ::RawModel::MaterialType::Basic: case ::RawModel::MaterialType::Basic:
if (Model->IsSkinned()) {
ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusSkinnedProgram")->ResourceID;
}
else {
ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusProgram")->ResourceID;
}
TextureID = 0; TextureID = 0;
break; break;
case ::RawModel::MaterialType::SingleTextures: case ::RawModel::MaterialType::SingleTextures:
{ {
if (Model->IsSkinned()) {
ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusSkinnedProgram")->ResourceID;
}
else {
ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusProgram")->ResourceID;
}
::RawModel::MaterialSingleTextures* singleTextures = static_cast<::RawModel::MaterialSingleTextures*>(matProp.material); ::RawModel::MaterialSingleTextures* singleTextures = static_cast<::RawModel::MaterialSingleTextures*>(matProp.material);
TextureID = (singleTextures->ColorMap.Texture) ? singleTextures->ColorMap.Texture->ResourceID : 0; TextureID = (singleTextures->ColorMap.Texture) ? singleTextures->ColorMap.Texture->ResourceID : 0;
if (modelComponent["DiffuseTexture"]) { if (modelComponent["DiffuseTexture"]) {
@@ -65,12 +54,6 @@ struct ModelJob : RenderJob
break; break;
case ::RawModel::MaterialType::SplatMapping: case ::RawModel::MaterialType::SplatMapping:
{ {
if (Model->IsSkinned()) {
ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusSplatMapSkinnedProgram")->ResourceID;
}
else {
ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusSplatMapProgram")->ResourceID;
}
::RawModel::MaterialSplatMapping* SplatTextures = static_cast<::RawModel::MaterialSplatMapping*>(matProp.material); ::RawModel::MaterialSplatMapping* SplatTextures = static_cast<::RawModel::MaterialSplatMapping*>(matProp.material);
SplatMap = &SplatTextures->SplatMap; SplatMap = &SplatTextures->SplatMap;
@@ -18,6 +18,7 @@
#include "../Core/ResourceManager.h" #include "../Core/ResourceManager.h"
#include "Texture.h" #include "Texture.h"
#include "Skeleton.h" #include "Skeleton.h"
#include "ShaderProgram.h"
#include "boost\endian\buffers.hpp" #include "boost\endian\buffers.hpp"
@@ -87,6 +88,7 @@ public:
struct MaterialProperties { struct MaterialProperties {
MaterialType type; MaterialType type;
MaterialBasic* material; MaterialBasic* material;
unsigned int ShaderID = 0;
}; };
const Vertex* Vertices() const { const Vertex* Vertices() const {
+22 -28
View File
@@ -242,7 +242,7 @@ void DrawFinalPass::InitializeShaderPrograms()
} }
void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass, TextPass* textPass) void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
{ {
GLERROR("Pre"); GLERROR("Pre");
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle()); DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle());
@@ -282,36 +282,10 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass, TextPass* tex
//state->StencilMask(0x00); //state->StencilMask(0x00);
DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene); DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene);
GLERROR("OpaqueObjects"); GLERROR("OpaqueObjects");
delete state;
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
if (scene.ShouldBlur) {
//Combine nonblur and blur texture
stateSprite->Disable(GL_DEPTH_TEST);
stateSprite->Disable(GL_STENCIL_TEST);
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
}
//Draw Transparen objects
//state->BlendFunc(GL_ONE, GL_ONE);
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
//DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
GLERROR("TransparentObjects");
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
stateSprite->Enable(GL_DEPTH_TEST);
//stateSprite->AlphaFunc(GL_GEQUAL, 0.05f);
//stateSprite->Enable(GL_ALPHA_TEST);
DrawSprites(scene.Jobs.SpriteJob, scene);
GLERROR("SpriteJobs");
delete stateSprite;
state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
//state->Disable(GL_STENCIL_TEST); //state->Disable(GL_STENCIL_TEST);
//Draw Transparen Shielded objects //Draw Transparen Shielded objects
state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
textPass->Draw(scene, m_FinalPassFrameBuffer);
DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing
GLERROR("Shielded Transparent objects"); GLERROR("Shielded Transparent objects");
@@ -322,7 +296,27 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass, TextPass* tex
m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene); m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene);
} }
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
if(scene.ShouldBlur) {
//Combine nonblur and blur texture
stateSprite->Disable(GL_DEPTH_TEST);
stateSprite->Disable(GL_STENCIL_TEST);
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
}
//Draw Transparen objects
//state->BlendFunc(GL_ONE, GL_ONE);
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
//DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
GLERROR("TransparentObjects");
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
stateSprite->Enable(GL_DEPTH_TEST);
//stateSprite->AlphaFunc(GL_GEQUAL, 0.05f);
//stateSprite->Enable(GL_ALPHA_TEST);
DrawSprites(scene.Jobs.SpriteJob, scene);
GLERROR("SpriteJobs");
delete stateSprite;
GLERROR("END"); GLERROR("END");
} }
+15
View File
@@ -148,14 +148,29 @@ void RawModelCustom::ReadMaterialSingle(std::size_t& offset, char* fileData, con
case MaterialType::Basic: case MaterialType::Basic:
newMaterialProperty.material = new MaterialBasic(); newMaterialProperty.material = new MaterialBasic();
ReadMaterialBasic(newMaterialProperty.material, offset, fileData, fileByteSize); ReadMaterialBasic(newMaterialProperty.material, offset, fileData, fileByteSize);
if(hasSkin){
newMaterialProperty.ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusSkinnedProgram")->ResourceID;
} else {
newMaterialProperty.ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusProgram")->ResourceID;
}
break; break;
case MaterialType::SplatMapping: case MaterialType::SplatMapping:
newMaterialProperty.material = new MaterialSplatMapping(); newMaterialProperty.material = new MaterialSplatMapping();
ReadMaterialSplatMapping(static_cast<MaterialSplatMapping*>(newMaterialProperty.material), offset, fileData, fileByteSize); ReadMaterialSplatMapping(static_cast<MaterialSplatMapping*>(newMaterialProperty.material), offset, fileData, fileByteSize);
if (hasSkin){
newMaterialProperty.ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusSplatMapSkinnedProgram")->ResourceID;
} else {
newMaterialProperty.ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusSplatMapProgram")->ResourceID;
}
break; break;
case MaterialType::SingleTextures: case MaterialType::SingleTextures:
newMaterialProperty.material = new MaterialSingleTextures(); newMaterialProperty.material = new MaterialSingleTextures();
ReadMaterialSingleTexture(static_cast<MaterialSingleTextures*>(newMaterialProperty.material), offset, fileData, fileByteSize); ReadMaterialSingleTexture(static_cast<MaterialSingleTextures*>(newMaterialProperty.material), offset, fileData, fileByteSize);
if (hasSkin){
newMaterialProperty.ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusSkinnedProgram")->ResourceID;
} else {
newMaterialProperty.ShaderID = ResourceManager::Load<ShaderProgram>("#ForwardPlusProgram")->ResourceID;
}
break; break;
default: default:
throw Resource::FailedLoadingException("Material contains an unknown MaterialType"); throw Resource::FailedLoadingException("Material contains an unknown MaterialType");
+4 -5
View File
@@ -210,15 +210,14 @@ void Renderer::Draw(RenderFrame& frame)
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Light Culling"); PerformanceTimer::StartTimerAndStopPrevious("Renderer-Light Culling");
m_LightCullingPass->CullLights(*scene); m_LightCullingPass->CullLights(*scene);
GLERROR("LightCulling"); GLERROR("LightCulling");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Text");
//m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer());
GLERROR("Draw Text");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Geometry+Light"); PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Geometry+Light");
m_DrawFinalPass->Draw(*scene, m_BlurHUDPass, m_TextPass); m_DrawFinalPass->Draw(*scene, m_BlurHUDPass);
GLERROR("Draw Geometry+Light"); GLERROR("Draw Geometry+Light");
//m_DrawScenePass->Draw(*scene); //m_DrawScenePass->Draw(*scene);
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Text");
m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer());
GLERROR("Draw Text");
PerformanceTimer::StopTimer("Renderer-Draw Text"); PerformanceTimer::StopTimer("Renderer-Draw Text");
} }
+2 -2
View File
@@ -34,7 +34,7 @@ void TextPass::Update()
void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer) void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer)
{ {
GLERROR("Derp1"); GLERROR("Derp1");
//TextPassState* state = new TextPassState(frameBuffer.GetHandle()); TextPassState* state = new TextPassState(frameBuffer.GetHandle());
for (auto &job : scene.Jobs.Text) { for (auto &job : scene.Jobs.Text) {
auto textJob = std::dynamic_pointer_cast<TextJob>(job); auto textJob = std::dynamic_pointer_cast<TextJob>(job);
if (textJob) { if (textJob) {
@@ -43,7 +43,7 @@ void TextPass::Draw(RenderScene& scene, FrameBuffer& frameBuffer)
} }
} }
GLERROR("Derp2"); GLERROR("Derp2");
// delete state; delete state;
} }
void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix) void TextPass::renderText(std::string text, Font* font, TextJob::AlignmentEnum alignment, glm::vec4 color, glm::mat4 modelMatrix, glm::mat4 projectionMatrix, glm::mat4 viewMatrix)
+4 -7
View File
@@ -4,13 +4,10 @@
TextPassState::TextPassState(GLuint frameBuffer) TextPassState::TextPassState(GLuint frameBuffer)
{ {
BindFramebuffer(frameBuffer); BindFramebuffer(frameBuffer);
Enable(GL_BLEND); glEnable(GL_BLEND);
Disable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
Enable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Enable(GL_ALPHA_TEST);
AlphaFunc(GL_GEQUAL, 0.05f);
} }
TextPassState::~TextPassState() TextPassState::~TextPassState()