Compare commits

..

No commits in common. "ArgoreOfficial/main" and "main" have entirely different histories.

5 changed files with 49 additions and 60 deletions

View File

@ -380,20 +380,28 @@ int main(int argc, char *argv[])
projection = glm::perspective(glm::radians(camera.Zoom), windowX / windowY, 0.1f, 1000.0f); projection = glm::perspective(glm::radians(camera.Zoom), windowX / windowY, 0.1f, 1000.0f);
shader.use(); shader.use();
shader.setMat4x4f( "view", view ); unsigned int viewLoc = glGetUniformLocation(shader.ID, "view");
shader.setMat4x4f( "projection", projection ); glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
unsigned int projectionLoc = glGetUniformLocation(shader.ID, "projection");
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
waterShader.use(); waterShader.use();
waterShader.setMat4x4f( "view", view ); viewLoc = glGetUniformLocation(waterShader.ID, "view");
waterShader.setMat4x4f( "projection", projection ); glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
projectionLoc = glGetUniformLocation(waterShader.ID, "projection");
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
billboardShader.use(); billboardShader.use();
billboardShader.setMat4x4f( "view", view ); viewLoc = glGetUniformLocation(billboardShader.ID, "view");
billboardShader.setMat4x4f( "projection", projection ); glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
projectionLoc = glGetUniformLocation(billboardShader.ID, "projection");
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
outlineShader.use(); outlineShader.use();
outlineShader.setMat4x4f( "view", view ); viewLoc = glGetUniformLocation(outlineShader.ID, "view");
outlineShader.setMat4x4f( "projection", projection ); glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
projectionLoc = glGetUniformLocation(outlineShader.ID, "projection");
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
Planet::planet->Update(camera.Position); Planet::planet->Update(camera.Position);
@ -484,7 +492,8 @@ int main(int argc, char *argv[])
glEnable(GL_BLEND); glEnable(GL_BLEND);
glEnable(GL_COLOR_LOGIC_OP); glEnable(GL_COLOR_LOGIC_OP);
crosshairShader.setMat4x4f( "projection", ortho ); unsigned int crosshairProjLoc = glGetUniformLocation(crosshairShader.ID, "projection");
glUniformMatrix4fv(crosshairProjLoc, 1, GL_FALSE, glm::value_ptr(ortho));
glBindVertexArray(crosshairVAO); glBindVertexArray(crosshairVAO);
glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_TRIANGLES, 0, 6);

View File

@ -519,15 +519,18 @@ void Chunk::Render(Shader* mainShader, Shader* billboardShader)
// Render main mesh // Render main mesh
mainShader->use(); mainShader->use();
mainShader->setMat4x4f( "model", model );
modelLoc = glGetUniformLocation(mainShader->ID, "model");
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
glBindVertexArray(mainVAO); glBindVertexArray(mainVAO);
glDrawElements(GL_TRIANGLES, numTrianglesMain, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, numTrianglesMain, GL_UNSIGNED_INT, 0);
// Render billboard mesh // Render billboard mesh
billboardShader->use(); billboardShader->use();
billboardShader->setMat4x4f( "model", model );
modelLoc = glGetUniformLocation(billboardShader->ID, "model");
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
glBindVertexArray(billboardVAO); glBindVertexArray(billboardVAO);
@ -543,11 +546,12 @@ void Chunk::RenderWater(Shader* shader)
//std::cout << "Rendering chunk " << chunkPos.x << ", " << chunkPos.y << ", " << chunkPos.z << '\n' //std::cout << "Rendering chunk " << chunkPos.x << ", " << chunkPos.y << ", " << chunkPos.z << '\n'
// << "Chunk VAO: " << vertexArrayObject << '\n' << "Triangles: " << numTriangles << '\n'; // << "Chunk VAO: " << vertexArrayObject << '\n' << "Triangles: " << numTriangles << '\n';
modelLoc = glGetUniformLocation(shader->ID, "model");
glBindVertexArray(waterVAO); glBindVertexArray(waterVAO);
glm::mat4 model = glm::mat4(1.0f); glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, worldPos); model = glm::translate(model, worldPos);
shader->setMat4x4f( "model", model ); glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
glDrawElements(GL_TRIANGLES, numTrianglesWater, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, numTrianglesWater, GL_UNSIGNED_INT, 0);
} }

View File

