openspades/Sources/Draw/GLModelRenderer.cpp

120 lines
3.0 KiB
C++
Raw Normal View History

2013-08-29 11:45:22 +09:00
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/
2013-08-18 16:18:06 +09:00
#include "GLModelRenderer.h"
#include "GLModel.h"
#include "GLRenderer.h"
#include "../Core/Debug.h"
2013-08-25 08:18:00 +09:00
#include "GLProfiler.h"
2013-08-18 16:18:06 +09:00
namespace spades {
namespace draw {
GLModelRenderer::GLModelRenderer(GLRenderer *r):
device(r->GetGLDevice()), renderer(r){
SPADES_MARK_FUNCTION();
2013-08-25 08:18:00 +09:00
modelCount = 0;
2013-08-18 16:18:06 +09:00
}
GLModelRenderer::~GLModelRenderer() {
SPADES_MARK_FUNCTION();
2013-11-17 00:26:05 +09:00
Clear();
2013-08-18 16:18:06 +09:00
}
void GLModelRenderer::AddModel(GLModel *model,
const client::ModelRenderParam &param) {
SPADES_MARK_FUNCTION();
if(model->renderId == -1){
model->renderId = (int)models.size();
RenderModel m;
m.model = model;
2013-11-17 00:26:05 +09:00
model->AddRef();
2013-08-18 16:18:06 +09:00
models.push_back(m);
}
2013-08-25 08:18:00 +09:00
modelCount++;
2013-08-18 16:18:06 +09:00
models[model->renderId].params.push_back(param);
}
void GLModelRenderer::RenderShadowMapPass() {
SPADES_MARK_FUNCTION();
2013-08-25 08:18:00 +09:00
GLProfiler profiler(device, "Model [%d model(s), %d unique model type(s)]", modelCount, (int)models.size());
2013-08-18 16:18:06 +09:00
int numModels = 0;
for(size_t i = 0; i < models.size(); i++){
RenderModel& m = models[i];
GLModel *model = m.model;
model->RenderShadowMapPass(m.params);
numModels += (int)m.params.size();
}
#if 0
printf("Model types: %d, Number of models: %d\n",
(int)models.size(), numModels);
#endif
}
void GLModelRenderer::Prerender() {
SPADES_MARK_FUNCTION();
}
void GLModelRenderer::RenderSunlightPass() {
SPADES_MARK_FUNCTION();
2013-08-25 08:18:00 +09:00
GLProfiler profiler(device, "Model [%d model(s), %d unique model type(s)]", modelCount, (int)models.size());
2013-08-18 16:18:06 +09:00
for(size_t i = 0; i < models.size(); i++){
RenderModel& m = models[i];
GLModel *model = m.model;
model->RenderSunlightPass(m.params);
}
}
void GLModelRenderer::RenderDynamicLightPass(std::vector<GLDynamicLight> lights) {
SPADES_MARK_FUNCTION();
2013-08-25 08:18:00 +09:00
GLProfiler profiler(device, "Model [%d model(s), %d unique model type(s)]", modelCount, (int)models.size());
2013-08-18 16:18:06 +09:00
if(!lights.empty()){
for(size_t i = 0; i < models.size(); i++){
RenderModel& m = models[i];
GLModel *model = m.model;
model->RenderDynamicLightPass(m.params, lights);
}
}
2013-09-04 22:11:39 +09:00
}
void GLModelRenderer::Clear() {
2013-08-18 16:18:06 +09:00
// last phase: clear scene
for(size_t i = 0; i < models.size(); i++){
models[i].model->renderId = -1;
2013-11-17 00:26:05 +09:00
models[i].model->Release();
2013-08-18 16:18:06 +09:00
}
models.clear();
2013-08-25 08:18:00 +09:00
modelCount = 0;
2013-08-18 16:18:06 +09:00
}
}
}