-Subproject commit 7f1ebb8448f866ac28ea14b0dd8792edebedcf5a
+Subproject commit b965c835cce06d762c9741f42dee34809bbf6a08
, chunk_renderer(*interface.GetPlayer().chunks)
, skeletons()
, spawner(world, skeletons, gc.seed)
+, sky(env.loader.LoadCubeMap("skybox"))
, preload(env, chunk_loader, chunk_renderer)
, unload(env, world.Chunks(), save) {
TextureIndex tex_index;
viewport.WorldPosition(player.Transform(player.ChunkCoords()));
chunk_renderer.Render(viewport);
world.Render(viewport);
+ sky.Render(viewport);
+
interface.Render(viewport);
}
#include "State.hpp"
#include "UnloadState.hpp"
#include "../ai/Spawner.hpp"
+#include "../graphics/SkyBox.hpp"
#include "../model/Skeletons.hpp"
#include "../ui/Interface.hpp"
#include "../world/BlockTypeRegistry.hpp"
Skeletons skeletons;
Spawner spawner;
+ SkyBox sky;
+
PreloadState preload;
UnloadState unload;
--- /dev/null
+#ifndef BLANK_GRAPHICS_SKYBOX_HPP_
+#define BLANK_GRAPHICS_SKYBOX_HPP_
+
+#include "CubeMap.hpp"
+#include "../model/SkyBoxModel.hpp"
+
+
+namespace blank {
+
+class Viewport;
+
+class SkyBox {
+
+public:
+ explicit SkyBox(CubeMap &&);
+
+ void Render(Viewport &) noexcept;
+
+private:
+ CubeMap texture;
+ SkyBoxModel model;
+
+};
+
+}
+
+#endif
void SetTexture(CubeMap &) noexcept;
- void SetM(const glm::mat4 &m) noexcept;
void SetProjection(const glm::mat4 &p) noexcept;
void SetView(const glm::mat4 &v) noexcept;
void SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept;
- void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept;
const glm::mat4 &Projection() const noexcept { return projection; }
const glm::mat4 &View() const noexcept { return view; }
glm::mat4 view;
glm::mat4 vp;
- GLuint m_handle;
- GLuint mv_handle;
- GLuint mvp_handle;
+ GLuint vp_handle;
GLuint sampler_handle;
};
SkyBoxShader::SkyBoxShader()
: program()
, vp(1.0f)
-, m_handle(0)
-, mv_handle(0)
-, mvp_handle(0)
+, vp_handle(0)
, sampler_handle(0) {
program.LoadShader(
GL_VERTEX_SHADER,
"#version 330 core\n"
"layout(location = 0) in vec3 vtx_position;\n"
- "uniform mat4 M;\n"
- "uniform mat4 MV;\n"
- "uniform mat4 MVP;\n"
+ "uniform mat4 VP;\n"
"out vec3 vtx_viewspace;\n"
"void main() {\n"
- "gl_Position = MVP * vec4(vtx_position, 1);\n"
+ "gl_Position = VP * vec4(vtx_position, 1);\n"
"gl_Position.z = gl_Position.w;\n"
- "vtx_viewspace = (MV * vec4(vtx_position, 1)).xyz;\n"
+ "vtx_viewspace = vtx_position;\n"
"}\n"
);
program.LoadShader(
throw std::runtime_error("link program");
}
- m_handle = program.UniformLocation("M");
- mv_handle = program.UniformLocation("MV");
- mvp_handle = program.UniformLocation("MVP");
+ vp_handle = program.UniformLocation("VP");
sampler_handle = program.UniformLocation("tex_sampler");
}
program.Use();
}
-void SkyBoxShader::SetM(const glm::mat4 &M) noexcept {
- glm::mat4 m(M);
- m[0].w = 0.0f;
- m[1].w = 0.0f;
- m[2].w = 0.0f;
- m[3] = { 0.0f, 0.0f, 0.0f, 1.0f };
- program.Uniform(m_handle, m);
- program.Uniform(mv_handle, view * m);
- program.Uniform(mvp_handle, vp * m);
-}
-
void SkyBoxShader::SetTexture(CubeMap &tex) noexcept {
glActiveTexture(GL_TEXTURE0);
tex.Bind();
void SkyBoxShader::SetProjection(const glm::mat4 &p) noexcept {
projection = p;
vp = p * view;
+ program.Uniform(vp_handle, vp);
}
void SkyBoxShader::SetView(const glm::mat4 &v) noexcept {
view[0].w = 0.0f;
view[1].w = 0.0f;
view[2].w = 0.0f;
- view[3] = { 0.0f, 0.0f, 0.0f, 1.0f };
+ view[3] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
vp = projection * v;
+ program.Uniform(vp_handle, vp);
}
void SkyBoxShader::SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept {
SetView(v);
}
-void SkyBoxShader::SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept {
- SetVP(v, p);
- SetM(m);
-}
-
PlainColor::PlainColor()
: program()
#include "Camera.hpp"
#include "Canvas.hpp"
+#include "SkyBox.hpp"
#include "Viewport.hpp"
#include "../app/init.hpp"
}
+SkyBox::SkyBox(CubeMap &&tex)
+: texture(std::move(tex))
+, model() {
+ model.LoadUnitBox();
+}
+
+void SkyBox::Render(Viewport &viewport) noexcept {
+ SkyBoxShader &prog = viewport.SkyBoxProgram();
+ prog.SetTexture(texture);
+ model.Draw();
+}
+
+
Viewport::Viewport()
: cam()
, canv()
} else {
entity_prog.SetProjection(Perspective());
}
+ sky_prog.SetProjection(Perspective());
sprite_prog.SetProjection(Ortho());
}
if (active_prog != SKY_BOX) {
sky_prog.Activate();
DisableBlending();
+ DisableBackfaceCulling();
EqualDepthTest();
active_prog = SKY_BOX;
}
void Viewport::WorldPosition(const glm::mat4 &t) noexcept {
cam.View(glm::inverse(t));
chunk_prog.SetView(cam.View());
+ sky_prog.SetView(cam.View());
}
}