|
|
@ -33,7 +33,7 @@ OpenGLState::OpenGLState() {
|
|
|
|
stencil.action_depth_pass = GL_KEEP;
|
|
|
|
stencil.action_depth_pass = GL_KEEP;
|
|
|
|
stencil.action_stencil_fail = GL_KEEP;
|
|
|
|
stencil.action_stencil_fail = GL_KEEP;
|
|
|
|
|
|
|
|
|
|
|
|
blend.enabled = false;
|
|
|
|
blend.enabled = true;
|
|
|
|
blend.rgb_equation = GL_FUNC_ADD;
|
|
|
|
blend.rgb_equation = GL_FUNC_ADD;
|
|
|
|
blend.a_equation = GL_FUNC_ADD;
|
|
|
|
blend.a_equation = GL_FUNC_ADD;
|
|
|
|
blend.src_rgb_func = GL_ONE;
|
|
|
|
blend.src_rgb_func = GL_ONE;
|
|
|
@ -68,6 +68,18 @@ OpenGLState::OpenGLState() {
|
|
|
|
draw.vertex_buffer = 0;
|
|
|
|
draw.vertex_buffer = 0;
|
|
|
|
draw.uniform_buffer = 0;
|
|
|
|
draw.uniform_buffer = 0;
|
|
|
|
draw.shader_program = 0;
|
|
|
|
draw.shader_program = 0;
|
|
|
|
|
|
|
|
draw.program_pipeline = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scissor.enabled = false;
|
|
|
|
|
|
|
|
scissor.x = 0;
|
|
|
|
|
|
|
|
scissor.y = 0;
|
|
|
|
|
|
|
|
scissor.width = 0;
|
|
|
|
|
|
|
|
scissor.height = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewport.x = 0;
|
|
|
|
|
|
|
|
viewport.y = 0;
|
|
|
|
|
|
|
|
viewport.width = 0;
|
|
|
|
|
|
|
|
viewport.height = 0;
|
|
|
|
|
|
|
|
|
|
|
|
clip_distance = {};
|
|
|
|
clip_distance = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -148,9 +160,6 @@ void OpenGLState::Apply() const {
|
|
|
|
if (blend.enabled != cur_state.blend.enabled) {
|
|
|
|
if (blend.enabled != cur_state.blend.enabled) {
|
|
|
|
if (blend.enabled) {
|
|
|
|
if (blend.enabled) {
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
|
|
|
|
|
|
|
cur_state.logic_op = GL_COPY;
|
|
|
|
|
|
|
|
glLogicOp(cur_state.logic_op);
|
|
|
|
|
|
|
|
glDisable(GL_COLOR_LOGIC_OP);
|
|
|
|
glDisable(GL_COLOR_LOGIC_OP);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
@ -196,7 +205,7 @@ void OpenGLState::Apply() const {
|
|
|
|
// Lighting LUTs
|
|
|
|
// Lighting LUTs
|
|
|
|
if (lighting_lut.texture_buffer != cur_state.lighting_lut.texture_buffer) {
|
|
|
|
if (lighting_lut.texture_buffer != cur_state.lighting_lut.texture_buffer) {
|
|
|
|
glActiveTexture(TextureUnits::LightingLUT.Enum());
|
|
|
|
glActiveTexture(TextureUnits::LightingLUT.Enum());
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, cur_state.lighting_lut.texture_buffer);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, lighting_lut.texture_buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Fog LUT
|
|
|
|
// Fog LUT
|
|
|
@ -263,6 +272,31 @@ void OpenGLState::Apply() const {
|
|
|
|
glUseProgram(draw.shader_program);
|
|
|
|
glUseProgram(draw.shader_program);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Program pipeline
|
|
|
|
|
|
|
|
if (draw.program_pipeline != cur_state.draw.program_pipeline) {
|
|
|
|
|
|
|
|
glBindProgramPipeline(draw.program_pipeline);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Scissor test
|
|
|
|
|
|
|
|
if (scissor.enabled != cur_state.scissor.enabled) {
|
|
|
|
|
|
|
|
if (scissor.enabled) {
|
|
|
|
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (scissor.x != cur_state.scissor.x || scissor.y != cur_state.scissor.y ||
|
|
|
|
|
|
|
|
scissor.width != cur_state.scissor.width || scissor.height != cur_state.scissor.height) {
|
|
|
|
|
|
|
|
glScissor(scissor.x, scissor.y, scissor.width, scissor.height);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (viewport.x != cur_state.viewport.x || viewport.y != cur_state.viewport.y ||
|
|
|
|
|
|
|
|
viewport.width != cur_state.viewport.width ||
|
|
|
|
|
|
|
|
viewport.height != cur_state.viewport.height) {
|
|
|
|
|
|
|
|
glViewport(viewport.x, viewport.y, viewport.width, viewport.height);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Clip distance
|
|
|
|
// Clip distance
|
|
|
|
for (size_t i = 0; i < clip_distance.size(); ++i) {
|
|
|
|
for (size_t i = 0; i < clip_distance.size(); ++i) {
|
|
|
|
if (clip_distance[i] != cur_state.clip_distance[i]) {
|
|
|
|
if (clip_distance[i] != cur_state.clip_distance[i]) {
|
|
|
@ -277,62 +311,75 @@ void OpenGLState::Apply() const {
|
|
|
|
cur_state = *this;
|
|
|
|
cur_state = *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpenGLState::ResetTexture(GLuint handle) {
|
|
|
|
OpenGLState& OpenGLState::ResetTexture(GLuint handle) {
|
|
|
|
for (auto& unit : cur_state.texture_units) {
|
|
|
|
for (auto& unit : texture_units) {
|
|
|
|
if (unit.texture_2d == handle) {
|
|
|
|
if (unit.texture_2d == handle) {
|
|
|
|
unit.texture_2d = 0;
|
|
|
|
unit.texture_2d = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cur_state.lighting_lut.texture_buffer == handle)
|
|
|
|
if (lighting_lut.texture_buffer == handle)
|
|
|
|
cur_state.lighting_lut.texture_buffer = 0;
|
|
|
|
lighting_lut.texture_buffer = 0;
|
|
|
|
if (cur_state.fog_lut.texture_buffer == handle)
|
|
|
|
if (fog_lut.texture_buffer == handle)
|
|
|
|
cur_state.fog_lut.texture_buffer = 0;
|
|
|
|
fog_lut.texture_buffer = 0;
|
|
|
|
if (cur_state.proctex_noise_lut.texture_buffer == handle)
|
|
|
|
if (proctex_noise_lut.texture_buffer == handle)
|
|
|
|
cur_state.proctex_noise_lut.texture_buffer = 0;
|
|
|
|
proctex_noise_lut.texture_buffer = 0;
|
|
|
|
if (cur_state.proctex_color_map.texture_buffer == handle)
|
|
|
|
if (proctex_color_map.texture_buffer == handle)
|
|
|
|
cur_state.proctex_color_map.texture_buffer = 0;
|
|
|
|
proctex_color_map.texture_buffer = 0;
|
|
|
|
if (cur_state.proctex_alpha_map.texture_buffer == handle)
|
|
|
|
if (proctex_alpha_map.texture_buffer == handle)
|
|
|
|
cur_state.proctex_alpha_map.texture_buffer = 0;
|
|
|
|
proctex_alpha_map.texture_buffer = 0;
|
|
|
|
if (cur_state.proctex_lut.texture_buffer == handle)
|
|
|
|
if (proctex_lut.texture_buffer == handle)
|
|
|
|
cur_state.proctex_lut.texture_buffer = 0;
|
|
|
|
proctex_lut.texture_buffer = 0;
|
|
|
|
if (cur_state.proctex_diff_lut.texture_buffer == handle)
|
|
|
|
if (proctex_diff_lut.texture_buffer == handle)
|
|
|
|
cur_state.proctex_diff_lut.texture_buffer = 0;
|
|
|
|
proctex_diff_lut.texture_buffer = 0;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpenGLState::ResetSampler(GLuint handle) {
|
|
|
|
OpenGLState& OpenGLState::ResetSampler(GLuint handle) {
|
|
|
|
for (auto& unit : cur_state.texture_units) {
|
|
|
|
for (auto& unit : texture_units) {
|
|
|
|
if (unit.sampler == handle) {
|
|
|
|
if (unit.sampler == handle) {
|
|
|
|
unit.sampler = 0;
|
|
|
|
unit.sampler = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpenGLState::ResetProgram(GLuint handle) {
|
|
|
|
OpenGLState& OpenGLState::ResetProgram(GLuint handle) {
|
|
|
|
if (cur_state.draw.shader_program == handle) {
|
|
|
|
if (draw.shader_program == handle) {
|
|
|
|
cur_state.draw.shader_program = 0;
|
|
|
|
draw.shader_program = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpenGLState::ResetBuffer(GLuint handle) {
|
|
|
|
OpenGLState& OpenGLState::ResetPipeline(GLuint handle) {
|
|
|
|
if (cur_state.draw.vertex_buffer == handle) {
|
|
|
|
if (draw.program_pipeline == handle) {
|
|
|
|
cur_state.draw.vertex_buffer = 0;
|
|
|
|
draw.program_pipeline = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_state.draw.uniform_buffer == handle) {
|
|
|
|
|
|
|
|
cur_state.draw.uniform_buffer = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpenGLState::ResetVertexArray(GLuint handle) {
|
|
|
|
OpenGLState& OpenGLState::ResetBuffer(GLuint handle) {
|
|
|
|
if (cur_state.draw.vertex_array == handle) {
|
|
|
|
if (draw.vertex_buffer == handle) {
|
|
|
|
cur_state.draw.vertex_array = 0;
|
|
|
|
draw.vertex_buffer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draw.uniform_buffer == handle) {
|
|
|
|
|
|
|
|
draw.uniform_buffer = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpenGLState::ResetFramebuffer(GLuint handle) {
|
|
|
|
OpenGLState& OpenGLState::ResetVertexArray(GLuint handle) {
|
|
|
|
if (cur_state.draw.read_framebuffer == handle) {
|
|
|
|
if (draw.vertex_array == handle) {
|
|
|
|
cur_state.draw.read_framebuffer = 0;
|
|
|
|
draw.vertex_array = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_state.draw.draw_framebuffer == handle) {
|
|
|
|
|
|
|
|
cur_state.draw.draw_framebuffer = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OpenGLState& OpenGLState::ResetFramebuffer(GLuint handle) {
|
|
|
|
|
|
|
|
if (draw.read_framebuffer == handle) {
|
|
|
|
|
|
|
|
draw.read_framebuffer = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draw.draw_framebuffer == handle) {
|
|
|
|
|
|
|
|
draw.draw_framebuffer = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|