summaryrefslogtreecommitdiff
path: root/game/scenary/foliage.cpp
blob: 35be051ea9ee5fabe427772d5f05b19360aba9d8 (plain)
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
#include "foliage.h"
#include "gfx/gl/sceneShader.h"
#include "gfx/gl/shadowMapper.h"
#include "gfx/gl/vertexArrayObject.hpp"
#include "gfx/models/texture.h"
#include "location.hpp"

bool
Foliage::persist(Persistence::PersistenceStore & store)
{
	return STORE_TYPE && STORE_HELPER(bodyMesh, Asset::MeshConstruct) && Asset::persist(store);
}

void
Foliage::postLoad()
{
	texture = getTexture();
	bodyMesh->configureVAO(instanceVAO).addAttribs<glm::mat4>(instances.bufferName(), 1);
}

void
Foliage::render(const SceneShader & shader) const
{
	if (const auto count = instances.count()) {
		shader.basicInst.use();
		if (texture) {
			texture->bind();
		}
		glBindVertexArray(instanceVAO);
		glDrawElementsInstanced(
				bodyMesh->type(), bodyMesh->count(), GL_UNSIGNED_INT, nullptr, static_cast<GLsizei>(count));
		glBindVertexArray(0);
	}
}

void
Foliage::shadows(const ShadowMapper &) const
{
}