Browse Source

began mesher rework

testing
Michael Porter 2 years ago
parent
commit
9dad2ea38b

+ 1907
- 0
comp.txt
File diff suppressed because it is too large
View File


+ 1
- 1
include/graphics/chunkgeometry.h View File

@@ -17,7 +17,7 @@ public:
void buildVertices(Chunk& chunk);
void buildLighting(Chunk& chunk);
protected:
unsigned mVAO;
};

}

+ 28
- 0
include/graphics/chunkmesh.h View File

@@ -0,0 +1,28 @@
#pragma once

#include <memory>
#include <glm/glm.hpp>

namespace vtk {
class World;

class ChunkMesh {
public:
ChunkMesh(World& world, glm::ivec3 linkedChunkPos);
void rebuildChunkGeometry(const unsigned& vao);
void rebuildChunkLighting(const unsigned& vao);

protected:
//position of chunk since chunk does NOT have to exist to rebuild
//if chunk is not loaded, rebuild will fail silently
//this is useful for allowing you to unload distant chunks but still draw them
//it's also faster to look up adjacent chunk positions when you have the position
glm::ivec3 mLinkedChunkPos;
World& mLinkedWorld;

unsigned mVAO;
unsigned mGemetryTexVBO;
unsigned mLightVBO;
};
}

+ 2
- 0
include/world.h View File

@@ -43,6 +43,8 @@ public:
bool makeChunk(const int& x, const int& y, const int& z);
bool generateChunk(const int& x, const int& y, const int& z);

Chunk* getChunk(const glm::ivec3& pos);

void queueChunkUpdate(const int& x, const int& y, const int& z);
void queueChunkUpdate(const iPos& pos);


+ 14
- 2
src/graphics/chunkgeometry.cpp View File

@@ -1,9 +1,21 @@
#include <vector>

#include "graphics/chunkgeometry.h"

namespace vtk {

void draw(RenderTask& task) {
void ChunkGeometry::draw(RenderTask& task) {
}

void ChunkGeometry::buildGeometry(Chunk& chunk) {
}

void ChunkGeometry::buildVertices(Chunk& chunk) {

}

void ChunkGeometry::buildLighting(Chunk& chunk) {

}

} //namespace vtk

+ 82
- 0
src/graphics/chunkmesh.cpp View File

@@ -0,0 +1,82 @@
#include "graphics/chunkmesh.h"
#include "world.h"

namespace vtk {
ChunkMesh::ChunkMesh(World& world, glm::ivec3 chunkPos) :
mLinkedWorld(world),
mLinkedChunkPos(chunkPos)
{
}

void ChunkMesh::rebuildChunkGeometry(const unsigned& vao) {
//get the chunk from position
auto chunk = mLinkedWorld.getChunk(mLinkedChunkPos);

//temporary until I finish mesh providers
float textUV [] = {
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 0.0f,
1.0f, 1.0f
};
float topModel [] = {
//x y z
0.0f, 1.0f, 0.0f, //tl
1.0f, 1.0f, 0.0f, //tr
0.0f, 1.0f, 1.0f, //bl
1.0f, 1.0f, 1.0f, //br
0.0f, 1.0f, 1.0f, //bl
1.0f, 1.0f, 0.0f //tr
};
float bottomModel [] = {
//x y z u v
0.0f, 0.0f, 1.0f, //tl
1.0f, 0.0f, 1.0f, //tr
0.0f, 0.0f, 0.0f, //bl
1.0f, 0.0f, 0.0f, //br
0.0f, 0.0f, 1.0f, //bl
1.0f, 0.0f, 1.0f //tr
};
float northModel [] = {
//x y z u v
0.0f, 1.0f, 1.0f, //tl
1.0f, 1.0f, 1.0f, //tr
0.0f, 1.0f, 1.0f, //bl
1.0f, 0.0f, 1.0f, //br
0.0f, 0.0f, 1.0f, //bl
1.0f, 1.0f, 1.0f //tr
};
float southModel [] = {
//x y z u v
1.0f, 1.0f, 0.0f, //tl
0.0f, 1.0f, 0.0f, //tr
1.0f, 0.0f, 0.0f, //bl
0.0f, 0.0f, 0.0f, //br
1.0f, 0.0f, 0.0f, //bl
0.0f, 1.0f, 0.0f //tr
};
float eastModel [] = {
//x y z u v
1.0f, 1.0f, 1.0f, //tl
1.0f, 1.0f, 0.0f, //tr
1.0f, 0.0f, 1.0f, //bl
1.0f, 0.0f, 0.0f, //br
1.0f, 0.0f, 1.0f, //bl
1.0f, 1.0f, 0.0f //tr
};
float westModel [] = {
//x y z u v
0.0f, 1.0f, 0.0f, //tl
0.0f, 1.0f, 1.0f, //tr
0.0f, 0.0f, 0.0f, //bl
0.0f, 0.0f, 1.0f, //br
0.0f, 0.0f, 0.0f, //bl
0.0f, 1.0f, 1.0f //tr
};
}
void ChunkMesh::rebuildChunkLighting(const unsigned& vao) {

}
}

+ 4
- 6
src/scenes/testscene.cpp View File

@@ -105,8 +105,6 @@ void TestScene::init() {
handler.getEventSignal(SDL_QUIT ).connect<Game , &Game::stop >(linkedGame);
handler.getEventSignal(SDL_MOUSEMOTION).connect<TestScene, &TestScene::look>(this);



world.voxelInfo.setTextureData(1, Face3D::RIGHT, Orientation2D::UP, 0.0f);
world.voxelInfo.setTextureData(1, Face3D::LEFT, Orientation2D::UP, 0.0f);
world.voxelInfo.setTextureData(1, Face3D::TOP, Orientation2D::UP, 0.0f);
@@ -186,17 +184,17 @@ void TestScene::update(const float& dTime) {
}

void TestScene::draw() {
mSkyboxTask->draw();
mSkyboxTask->draw();

gls::setShader(shaders);
gls::setShader(shaders);
glUniformMatrix4fv(viewMatUni, 1, GL_FALSE, glm::value_ptr(camera.getViewMatrix()));
world.draw();
glDisable(GL_DEPTH_TEST);
mCursorShader.activate();
mCursorShader.activate();
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 6);
glEnable(GL_DEPTH_TEST);
glEnable(GL_DEPTH_TEST);
}

void TestScene::look() {

+ 5
- 0
src/world.cpp View File

@@ -113,6 +113,11 @@ bool World::generateChunk(const int& x, const int& y, const int& z) {
return chunkMade;
}


Chunk* World::getChunk(const glm::ivec3& pos) {
return chunks[std::make_tuple(pos.x, pos.y, pos.z)];
}
void World::queueChunkUpdate(const int& x, const int& y, const int& z) {
queueChunkUpdate(std::make_tuple(x,y,z));
}

Loading…
Cancel
Save