summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/GalOgl.cpp2
-rw-r--r--src/Render.cpp7
-rw-r--r--src/RenderConfigs.cpp1
-rw-r--r--src/RenderConfigs.hpp7
-rw-r--r--src/RendererEntity.cpp2
-rw-r--r--src/RendererWorld.cpp43
-rw-r--r--src/Rml.cpp11
7 files changed, 28 insertions, 45 deletions
diff --git a/src/GalOgl.cpp b/src/GalOgl.cpp
index 854ab40..961c6ef 100644
--- a/src/GalOgl.cpp
+++ b/src/GalOgl.cpp
@@ -1049,6 +1049,8 @@ struct ImplOgl : public Impl {
throw std::runtime_error("GLEW initialization failed with unknown reason");
}
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
GLint flags;
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
if (flags & GL_CONTEXT_FLAG_DEBUG_BIT)
diff --git a/src/Render.cpp b/src/Render.cpp
index 8a5253c..682b60a 100644
--- a/src/Render.cpp
+++ b/src/Render.cpp
@@ -172,8 +172,8 @@ void Render::PrepareToRendering() {
fbPPC->SetPixelShader(gal->LoadPixelShader(pixelSource));
fbPPC->AddStaticTexture("inputTexture", gbuffer->GetFinalTexture());
auto fbColorBB = fbPPC->BindVertexBuffer({
- {"Pos", Gal::Type::Vec2},
- {"TextureCoords", Gal::Type::Vec2}
+ {"pos", Gal::Type::Vec2},
+ {"uvPos", Gal::Type::Vec2}
});
fbPipeline = gal->BuildPipeline(fbPPC);
@@ -213,7 +213,6 @@ void Render::RenderFrame() {
Gal::GetImplementation()->SetWireframe(true);
if (renderWorld) {
world->Render(static_cast<float>(windowWidth) / static_cast<float>(windowHeight));
- gbuffer->SetDayTime(world->shaderDayTime);
}
if (isWireframe)
Gal::GetImplementation()->SetWireframe(false);
@@ -256,6 +255,7 @@ void Render::HandleEvents() {
windowHeight = height;
rmlRender->Update(width, height);
rmlContext->SetDimensions(Rml::Vector2i(width, height));
+ Gal::GetImplementation()->GetGlobalShaderParameters()->Get<GlobalShaderParameters>()->viewportSize = glm::uvec2(width, height);
PrepareToRendering();
break;
}
@@ -613,6 +613,7 @@ void Render::InitRml() {
rmlRender = std::make_unique<RmlRenderInterface>();
Rml::SetRenderInterface(rmlRender.get());
rmlRender->Update(windowWidth, windowHeight);
+ Gal::GetImplementation()->GetGlobalShaderParameters()->Get<GlobalShaderParameters>()->viewportSize = glm::uvec2(windowWidth, windowHeight);
rmlFile = std::make_unique<RmlFileInterface>();
Rml::SetFileInterface(rmlFile.get());
diff --git a/src/RenderConfigs.cpp b/src/RenderConfigs.cpp
index d62d204..aad2c59 100644
--- a/src/RenderConfigs.cpp
+++ b/src/RenderConfigs.cpp
@@ -124,7 +124,6 @@ Gbuffer::Gbuffer(size_t geomW, size_t geomH, size_t lightW, size_t lightH) {
};
std::vector<std::pair<std::string_view, Gal::Type>> lightingParameters = {
- {"dayTime", Gal::Type::Float},
{"renderBuff", Gal::Type::Int32},
};
diff --git a/src/RenderConfigs.hpp b/src/RenderConfigs.hpp
index a9d6c00..da7fd96 100644
--- a/src/RenderConfigs.hpp
+++ b/src/RenderConfigs.hpp
@@ -4,6 +4,9 @@
struct GlobalShaderParameters {
glm::mat4 projView;
+ glm::uvec2 viewportSize;
+ float globalTime;
+ float dayTime;
};
std::shared_ptr<Gal::Shader> LoadVertexShader(std::string_view assetPath);
@@ -76,10 +79,6 @@ public:
lightingPass->Clear();
}
- void SetDayTime(float dayTime) {
- lightingPass->SetShaderParameter("dayTime", dayTime);
- }
-
int GetMaxRenderBuffers() {
return 5;
}
diff --git a/src/RendererEntity.cpp b/src/RendererEntity.cpp
index 02a5f54..d014bdb 100644
--- a/src/RendererEntity.cpp
+++ b/src/RendererEntity.cpp
@@ -18,5 +18,5 @@ void RendererEntity::Render(std::shared_ptr<Gal::Pipeline> pipeline, const World
model = glm::scale(model, glm::vec3(entity.width, entity.height, entity.width));
pipeline->SetShaderParameter("model", model);
- pipeline->SetShaderParameter("color", entity.renderColor);
+ pipeline->SetShaderParameter("entityColor", entity.renderColor);
}
diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp
index 2434ed1..c6d490a 100644
--- a/src/RendererWorld.cpp
+++ b/src/RendererWorld.cpp
@@ -256,10 +256,9 @@ RendererWorld::RendererWorld(std::shared_ptr<Gal::Framebuffer> target) {
sections.erase(it);
});
- listener->RegisterHandler("SetMinLightLevel", [this](const Event& eventData) {
- auto value = eventData.get<float>();
- sectionsPipeline->SetShaderParameter("MinLightLevel", value);
- });
+ listener->RegisterHandler("SetMinLightLevel", [this](const Event& eventData) {
+
+ });
for (int i = 0; i < numOfWorkers; i++)
workers.push_back(std::thread(&RendererWorld::WorkerFunction, this, i));
@@ -290,13 +289,12 @@ void RendererWorld::Render(float screenRatio) {
glm::mat4 view = GetGameState()->GetViewMatrix();
glm::mat4 projView = projection * view;
- Gal::GetImplementation()->GetGlobalShaderParameters()->Get<GlobalShaderParameters>()->projView = projView;
+ auto globalSpb = Gal::GetImplementation()->GetGlobalShaderParameters();
+ globalSpb->Get<GlobalShaderParameters>()->projView = projView;
//Render Entities
constexpr size_t entitiesVerticesCount = 240;
entitiesPipeline->Activate();
- entitiesPipeline->SetShaderParameter("projView", projView);
-
entitiesPipelineInstance->Activate();
for (auto& it : entities) {
it.Render(entitiesPipeline, &GetGameState()->GetWorld());
@@ -312,7 +310,7 @@ void RendererWorld::Render(float screenRatio) {
model = glm::translate(model,glm::vec3(0.5f,0.5f,0.5f));
model = glm::scale(model,glm::vec3(1.01f,1.01f,1.01f));
entitiesPipeline->SetShaderParameter("model", model);
- entitiesPipeline->SetShaderParameter("color", glm::vec3(0, 0, 0));
+ entitiesPipeline->SetShaderParameter("entityColor", glm::vec3(0, 0, 0));
entitiesPipelineInstance->Render(0, entitiesVerticesCount);
}
}
@@ -328,9 +326,9 @@ void RendererWorld::Render(float screenRatio) {
//entityShader->SetUniform("model", model);
entitiesPipeline->SetShaderParameter("model", model);
if (selectedBlock == Vector())
- entitiesPipeline->SetShaderParameter("color", glm::vec3(0.7f, 0.0f, 0.0f));
+ entitiesPipeline->SetShaderParameter("entityColor", glm::vec3(0.7f, 0.0f, 0.0f));
else
- entitiesPipeline->SetShaderParameter("color", glm::vec3(0.0f, 0.0f, 0.7f));
+ entitiesPipeline->SetShaderParameter("entityColor", glm::vec3(0.0f, 0.0f, 0.7f));
entitiesPipelineInstance->Render(0, entitiesVerticesCount);
}
}
@@ -369,12 +367,11 @@ void RendererWorld::Render(float screenRatio) {
float timePassed = (dayTime - moonriseMin);
mixLevel = 1.0 - (timePassed / moonriseLength);
}
- shaderDayTime = mixLevel;
+
+ globalSpb->Get<GlobalShaderParameters>()->dayTime = mixLevel;
skyPipeline->Activate();
- skyPipeline->SetShaderParameter("projView", projView);
skyPipeline->SetShaderParameter("model", model);
- skyPipeline->SetShaderParameter("DayTime", mixLevel);
skyPipelineInstance->Activate();
skyPipelineInstance->Render(0, 36);
@@ -382,10 +379,8 @@ void RendererWorld::Render(float screenRatio) {
//Render sections
auto rawGlobalTime = (std::chrono::high_resolution_clock::now() - globalTimeStart);
float globalTime = rawGlobalTime.count() / 1000000000.0f;
+ globalSpb->Get<GlobalShaderParameters>()->globalTime = globalTime;
sectionsPipeline->Activate();
- sectionsPipeline->SetShaderParameter("DayTime", mixLevel);
- sectionsPipeline->SetShaderParameter("projView", projView);
- sectionsPipeline->SetShaderParameter("GlobalTime", globalTime);
Frustum frustum(projView);
@@ -443,16 +438,12 @@ void RendererWorld::PrepareRender(std::shared_ptr<Gal::Framebuffer> target) {
{
auto sectionsPLC = gal->CreatePipelineConfig();
sectionsPLC->SetTarget(target);
- sectionsPLC->AddShaderParameter("projView", Gal::Type::Mat4);
- sectionsPLC->AddShaderParameter("DayTime", Gal::Type::Float);
- sectionsPLC->AddShaderParameter("GlobalTime", Gal::Type::Float);
- sectionsPLC->AddShaderParameter("MinLightLevel", Gal::Type::Float);
sectionsPLC->AddStaticTexture("textureAtlas", AssetManager::GetTextureAtlas());
sectionsPLC->SetVertexShader(gal->LoadVertexShader(sectionVertexSource));
sectionsPLC->SetPixelShader(gal->LoadPixelShader(sectionPixelSource));
sectionsPLC->SetPrimitive(Gal::Primitive::TriangleFan);
sectionsBufferBinding = sectionsPLC->BindVertexBuffer({
- {"position", Gal::Type::Vec3, 4, 1},
+ {"pos", Gal::Type::Vec3, 4, 1},
{"normal", Gal::Type::Vec3, 1, 1},
{"uv", Gal::Type::Vec2, 4, 1},
{"uvLayer", Gal::Type::Float, 1, 1},
@@ -462,20 +453,18 @@ void RendererWorld::PrepareRender(std::shared_ptr<Gal::Framebuffer> target) {
{"", Gal::Type::Uint8, 8, 1}
});
sectionsPipeline = gal->BuildPipeline(sectionsPLC);
- sectionsPipeline->SetShaderParameter("MinLightLevel", 0.2f);
}
{
auto entitiesPLC = gal->CreatePipelineConfig();
entitiesPLC->SetTarget(target);
- entitiesPLC->AddShaderParameter("projView", Gal::Type::Mat4);
entitiesPLC->AddShaderParameter("model", Gal::Type::Mat4);
- entitiesPLC->AddShaderParameter("color", Gal::Type::Vec3);
+ entitiesPLC->AddShaderParameter("entityColor", Gal::Type::Vec3);
entitiesPLC->SetVertexShader(gal->LoadVertexShader(entitiesVertexSource));
entitiesPLC->SetPixelShader(gal->LoadPixelShader(entitiesPixelSource));
entitiesPLC->SetPrimitive(Gal::Primitive::Triangle);
auto entitiesPosBB = entitiesPLC->BindVertexBuffer({
- {"position", Gal::Type::Vec3},
+ {"pos", Gal::Type::Vec3},
});
auto entitiesIndicesBB = entitiesPLC->BindIndexBuffer();
@@ -636,14 +625,12 @@ void RendererWorld::PrepareRender(std::shared_ptr<Gal::Framebuffer> target) {
skyPPC->AddShaderParameter("sunTextureLayer", Gal::Type::Float);
skyPPC->AddShaderParameter("moonTexture", Gal::Type::Vec4);
skyPPC->AddShaderParameter("moonTextureLayer", Gal::Type::Float);
- skyPPC->AddShaderParameter("DayTime", Gal::Type::Float);
- skyPPC->AddShaderParameter("projView", Gal::Type::Mat4);
skyPPC->AddShaderParameter("model", Gal::Type::Mat4);
skyPPC->AddStaticTexture("textureAtlas", AssetManager::GetTextureAtlas());
skyPPC->SetVertexShader(gal->LoadVertexShader(skyVertexSource));
skyPPC->SetPixelShader(gal->LoadPixelShader(skyPixelSource));
auto skyPosUvBB = skyPPC->BindVertexBuffer({
- {"position", Gal::Type::Vec3},
+ {"pos", Gal::Type::Vec3},
{"", Gal::Type::Vec2},
});
diff --git a/src/Rml.cpp b/src/Rml.cpp
index fa2d4e7..746f6a4 100644
--- a/src/Rml.cpp
+++ b/src/Rml.cpp
@@ -64,7 +64,6 @@ RmlRenderInterface::RmlRenderInterface() {
{
auto pipelineConfig = gal->CreatePipelineConfig();
- pipelineConfig->AddShaderParameter("viewportSize", Gal::Type::Vec2u32);
pipelineConfig->AddShaderParameter("translation", Gal::Type::Vec2);
pipelineConfig->SetTarget(gal->GetDefaultFramebuffer());
pipelineConfig->SetVertexShader(gal->LoadVertexShader(vertexSource));
@@ -72,7 +71,7 @@ RmlRenderInterface::RmlRenderInterface() {
auto vertBuffBind = pipelineConfig->BindVertexBuffer({
{"pos", Gal::Type::Vec2},
- {"color", Gal::Type::Vec4u8},
+ {"col", Gal::Type::Vec4u8},
{"", Gal::Type::Vec2}, //it's not used in shader, so driver optimizes it away
});
@@ -88,7 +87,6 @@ RmlRenderInterface::RmlRenderInterface() {
{
auto texPipelineConfig = gal->CreatePipelineConfig();
- texPipelineConfig->AddShaderParameter("viewportSize", Gal::Type::Vec2u32);
texPipelineConfig->AddShaderParameter("translation", Gal::Type::Vec2);
texPipelineConfig->AddShaderParameter("fontTexture", Gal::Type::Int32);
texPipelineConfig->SetTarget(gal->GetDefaultFramebuffer());
@@ -97,8 +95,8 @@ RmlRenderInterface::RmlRenderInterface() {
auto texVertBuffBind = texPipelineConfig->BindVertexBuffer({
{"pos", Gal::Type::Vec2},
- {"color", Gal::Type::Vec4u8},
- {"tex_coord", Gal::Type::Vec2},
+ {"col", Gal::Type::Vec4u8},
+ {"uvPos", Gal::Type::Vec2},
});
auto texIndexBuffBind = texPipelineConfig->BindIndexBuffer();
@@ -165,9 +163,6 @@ void RmlRenderInterface::ReleaseTexture(Rml::TextureHandle texture) {
}
void RmlRenderInterface::Update(unsigned int windowWidth, unsigned int windowHeight) {
- pipeline->SetShaderParameter("viewportSize", glm::uvec2(windowWidth, windowHeight));
- texPipeline->SetShaderParameter("viewportSize", glm::uvec2(windowWidth, windowHeight));
-
vpWidth = windowWidth;
vpHeight = windowHeight;
}