-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstaticmesh.cpp
More file actions
63 lines (52 loc) · 1.73 KB
/
staticmesh.cpp
File metadata and controls
63 lines (52 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "stdafx.h"
#include "staticmesh.h"
#include "camera.h"
#include "ShaderProgram.h"
#include "world.h"
#include "System.h"
#include "Graphics.h"
void StaticMesh::draw(Camera* camera)
{
m_apiData.prepareForDrawing();
assert(m_inGPU && (m_instanceTransforms.size() == m_appliedTextures.size()));
for (unsigned i = 0; i < m_instanceTransforms.size(); ++i)
{
if (m_instanceTransforms[i].pendingUpdate())
m_instanceTransforms[i].forceMatrixUpdate();
//if (Graphics::viewFrustrumCheck(MVP, m_centrePoint, m_radius))
{
systemptr->graphics->prepareGeomPass();
s_geometryShader->setModelMatrix(m_instanceTransforms[i].matrix());
s_geometryShader->setMVP(camera->projection() * camera->matrix() * m_instanceTransforms[i].matrix());
s_geometryShader->setModelViewMatrix(camera->matrix() * m_instanceTransforms[i].matrix());
m_appliedTextures[i].bindForGPU();
GraphicsInterface::drawIndexedMeshWithState(m_indexCount);
//Draw for shadows:
systemptr->graphics->prepareShadowPass();
for (Light*& l : systemptr->gamestate.m_world->m_lights)
{
LightShadowInfo* shadowInfo = l->getShadowInfo();
if (shadowInfo)
{
switch (l->type())
{
case Enum::LIGHT_DIRECTIONAL:
{
DirectionalLight* light = (DirectionalLight*)l;
Camera lightCam;
lightCam.initOrthoProjectionMatrix(-90, 90, -90, 90, -90, 90);
s_shadowShader->setMVP(lightCam.projection() * m_instanceTransforms[i].matrix());
GraphicsInterface::drawIndexedMeshWithState(m_indexCount);
break;
}
}
}
}
}
}
}
void StaticMesh::createInstance(const Transformable& position, const Texture& texture)
{
m_instanceTransforms.push_back(position);
m_appliedTextures.push_back(texture);
}