Browse Source

minor cleanup

testing
totallyfake 2 years ago
parent
commit
6d6ba5da6c
2 changed files with 13 additions and 185 deletions
  1. 12
    172
      src/graphics/chunkmesh.cpp
  2. 1
    13
      src/terraingen.cpp

+ 12
- 172
src/graphics/chunkmesh.cpp View File

@@ -37,89 +37,21 @@ ChunkMesh::ChunkMesh(World& world, glm::ivec3 chunkPos) :

glVertexAttribIPointer(1, 1, GL_UNSIGNED_INT, GL_FALSE, 0);
glEnableVertexAttribArray(1);

//tex uv coords
//glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 4*sizeof(unsigned), (void*)(1*sizeof(unsigned)));
//glEnableVertexAttribArray(1);
}

void ChunkMesh::rebuildChunkGeometry() {
// check if it's currently rebuilding
if (mLocked) return;
mLocked = true;

//get the chunk from position
auto chunk = mLinkedWorld.getChunk(mLinkedChunkPos);
//temporary until I finish mesh providers
float texUV [] = {
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, 0.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, 0.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
};
// geometry format: x,y,z,u,v,i
geometry.clear();
mGeometry.clear();
mFaceAttribs.clear();
mFaceCount = 0;
int chunkSize = 16; // TODO: make this not hardcoded

int chunkSize = 16;
for (int i = 0; i < chunkSize; ++i) {
for (int j = 0; j < chunkSize; ++j) {
@@ -153,104 +85,6 @@ void ChunkMesh::rebuildChunkGeometry() {
}
}
}
/*
for (int i = 0; i < chunkSize; ++i) {
for (int j = 0; j < chunkSize; ++j) {
for (int k = 0; k < chunkSize; ++k) {
//for each voxel in the chunk...
// TODO: move this code into a mesh provider system

//top
if (chunk->isVoxelSolid(i,j,k)) { //check that it's solid
if (!chunk->isVoxelSolid(i, j + 1, k)) {
++mFaceCount;
for (int l = 0; l < 6; ++l) {
geometry.push_back(topModel[(l * 3)] + (float)i);
geometry.push_back(topModel[(l * 3) + 1] + (float)j);
geometry.push_back(topModel[(l * 3) + 2] + (float)k);
geometry.push_back(texUV[l*2]);
geometry.push_back(texUV[(l*2)+1]);
geometry.push_back(mLinkedWorld.voxelInfo.getTexIndexFromID(2, Face3D::TOP));
}
}
}

//bottom
if (chunk->isVoxelSolid(i,j,k)) { //check that it's solid
if (!chunk->isVoxelSolid(i, j - 1, k)) {
++mFaceCount;
for (int l = 0; l < 6; ++l) {
geometry.push_back(bottomModel[(l * 3)] + (float)i);
geometry.push_back(bottomModel[(l * 3) + 1] + (float)j);
geometry.push_back(bottomModel[(l * 3) + 2] + (float)k);
geometry.push_back(texUV[l*2]);
geometry.push_back(texUV[(l*2)+1]);
geometry.push_back(mLinkedWorld.voxelInfo.getTexIndexFromID(2, Face3D::TOP));
}
}
}

//north
if (chunk->isVoxelSolid(i,j,k)) { //check that it's solid
if (!chunk->isVoxelSolid(i, j, k + 1)) {
++mFaceCount;
for (int l = 0; l < 6; ++l) {
geometry.push_back(northModel[(l * 3)] + (float)i);
geometry.push_back(northModel[(l * 3) + 1] + (float)j);
geometry.push_back(northModel[(l * 3) + 2] + (float)k);
geometry.push_back(texUV[l*2]);
geometry.push_back(texUV[(l*2)+1]);
geometry.push_back(mLinkedWorld.voxelInfo.getTexIndexFromID(2, Face3D::TOP));
}
}
}
//south
if (chunk->isVoxelSolid(i,j,k)) { //check that it's solid
if (!chunk->isVoxelSolid(i, j, k - 1)) {
++mFaceCount;
for (int l = 0; l < 6; ++l) {
geometry.push_back(southModel[(l * 3)] + (float)i);
geometry.push_back(southModel[(l * 3) + 1] + (float)j);
geometry.push_back(southModel[(l * 3) + 2] + (float)k);
geometry.push_back(texUV[l*2]);
geometry.push_back(texUV[(l*2)+1]);
geometry.push_back(mLinkedWorld.voxelInfo.getTexIndexFromID(2, Face3D::TOP));
}
}
}
//east
if (chunk->isVoxelSolid(i,j,k)) { //check that it's solid
if (!chunk->isVoxelSolid(i + 1, j, k)) {
++mFaceCount;
for (int l = 0; l < 6; ++l) {
geometry.push_back(eastModel[(l * 3)] + (float)i);
geometry.push_back(eastModel[(l * 3) + 1] + (float)j);
geometry.push_back(eastModel[(l * 3) + 2] + (float)k);
geometry.push_back(texUV[l*2]);
geometry.push_back(texUV[(l*2)+1]);
geometry.push_back(mLinkedWorld.voxelInfo.getTexIndexFromID(2, Face3D::TOP));
}
}
}

//west
if (chunk->isVoxelSolid(i,j,k)) { //check that it's solid
if (!chunk->isVoxelSolid(i - 1, j, k)) {
++mFaceCount;
for (int l = 0; l < 6; ++l) {
geometry.push_back(westModel[(l * 3)] + (float)i);
geometry.push_back(westModel[(l * 3) + 1] + (float)j);
geometry.push_back(westModel[(l * 3) + 2] + (float)k);
geometry.push_back(texUV[l*2]);
geometry.push_back(texUV[(l*2)+1]);
geometry.push_back(mLinkedWorld.voxelInfo.getTexIndexFromID(2, Face3D::TOP));
}
}
}
}
}
}
*/
mUpdated = true;
mLocked = false;
}
@@ -271,11 +105,17 @@ bool ChunkMesh::updateGeometry() {
if (mUpdated) {
mUpdated = false;
glBindBuffer(GL_ARRAY_BUFFER, mGeometryTexVBO);
//glBufferData(GL_ARRAY_BUFFER, sizeof(float) * geometry.size(), geometry.data(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned) * mGeometry.size(), mGeometry.data(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER,
sizeof(unsigned) * mGeometry.size(),
mGeometry.data(),
GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, mFaceAttribsVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned) * mFaceAttribs.size(), mFaceAttribs.data(), GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER,
sizeof(unsigned) * mFaceAttribs.size(),
mFaceAttribs.data(),
GL_STATIC_DRAW);

