1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

Introduce depth test render state

This commit is contained in:
Daniel Evans 2018-08-15 22:41:30 +01:00
parent 7337da3133
commit 2e472dd25c
2 changed files with 22 additions and 1 deletions

View File

@ -282,6 +282,7 @@ void OpenGLRenderer::setDrawState(const glm::mat4& model, DrawBuffer* draw,
setBlend(p.blendMode);
setDepthWrite(p.depthWrite);
setDepthMode(p.depthMode);
ObjectUniformData objectData{model,
glm::vec4(p.colour.r / 255.f, p.colour.g / 255.f,
@ -369,6 +370,7 @@ void OpenGLRenderer::invalidate() {
currentTextures.clear();
currentUBO = 0;
setBlend(BlendMode::BLEND_NONE);
setDepthMode(DepthMode::OFF);
}
bool OpenGLRenderer::createUBO(Buffer &out, GLsizei size, GLsizei entrySize)

View File

@ -62,6 +62,11 @@ enum class BlendMode {
BLEND_ADDITIVE
};
enum class DepthMode {
OFF,
LESS,
};
class Renderer {
public:
typedef std::vector<GLuint> Textures;
@ -84,7 +89,9 @@ public:
Textures textures{};
/// Blending mode
BlendMode blendMode = BlendMode::BLEND_NONE;
// Depth writing state
/// Depth
DepthMode depthMode = DepthMode::LESS;
/// Depth writing state
bool depthWrite = true;
/// Material
glm::u8vec4 colour{};
@ -342,6 +349,7 @@ private:
DrawBuffer* currentDbuff = nullptr;
OpenGLShaderProgram* currentProgram = nullptr;
BlendMode blendMode = BlendMode::BLEND_NONE;
DepthMode depthMode = DepthMode::OFF;
bool depthWriteEnabled = false;
GLuint currentUBO = 0;
GLuint currentUnit = 0;
@ -373,6 +381,17 @@ private:
blendMode = mode;
}
void setDepthMode(DepthMode mode) {
if (mode != depthMode) {
if (depthMode == DepthMode::OFF) glEnable(GL_DEPTH_TEST);
switch(mode) {
case DepthMode::OFF: glDisable(GL_DEPTH_TEST); break;
case DepthMode::LESS: glDepthFunc(GL_LESS); break;
}
depthMode = mode;
}
}
void setDepthWrite(bool enable) {
if (enable != depthWriteEnabled) {
glDepthMask(enable ? GL_TRUE : GL_FALSE);