32#include <glsl_smaa_base.h>
33#include <glsl_smaa_pass_1_frag_color.h>
34#include <glsl_smaa_pass_1_frag_luma.h>
35#include <glsl_smaa_pass_1_vert.h>
36#include <glsl_smaa_pass_2_frag.h>
37#include <glsl_smaa_pass_2_vert.h>
38#include <glsl_smaa_pass_3_frag.h>
39#include <glsl_smaa_pass_3_vert.h>
50 compositor( aCompositor )
100void draw_fullscreen_primitive()
102 glMatrixMode( GL_MODELVIEW );
105 glMatrixMode( GL_PROJECTION );
110 glBegin( GL_TRIANGLES );
111 glTexCoord2f( 0.0f, 1.0f );
112 glVertex2f( -1.0f, 1.0f );
113 glTexCoord2f( 0.0f, 0.0f );
114 glVertex2f( -1.0f, -1.0f );
115 glTexCoord2f( 1.0f, 1.0f );
116 glVertex2f( 1.0f, 1.0f );
118 glTexCoord2f( 1.0f, 1.0f );
119 glVertex2f( 1.0f, 1.0f );
120 glTexCoord2f( 0.0f, 0.0f );
121 glVertex2f( -1.0f, -1.0f );
122 glTexCoord2f( 1.0f, 0.0f );
123 glVertex2f( 1.0f, -1.0f );
127 glMatrixMode( GL_MODELVIEW );
138 compositor( aCompositor ),
139 ssaaMainBuffer( 0 ), areBuffersCreated( false ), areShadersCreated( false )
151 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
152 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
182 glDisable( GL_BLEND );
183 glDisable( GL_DEPTH_TEST );
184 glActiveTexture( GL_TEXTURE0 );
188 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE );
190 draw_fullscreen_primitive();
192 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
212 areBuffersInitialized( false ),
213 shadersLoaded( false ),
214 compositor( aCompositor )
237 glEnable( GL_TEXTURE_2D );
238 glActiveTexture( GL_TEXTURE0 );
242 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
243 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
244 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
245 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
248 checkGlError(
"loading smaa area tex", __FILE__, __LINE__ );
252 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
253 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
254 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
255 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
258 checkGlError(
"loading smaa search tex", __FILE__, __LINE__ );
272 std::string quality_string;
273 std::string edge_detect_shader;
277 quality_string =
"#define SMAA_THRESHOLD 0.005\n"
278 "#define SMAA_MAX_SEARCH_STEPS 1\n"
279 "#define SMAA_MAX_SEARCH_STEPS_DIAG 2\n"
280 "#define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 1.5\n"
281 "#define SMAA_CORNER_ROUNDING 0\n";
282 edge_detect_shader = BUILTIN_SHADERS::glsl_smaa_pass_1_frag_luma;
285 std::string vert_preamble( R
"SHADER(
288#define SMAA_INCLUDE_VS 1
289#define SMAA_INCLUDE_PS 0
290uniform vec4 SMAA_RT_METRICS;
293 std::string frag_preamble( R"SHADER(
296#define SMAA_INCLUDE_VS 0
297#define SMAA_INCLUDE_PS 1
298uniform vec4 SMAA_RT_METRICS;
306 BUILTIN_SHADERS::glsl_smaa_base,
307 BUILTIN_SHADERS::glsl_smaa_pass_1_vert );
309 quality_string, BUILTIN_SHADERS::glsl_smaa_base, edge_detect_shader );
311 checkGlError(
"linking pass 1 shader", __FILE__, __LINE__ );
313 GLint smaaColorTexParameter =
pass_1_shader->AddParameter(
"colorTex" );
314 checkGlError(
"pass1: getting colorTex uniform", __FILE__, __LINE__ );
316 checkGlError(
"pass1: getting metrics uniform", __FILE__, __LINE__ );
319 checkGlError(
"pass1: using shader", __FILE__, __LINE__ );
321 checkGlError(
"pass1: setting colorTex uniform", __FILE__, __LINE__ );
323 checkGlError(
"pass1: deactivating shader", __FILE__, __LINE__ );
330 BUILTIN_SHADERS::glsl_smaa_base,
331 BUILTIN_SHADERS::glsl_smaa_pass_2_vert );
333 quality_string, BUILTIN_SHADERS::glsl_smaa_base,
334 BUILTIN_SHADERS::glsl_smaa_pass_2_frag );
336 checkGlError(
"linking pass 2 shader", __FILE__, __LINE__ );
338 GLint smaaEdgesTexParameter =
pass_2_shader->AddParameter(
"edgesTex" );
339 checkGlError(
"pass2: getting colorTex uniform", __FILE__, __LINE__ );
340 GLint smaaAreaTexParameter =
pass_2_shader->AddParameter(
"areaTex" );
341 checkGlError(
"pass2: getting areaTex uniform", __FILE__, __LINE__ );
342 GLint smaaSearchTexParameter =
pass_2_shader->AddParameter(
"searchTex" );
343 checkGlError(
"pass2: getting searchTex uniform", __FILE__, __LINE__ );
345 checkGlError(
"pass2: getting metrics uniform", __FILE__, __LINE__ );
348 checkGlError(
"pass2: using shader", __FILE__, __LINE__ );
350 checkGlError(
"pass2: setting colorTex uniform", __FILE__, __LINE__ );
352 checkGlError(
"pass2: setting areaTex uniform", __FILE__, __LINE__ );
354 checkGlError(
"pass2: setting searchTex uniform", __FILE__, __LINE__ );
356 checkGlError(
"pass2: deactivating shader", __FILE__, __LINE__ );
363 BUILTIN_SHADERS::glsl_smaa_base,
364 BUILTIN_SHADERS::glsl_smaa_pass_3_vert );
366 quality_string, BUILTIN_SHADERS::glsl_smaa_base,
367 BUILTIN_SHADERS::glsl_smaa_pass_3_frag );
370 GLint smaaP3ColorTexParameter =
pass_3_shader->AddParameter(
"colorTex" );
371 checkGlError(
"pass3: getting colorTex uniform", __FILE__, __LINE__ );
372 GLint smaaBlendTexParameter =
pass_3_shader->AddParameter(
"blendTex" );
373 checkGlError(
"pass3: getting blendTex uniform", __FILE__, __LINE__ );
375 checkGlError(
"pass3: getting metrics uniform", __FILE__, __LINE__ );
378 checkGlError(
"pass3: using shader", __FILE__, __LINE__ );
380 checkGlError(
"pass3: setting colorTex uniform", __FILE__, __LINE__ );
382 checkGlError(
"pass3: setting blendTex uniform", __FILE__, __LINE__ );
384 checkGlError(
"pass3: deactivating shader", __FILE__, __LINE__ );
395 checkGlError(
"pass1: using shader", __FILE__, __LINE__ );
397 float( dims.x ),
float( dims.y ) );
398 checkGlError(
"pass1: setting metrics uniform", __FILE__, __LINE__ );
400 checkGlError(
"pass1: deactivating shader", __FILE__, __LINE__ );
403 checkGlError(
"pass2: using shader", __FILE__, __LINE__ );
405 float( dims.x ),
float( dims.y ) );
406 checkGlError(
"pass2: setting metrics uniform", __FILE__, __LINE__ );
408 checkGlError(
"pass2: deactivating shader", __FILE__, __LINE__ );
411 checkGlError(
"pass3: using shader", __FILE__, __LINE__ );
413 float( dims.x ),
float( dims.y ) );
414 checkGlError(
"pass3: setting metrics uniform", __FILE__, __LINE__ );
416 checkGlError(
"pass3: deactivating shader", __FILE__, __LINE__ );
428 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
429 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
432 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
433 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
436 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
437 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
476void draw_fullscreen_triangle()
478 glMatrixMode( GL_MODELVIEW );
481 glMatrixMode( GL_PROJECTION );
485 glBegin( GL_TRIANGLES );
486 glTexCoord2f( 0.0f, 1.0f );
487 glVertex2f( -1.0f, 1.0f );
488 glTexCoord2f( 0.0f, -1.0f );
489 glVertex2f( -1.0f, -3.0f );
490 glTexCoord2f( 2.0f, 1.0f );
491 glVertex2f( 3.0f, 1.0f );
495 glMatrixMode( GL_MODELVIEW );
505 glDisable( GL_BLEND );
506 glDisable( GL_DEPTH_TEST );
507 glEnable( GL_TEXTURE_2D );
515 glActiveTexture( GL_TEXTURE0 );
516 glBindTexture( GL_TEXTURE_2D, sourceTexture );
519 checkGlError(
"using smaa pass 1 shader", __FILE__, __LINE__ );
520 draw_fullscreen_triangle();
531 glActiveTexture( GL_TEXTURE0 );
532 glBindTexture( GL_TEXTURE_2D, edgesTex );
533 glActiveTexture( GL_TEXTURE1 );
535 glActiveTexture( GL_TEXTURE3 );
539 draw_fullscreen_triangle();
549 glActiveTexture( GL_TEXTURE0 );
550 glBindTexture( GL_TEXTURE_2D, sourceTexture );
551 glActiveTexture( GL_TEXTURE1 );
552 glBindTexture( GL_TEXTURE_2D, blendTex );
554 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE );
557 draw_fullscreen_triangle();
560 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
const unsigned char areaTexBytes[]
Stored in R8G8 format.
static const unsigned char searchTexBytes[]
Stored in R8 format.
void DrawBuffer(GLuint aBuffer) override
unsigned int CreateBuffer() override
VECTOR2I GetInternalBufferSize() override
ANTIALIASING_NONE(OPENGL_COMPOSITOR *aCompositor)
OPENGL_COMPOSITOR * compositor
void OnLostBuffers() override
ANTIALIASING_SMAA(OPENGL_COMPOSITOR *aCompositor)
OPENGL_COMPOSITOR * compositor
unsigned int smaaEdgesBuffer
unsigned int smaaBaseBuffer
unsigned int smaaBlendBuffer
unsigned int smaaSearchTex
void DrawBuffer(GLuint buffer) override
VECTOR2I GetInternalBufferSize() override
bool areBuffersInitialized
std::unique_ptr< SHADER > pass_1_shader
void OnLostBuffers() override
std::unique_ptr< SHADER > pass_3_shader
std::unique_ptr< SHADER > pass_2_shader
unsigned int CreateBuffer() override
VECTOR2I GetInternalBufferSize() override
unsigned int CreateBuffer() override
void OnLostBuffers() override
void DrawBuffer(GLuint) override
OPENGL_COMPOSITOR * compositor
unsigned int ssaaMainBuffer
ANTIALIASING_SUPERSAMPLING(OPENGL_COMPOSITOR *aCompositor)
static const COLOR4D BLACK
static const unsigned int DIRECT_RENDERING
VECTOR2I GetScreenSize() const
virtual void ClearBuffer(const COLOR4D &aColor) override
Clear the selected buffer (set by the SetBuffer() function).
virtual void DrawBuffer(unsigned int aBufferHandle) override
Draw the selected buffer to the output buffer.
GLenum GetBufferTexture(unsigned int aBufferHandle)
virtual void SetBuffer(unsigned int aBufferHandle) override
Set the selected buffer as the rendering target.
virtual unsigned int CreateBuffer() override
Prepare a new buffer that may be used as a rendering target.
The Cairo implementation of the graphics abstraction layer.
@ SHADER_TYPE_VERTEX
Vertex shader.
@ SHADER_TYPE_FRAGMENT
Fragment shader.
Handle multitarget rendering (ie.
int checkGlError(const std::string &aInfo, const char *aFile, int aLine, bool aThrow)
Check if a recent OpenGL operation has failed.