mirror of
https://github.com/TomHarte/CLK.git
synced 2024-07-04 18:29:40 +00:00
Hides persistent low-part colour channel errors.
This commit is contained in:
parent
1bd6bbca8d
commit
b899a22c7d
@ -238,14 +238,15 @@ void OpenGLOutputBuilder::draw_frame(unsigned int output_width, unsigned int out
|
|||||||
// glTextureBarrierNV();
|
// glTextureBarrierNV();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// copy framebuffer to the intended place
|
// Copy framebuffer to the intended place; apply a threshold so that any persistent errors in
|
||||||
|
// the lower part of the colour channels are invisible.
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, static_cast<GLuint>(target_framebuffer_));
|
glBindFramebuffer(GL_FRAMEBUFFER, static_cast<GLuint>(target_framebuffer_));
|
||||||
glViewport(0, 0, (GLsizei)output_width, (GLsizei)output_height);
|
glViewport(0, 0, (GLsizei)output_width, (GLsizei)output_height);
|
||||||
|
|
||||||
glActiveTexture(pixel_accumulation_texture_unit);
|
glActiveTexture(pixel_accumulation_texture_unit);
|
||||||
framebuffer_->bind_texture();
|
framebuffer_->bind_texture();
|
||||||
framebuffer_->draw(static_cast<float>(output_width) / static_cast<float>(output_height));
|
framebuffer_->draw(static_cast<float>(output_width) / static_cast<float>(output_height), 4.0f / 255.0f);
|
||||||
|
|
||||||
fence_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
fence_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||||
draw_mutex_.unlock();
|
draw_mutex_.unlock();
|
||||||
|
@ -56,7 +56,7 @@ void TextureTarget::bind_texture() {
|
|||||||
glBindTexture(GL_TEXTURE_2D, texture_);
|
glBindTexture(GL_TEXTURE_2D, texture_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureTarget::draw(float aspect_ratio) {
|
void TextureTarget::draw(float aspect_ratio, float colour_threshold) {
|
||||||
if(!pixel_shader_) {
|
if(!pixel_shader_) {
|
||||||
const char *vertex_shader =
|
const char *vertex_shader =
|
||||||
"#version 150\n"
|
"#version 150\n"
|
||||||
@ -75,12 +75,15 @@ void TextureTarget::draw(float aspect_ratio) {
|
|||||||
"#version 150\n"
|
"#version 150\n"
|
||||||
|
|
||||||
"in vec2 texCoordVarying;"
|
"in vec2 texCoordVarying;"
|
||||||
|
|
||||||
"uniform sampler2D texID;"
|
"uniform sampler2D texID;"
|
||||||
|
"uniform float threshold;"
|
||||||
|
|
||||||
"out vec4 fragColour;"
|
"out vec4 fragColour;"
|
||||||
|
|
||||||
"void main(void)"
|
"void main(void)"
|
||||||
"{"
|
"{"
|
||||||
"fragColour = texture(texID, texCoordVarying);"
|
"fragColour = clamp(texture(texID, texCoordVarying), threshold, 1.0);"
|
||||||
"}";
|
"}";
|
||||||
pixel_shader_.reset(new Shader(vertex_shader, fragment_shader));
|
pixel_shader_.reset(new Shader(vertex_shader, fragment_shader));
|
||||||
pixel_shader_->bind();
|
pixel_shader_->bind();
|
||||||
@ -103,6 +106,8 @@ void TextureTarget::draw(float aspect_ratio) {
|
|||||||
|
|
||||||
GLint texIDUniform = pixel_shader_->get_uniform_location("texID");
|
GLint texIDUniform = pixel_shader_->get_uniform_location("texID");
|
||||||
glUniform1i(texIDUniform, static_cast<GLint>(texture_unit_ - GL_TEXTURE0));
|
glUniform1i(texIDUniform, static_cast<GLint>(texture_unit_ - GL_TEXTURE0));
|
||||||
|
|
||||||
|
threshold_uniform_ = pixel_shader_->get_uniform_location("threshold");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(set_aspect_ratio_ != aspect_ratio) {
|
if(set_aspect_ratio_ != aspect_ratio) {
|
||||||
@ -134,6 +139,8 @@ void TextureTarget::draw(float aspect_ratio) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pixel_shader_->bind();
|
pixel_shader_->bind();
|
||||||
|
glUniform1f(threshold_uniform_, colour_threshold);
|
||||||
|
|
||||||
glBindVertexArray(drawing_vertex_array_);
|
glBindVertexArray(drawing_vertex_array_);
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
}
|
}
|
||||||
|
@ -58,9 +58,17 @@ class TextureTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
Draws this texture to the currently-bound framebuffer, which has the aspect ratio
|
||||||
|
@c aspect_ratio. This texture will fill the height of the frame buffer, and pick
|
||||||
|
an appropriate width based o the aspect ratio.
|
||||||
|
|
||||||
|
@c colour_threshold sets a threshold test that each colour must satisfy to be
|
||||||
|
output. A threshold of 0.0f means that all colours will pass through. A threshold
|
||||||
|
of 0.5f means that only colour components above 0.5f will pass through, with
|
||||||
|
0.5f being substituted elsewhere. This provides a way to ensure that the sort of
|
||||||
|
persistent low-value errors that can result from an IIR are hidden.
|
||||||
*/
|
*/
|
||||||
void draw(float aspect_ratio);
|
void draw(float aspect_ratio, float colour_threshold = 0.0f);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ErrorFramebufferIncomplete
|
ErrorFramebufferIncomplete
|
||||||
@ -75,6 +83,8 @@ class TextureTarget {
|
|||||||
std::unique_ptr<Shader> pixel_shader_;
|
std::unique_ptr<Shader> pixel_shader_;
|
||||||
GLuint drawing_vertex_array_ = 0, drawing_array_buffer_ = 0;
|
GLuint drawing_vertex_array_ = 0, drawing_array_buffer_ = 0;
|
||||||
float set_aspect_ratio_ = 0.0f;
|
float set_aspect_ratio_ = 0.0f;
|
||||||
|
|
||||||
|
GLint threshold_uniform_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user