-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drawable.cpp
executable file
·65 lines (52 loc) · 1.75 KB
/
Drawable.cpp
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
64
65
#include "DXUT.h"
#include "Drawable.h"
#include "DrawableMesh.h"
#include "DrawableShader.h"
#include "Camera.h"
void BasicDrawable::Draw(ID3D11DeviceContext* pd3dContext)
{
//TODO: bounds of a given object
if (mCamera->testFrustum(mState.mPosition,mState.mCoords, mState.getBoundingRadius()) == TRUE) {
mState.updateMatrices();
mShader->DrawMesh(pd3dContext,mMesh,&mState,mCamera);
}
}
void BasicDrawable::DrawNoCull( ID3D11DeviceContext* pd3dContext )
{
mState.updateMatrices();
mShader->DrawMesh(pd3dContext,mMesh,&mState,mCamera);
}
BasicDrawable::BasicDrawable(DrawableMesh* pMesh, DrawableShader* pShader, Camera* pCamera)
: mState(), mMesh(pMesh), mShader(pShader), Drawable(pCamera)
{
}
BasicDrawable::BasicDrawable( const BasicDrawable& copy ) : Drawable(copy.mCamera)
{
mState = copy.mState;
mMesh = copy.mMesh;
mShader = copy.mShader;
}
BasicDrawable::~BasicDrawable()
{
}
void BasicDrawable::DrawInstanced( ID3D11DeviceContext* pd3dContext, BasicDrawable* pDrawableList, UINT pCount )
{
Camera* camera = pDrawableList[0].mCamera;
DrawableMesh* mesh = pDrawableList[0].mMesh;
DrawableShader* shader = pDrawableList[0].mShader;
UINT count = 0;
DrawableState** drawers = new DrawableState*[pCount];
for (UINT i = 0; i < pCount; i++) {
DrawableState& state = pDrawableList[i].mState;
if (camera->testFrustum(state.mPosition, state.mCoords, state.getBoundingRadius())) {
state.updateMatrices();
drawers[count] = &state;
count++;
}
}
shader->DrawInstanced(pd3dContext,mesh,drawers,camera,count);
}
void BasicDrawable::DrawInstancedIndirect(ID3D11DeviceContext* pd3dContext) {
mState.updateMatrices();
mShader->DrawInstancedIndirect(pd3dContext,mMesh,&mState,mCamera);
}