mGeometryFaceCount = mFaceCount;
return true;
}

+ 1
- 13
src/terraingen.cpp View File

@@ -32,7 +32,7 @@ namespace vtk {
TerrainGen::TerrainGen() {
std::shared_ptr<noise::NoiseModule> noise = std::make_shared<noise::Noise>(6969696);
std::shared_ptr<noise::NoiseModule> yGrad = std::make_shared<noise::YGradient>(0.0, 128.0);
mNoise = std::make_shared<noise::YTurbulence>(yGrad, noise, 40.0);
mNoise = std::make_shared<noise::YTurbulence>(yGrad, noise, 60.0);

mTerrainScale = 32.0;
}
@@ -52,18 +52,6 @@ void TerrainGen::generateChunk(Chunk* chunk) {
} else {
chunk->setVoxelType(i,j,k,0);
}
/*
glm::dvec3 pos((double)(chunk->chunkPos.x * 16 + i) * terrainScale,
(double)(chunk->chunkPos.y * 16 + j) * terrainScale,
(double)(chunk->chunkPos.z * 16 + k) * terrainScale);
if (selectorMod.GetValue(pos.x, pos.y, pos.z) <= 0.0) {
if (selectorMod.GetValue(pos.x, (double)(chunk->chunkPos.y * 16 + j + 1) * terrainScale, pos.z) >= 0.0) {
chunk->setVoxelType(i,j,k,2);
} else {
chunk->setVoxelType(i,j,k,1);
}
}
*/
}
}
}

Loading…
Cancel
Save