setMat4x4f uniform function
This commit is contained in:
parent
261b2540e0
commit
9582453dd1
@ -380,28 +380,20 @@ int main(int argc, char *argv[])
|
||||
projection = glm::perspective(glm::radians(camera.Zoom), windowX / windowY, 0.1f, 1000.0f);
|
||||
|
||||
shader.use();
|
||||
unsigned int viewLoc = glGetUniformLocation(shader.ID, "view");
|
||||
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));
|
||||
shader.setMat4x4f( "view", view );
|
||||
shader.setMat4x4f( "projection", projection );
|
||||
|
||||
waterShader.use();
|
||||
viewLoc = glGetUniformLocation(waterShader.ID, "view");
|
||||
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
|
||||
projectionLoc = glGetUniformLocation(waterShader.ID, "projection");
|
||||
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
|
||||
waterShader.setMat4x4f( "view", view );
|
||||
waterShader.setMat4x4f( "projection", projection );
|
||||
|
||||
billboardShader.use();
|
||||
viewLoc = glGetUniformLocation(billboardShader.ID, "view");
|
||||
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
|
||||
projectionLoc = glGetUniformLocation(billboardShader.ID, "projection");
|
||||
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
|
||||
billboardShader.setMat4x4f( "view", view );
|
||||
billboardShader.setMat4x4f( "projection", projection );
|
||||
|
||||
outlineShader.use();
|
||||
viewLoc = glGetUniformLocation(outlineShader.ID, "view");
|
||||
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
|
||||
projectionLoc = glGetUniformLocation(outlineShader.ID, "projection");
|
||||
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));
|
||||
outlineShader.setMat4x4f( "view", view );
|
||||
outlineShader.setMat4x4f( "projection", projection );
|
||||
|
||||
Planet::planet->Update(camera.Position);
|
||||
|
||||
@ -492,8 +484,7 @@ int main(int argc, char *argv[])
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_COLOR_LOGIC_OP);
|
||||
|
||||
unsigned int crosshairProjLoc = glGetUniformLocation(crosshairShader.ID, "projection");
|
||||
glUniformMatrix4fv(crosshairProjLoc, 1, GL_FALSE, glm::value_ptr(ortho));
|
||||
crosshairShader.setMat4x4f( "projection", ortho );
|
||||
glBindVertexArray(crosshairVAO);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
|
@ -519,18 +519,15 @@ void Chunk::Render(Shader* mainShader, Shader* billboardShader)
|
||||
|
||||
// Render main mesh
|
||||
mainShader->use();
|
||||
mainShader->setMat4x4f( "model", model );
|
||||
|
||||
modelLoc = glGetUniformLocation(mainShader->ID, "model");
|
||||
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
|
||||
|
||||
glBindVertexArray(mainVAO);
|
||||
glDrawElements(GL_TRIANGLES, numTrianglesMain, GL_UNSIGNED_INT, 0);
|
||||
|
||||
// Render billboard mesh
|
||||
billboardShader->use();
|
||||
|
||||
modelLoc = glGetUniformLocation(billboardShader->ID, "model");
|
||||
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
|
||||
billboardShader->setMat4x4f( "model", model );
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
glBindVertexArray(billboardVAO);
|
||||
@ -546,13 +543,12 @@ void Chunk::RenderWater(Shader* shader)
|
||||
//std::cout << "Rendering chunk " << chunkPos.x << ", " << chunkPos.y << ", " << chunkPos.z << '\n'
|
||||
// << "Chunk VAO: " << vertexArrayObject << '\n' << "Triangles: " << numTriangles << '\n';
|
||||
|
||||
modelLoc = glGetUniformLocation(shader->ID, "model");
|
||||
glBindVertexArray(waterVAO);
|
||||
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, worldPos);
|
||||
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
|
||||
|
||||
shader->setMat4x4f( "model", model );
|
||||
|
||||
glDrawElements(GL_TRIANGLES, numTrianglesWater, GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
||||
|
@ -106,8 +106,10 @@ 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())
|
||||
{
|
||||
chunkMutex.lock();
|
||||
delete it->second;
|
||||
it = chunkData.erase( it );
|
||||
chunkMutex.unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
@ -91,15 +93,22 @@ void Shader::use()
|
||||
glUseProgram(ID);
|
||||
}
|
||||
|
||||
void Shader::setBool(const std::string& name, bool value) const
|
||||
void Shader::setBool(const std::string& name, bool value)
|
||||
{
|
||||
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 ) );
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <glm/fwd.hpp>
|
||||
|
||||
class Shader
|
||||
{
|
||||
@ -13,7 +14,12 @@ public:
|
||||
// use/activate the shader
|
||||
void use();
|
||||
// utility uniform functions
|
||||
void setBool(const std::string& name, bool value) const;
|
||||
void setInt(const std::string& name, int value) const;
|
||||
void setFloat(const std::string& name, float value) const;
|
||||
void setBool(const std::string& name, bool value);
|
||||
void setInt(const std::string& name, int value);
|
||||
void setFloat(const std::string& name, float value);
|
||||
|
||||
void setMat4x4f( const std::string& name, const glm::mat4& matrix );
|
||||
|
||||
private:
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user