@ -39,15 +39,13 @@ void Planet::Update(glm::vec3 cameraPos)
{ {
numChunks++; numChunks++;
Chunk& chunk = *it->second; if (!(*it->second).ready)
if (!chunk.ready)
chunksLoading++; chunksLoading++;
int chunkX = chunk.chunkPos.x; int chunkX = (*it->second).chunkPos.x;
int chunkY = chunk.chunkPos.y; int chunkY = (*it->second).chunkPos.y;
int chunkZ = chunk.chunkPos.z; int chunkZ = (*it->second).chunkPos.z;
if ( chunk.ready && (abs(chunkX - camChunkX) > renderDistance || if ((*it->second).ready && (abs(chunkX - camChunkX) > renderDistance ||
abs(chunkY - camChunkY) > renderDistance || abs(chunkY - camChunkY) > renderDistance ||
abs(chunkZ - camChunkZ) > renderDistance)) abs(chunkZ - camChunkZ) > renderDistance))
{ {
@ -62,13 +60,13 @@ void Planet::Update(glm::vec3 cameraPos)
chunkDataDeleteQueue.push({ chunkX, chunkY, chunkZ - 1 }); chunkDataDeleteQueue.push({ chunkX, chunkY, chunkZ - 1 });
// Delete chunk // Delete chunk
delete it->second; // &chunk delete it->second;
it = chunks.erase(it); it = chunks.erase(it);
} }
else else
{ {
numChunksRendered++; numChunksRendered++;
chunk.Render(solidShader, billboardShader); (*it->second).Render(solidShader, billboardShader);
++it; ++it;
} }
} }
@ -77,13 +75,11 @@ void Planet::Update(glm::vec3 cameraPos)
waterShader->use(); waterShader->use();
for (auto it = chunks.begin(); it != chunks.end(); ) for (auto it = chunks.begin(); it != chunks.end(); )
{ {
Chunk& chunk = *it->second; int chunkX = (*it->second).chunkPos.x;
int chunkY = (*it->second).chunkPos.y;
int chunkZ = (*it->second).chunkPos.z;
int chunkX = chunk.chunkPos.x; (*it->second).RenderWater(waterShader);
int chunkY = chunk.chunkPos.y;
int chunkZ = chunk.chunkPos.z;
chunk.RenderWater(waterShader);
++it; ++it;
} }
@ -106,16 +102,11 @@ void Planet::ChunkThreadUpdate()
chunks.find({ pos.x, pos.y, pos.z + 1 }) == chunks.end() && chunks.find({ pos.x, pos.y, pos.z + 1 }) == chunks.end() &&
chunks.find({ pos.x, pos.y, pos.z - 1 }) == chunks.end()) chunks.find({ pos.x, pos.y, pos.z - 1 }) == chunks.end())
{ {
chunkMutex.lock(); delete chunkData.at(pos);
delete it->second; chunkData.erase(pos);
it = chunkData.erase( it );
chunkMutex.unlock();
} }
else
{
++it; ++it;
} }
}
// Check if camera moved to new chunk // Check if camera moved to new chunk
if (camChunkX != lastCamX || camChunkY != lastCamY || camChunkZ != lastCamZ) if (camChunkX != lastCamX || camChunkY != lastCamY || camChunkZ != lastCamZ)

View File

@ -2,8 +2,6 @@
#include <glad/glad.h> #include <glad/glad.h>
#include <glm/gtc/type_ptr.hpp>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
@ -93,22 +91,15 @@ void Shader::use()
glUseProgram(ID); glUseProgram(ID);
} }
void Shader::setBool(const std::string& name, bool value) void Shader::setBool(const std::string& name, bool value) const
{ {
glUniform1i( glGetUniformLocation( ID, name.c_str() ), (int)value); glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value);
} }
void Shader::setInt(const std::string& name, int value) const
void Shader::setInt(const std::string& name, int value)
{ {
glUniform1i( glGetUniformLocation( ID, name.c_str() ), value); glUniform1i(glGetUniformLocation(ID, name.c_str()), value);
} }
void Shader::setFloat(const std::string& name, float value) const
void Shader::setFloat(const std::string& name, float value)
{ {
glUniform1f( glGetUniformLocation( ID, name.c_str() ), value); glUniform1f(glGetUniformLocation(ID, name.c_str()), value);
}
void Shader::setMat4x4f( const std::string& name, const glm::mat4& matrix )
{
glUniformMatrix4fv( glGetUniformLocation( ID, name.c_str() ), 1, GL_FALSE, glm::value_ptr( matrix ) );
} }

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <string> #include <string>
#include <glm/fwd.hpp>
class Shader class Shader
{ {
@ -14,12 +13,7 @@ public:
// use/activate the shader // use/activate the shader
void use(); void use();
// utility uniform functions // utility uniform functions
void setBool(const std::string& name, bool value); void setBool(const std::string& name, bool value) const;
void setInt(const std::string& name, int value); void setInt(const std::string& name, int value) const;
void setFloat(const std::string& name, float value); void setFloat(const std::string& name, float value) const;
void setMat4x4f( const std::string& name, const glm::mat4& matrix );
private:
}; };