Browse Source

began mesher rework

testing
Michael Porter 5 years ago
parent
commit
9dad2ea38b
  1. 1907
      comp.txt
  2. 2
      include/graphics/chunkgeometry.h
  3. 28
      include/graphics/chunkmesh.h
  4. 2
      include/world.h
  5. 16
      src/graphics/chunkgeometry.cpp
  6. 82
      src/graphics/chunkmesh.cpp
  7. 10
      src/scenes/testscene.cpp
  8. 5
      src/world.cpp

1907
comp.txt

File diff suppressed because it is too large Load Diff

2
include/graphics/chunkgeometry.h

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

28
include/graphics/chunkmesh.h

@ -0,0 +1,28 @@ @@ -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
include/world.h

@ -43,6 +43,8 @@ public: @@ -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);

16
src/graphics/chunkgeometry.cpp

@ -1,9 +1,21 @@ @@ -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
src/graphics/chunkmesh.cpp

@ -0,0 +1,82 @@ @@ -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) {
}
}

10
src/scenes/testscene.cpp

@ -105,8 +105,6 @@ void TestScene::init() { @@ -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) { @@ -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
src/world.cpp

@ -113,6 +113,11 @@ bool World::generateChunk(const int& x, const int& y, const int& z) { @@ -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