mirror of https://github.com/auygun/kaliber.git
enable/disable depth test.
This commit is contained in:
parent
68b6b1dfea
commit
e669f2b474
|
@ -27,7 +27,7 @@ bool SkyQuad::Create() {
|
|||
if (!source->Load("sky.glsl"))
|
||||
return false;
|
||||
shader_->Create(std::move(source), engine.GetQuad()->vertex_description(),
|
||||
Engine::Get().GetQuad()->primitive());
|
||||
Engine::Get().GetQuad()->primitive(), false);
|
||||
|
||||
scale_ = engine.GetScreenSize();
|
||||
|
||||
|
|
|
@ -479,7 +479,7 @@ bool Engine::CreateRenderResources() {
|
|||
return false;
|
||||
}
|
||||
pass_through_shader_->Create(std::move(source), quad_->vertex_description(),
|
||||
quad_->primitive());
|
||||
quad_->primitive(), false);
|
||||
|
||||
// Create the shader we can reuse for solid rendering.
|
||||
source = std::make_unique<ShaderSource>();
|
||||
|
@ -488,7 +488,7 @@ bool Engine::CreateRenderResources() {
|
|||
return false;
|
||||
}
|
||||
solid_shader_->Create(std::move(source), quad_->vertex_description(),
|
||||
quad_->primitive());
|
||||
quad_->primitive(), false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -80,6 +80,7 @@ RENDER_COMMAND_BEGIN(CmdCreateShader)
|
|||
std::unique_ptr<ShaderSource> source;
|
||||
VertexDescripton vertex_description;
|
||||
std::shared_ptr<void> impl_data;
|
||||
bool enable_depth_test;
|
||||
RENDER_COMMAND_END
|
||||
|
||||
RENDER_COMMAND_BEGIN(CmdDestroyShader)
|
||||
|
|
|
@ -88,11 +88,13 @@ void RendererOpenGL::ActivateTexture(std::shared_ptr<void> impl_data) {
|
|||
void RendererOpenGL::CreateShader(std::shared_ptr<void> impl_data,
|
||||
std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vertex_description,
|
||||
Primitive primitive) {
|
||||
Primitive primitive,
|
||||
bool enable_depth_test) {
|
||||
auto cmd = std::make_unique<CmdCreateShader>();
|
||||
cmd->source = std::move(source);
|
||||
cmd->vertex_description = vertex_description;
|
||||
cmd->impl_data = impl_data;
|
||||
cmd->enable_depth_test = enable_depth_test;
|
||||
EnqueueCommand(std::move(cmd));
|
||||
}
|
||||
|
||||
|
@ -726,7 +728,7 @@ void RendererOpenGL::HandleCmdCreateShader(RenderCommand* cmd) {
|
|||
}
|
||||
}
|
||||
|
||||
*impl_data = {id, {}};
|
||||
*impl_data = {id, {}, c->enable_depth_test};
|
||||
}
|
||||
|
||||
void RendererOpenGL::HandleCmdDestroyShader(RenderCommand* cmd) {
|
||||
|
@ -744,6 +746,10 @@ void RendererOpenGL::HandleCmdActivateShader(RenderCommand* cmd) {
|
|||
if (impl_data->id > 0 && impl_data->id != active_shader_id_) {
|
||||
glUseProgram(impl_data->id);
|
||||
active_shader_id_ = impl_data->id;
|
||||
if (impl_data->enable_depth_test)
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
else
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,8 @@ class RendererOpenGL : public Renderer {
|
|||
void CreateShader(std::shared_ptr<void> impl_data,
|
||||
std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vertex_description,
|
||||
Primitive primitive) override;
|
||||
Primitive primitive,
|
||||
bool enable_depth_test) override;
|
||||
void DestroyShader(std::shared_ptr<void> impl_data) override;
|
||||
void ActivateShader(std::shared_ptr<void> impl_data) override;
|
||||
|
||||
|
@ -122,6 +123,7 @@ class RendererOpenGL : public Renderer {
|
|||
struct ShaderOpenGL {
|
||||
GLuint id = 0;
|
||||
std::unordered_map<std::string, GLuint> uniforms;
|
||||
bool enable_depth_test = false;
|
||||
};
|
||||
|
||||
struct TextureOpenGL {
|
||||
|
|
|
@ -53,7 +53,8 @@ class Renderer {
|
|||
virtual void CreateShader(std::shared_ptr<void> impl_data,
|
||||
std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vertex_description,
|
||||
Primitive primitive) = 0;
|
||||
Primitive primitive,
|
||||
bool enable_depth_test) = 0;
|
||||
virtual void DestroyShader(std::shared_ptr<void> impl_data) = 0;
|
||||
virtual void ActivateShader(std::shared_ptr<void> impl_data) = 0;
|
||||
|
||||
|
|
|
@ -18,10 +18,12 @@ Shader::~Shader() {
|
|||
|
||||
void Shader::Create(std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vd,
|
||||
Primitive primitive) {
|
||||
Primitive primitive,
|
||||
bool enable_depth_test) {
|
||||
Destroy();
|
||||
valid_ = true;
|
||||
renderer_->CreateShader(impl_data_, std::move(source), vd, primitive);
|
||||
renderer_->CreateShader(impl_data_, std::move(source), vd, primitive,
|
||||
enable_depth_test);
|
||||
}
|
||||
|
||||
void Shader::Destroy() {
|
||||
|
|
|
@ -22,7 +22,8 @@ class Shader : public RenderResource {
|
|||
|
||||
void Create(std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vd,
|
||||
Primitive primitive);
|
||||
Primitive primitive,
|
||||
bool enable_depth_test);
|
||||
|
||||
void Destroy() override;
|
||||
|
||||
|
|
|
@ -394,7 +394,8 @@ void RendererVulkan::ActivateTexture(std::shared_ptr<void> impl_data) {
|
|||
void RendererVulkan::CreateShader(std::shared_ptr<void> impl_data,
|
||||
std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vertex_description,
|
||||
Primitive primitive) {
|
||||
Primitive primitive,
|
||||
bool enable_depth_test) {
|
||||
auto shader = reinterpret_cast<ShaderVulkan*>(impl_data.get());
|
||||
|
||||
auto it = spirv_cache_.find(source->name());
|
||||
|
@ -536,8 +537,8 @@ void RendererVulkan::CreateShader(std::shared_ptr<void> impl_data,
|
|||
VkPipelineDepthStencilStateCreateInfo depth_stencil{};
|
||||
depth_stencil.sType =
|
||||
VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
|
||||
depth_stencil.depthTestEnable = VK_TRUE;
|
||||
depth_stencil.depthWriteEnable = VK_TRUE;
|
||||
depth_stencil.depthTestEnable = enable_depth_test ? VK_TRUE : VK_FALSE;
|
||||
depth_stencil.depthWriteEnable = enable_depth_test ? VK_TRUE : VK_FALSE;
|
||||
depth_stencil.depthCompareOp = VK_COMPARE_OP_LESS;
|
||||
depth_stencil.depthBoundsTestEnable = VK_FALSE;
|
||||
depth_stencil.stencilTestEnable = VK_FALSE;
|
||||
|
|
|
@ -46,7 +46,8 @@ class RendererVulkan : public Renderer {
|
|||
void CreateShader(std::shared_ptr<void> impl_data,
|
||||
std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vertex_description,
|
||||
Primitive primitive) override;
|
||||
Primitive primitive,
|
||||
bool enable_depth_test) override;
|
||||
void DestroyShader(std::shared_ptr<void> impl_data) override;
|
||||
void ActivateShader(std::shared_ptr<void> impl_data) override;
|
||||
|
||||
|
|
Loading…
Reference in New Issue