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,
310 edge_detect_shader );
312 checkGlError(
"linking pass 1 shader", __FILE__, __LINE__ );
314 GLint smaaColorTexParameter =
pass_1_shader->AddParameter(
"colorTex" );
315 checkGlError(
"pass1: getting colorTex uniform", __FILE__, __LINE__ );
317 checkGlError(
"pass1: getting metrics uniform", __FILE__, __LINE__ );
320 checkGlError(
"pass1: using shader", __FILE__, __LINE__ );
322 checkGlError(
"pass1: setting colorTex uniform", __FILE__, __LINE__ );
324 checkGlError(
"pass1: deactivating shader", __FILE__, __LINE__ );
331 BUILTIN_SHADERS::glsl_smaa_base,
332 BUILTIN_SHADERS::glsl_smaa_pass_2_vert );
334 quality_string, BUILTIN_SHADERS::glsl_smaa_base,
335 BUILTIN_SHADERS::glsl_smaa_pass_2_frag );
337 checkGlError(
"linking pass 2 shader", __FILE__, __LINE__ );
339 GLint smaaEdgesTexParameter =
pass_2_shader->AddParameter(
"edgesTex" );
340 checkGlError(
"pass2: getting colorTex uniform", __FILE__, __LINE__ );
341 GLint smaaAreaTexParameter =
pass_2_shader->AddParameter(
"areaTex" );
342 checkGlError(
"pass2: getting areaTex uniform", __FILE__, __LINE__ );
343 GLint smaaSearchTexParameter =
pass_2_shader->AddParameter(
"searchTex" );
344 checkGlError(
"pass2: getting searchTex uniform", __FILE__, __LINE__ );
346 checkGlError(
"pass2: getting metrics uniform", __FILE__, __LINE__ );
349 checkGlError(
"pass2: using shader", __FILE__, __LINE__ );
351 checkGlError(
"pass2: setting colorTex uniform", __FILE__, __LINE__ );
353 checkGlError(
"pass2: setting areaTex uniform", __FILE__, __LINE__ );
355 checkGlError(
"pass2: setting searchTex uniform", __FILE__, __LINE__ );
357 checkGlError(
"pass2: deactivating shader", __FILE__, __LINE__ );
364 BUILTIN_SHADERS::glsl_smaa_base,
365 BUILTIN_SHADERS::glsl_smaa_pass_3_vert );
367 quality_string, BUILTIN_SHADERS::glsl_smaa_base,
368 BUILTIN_SHADERS::glsl_smaa_pass_3_frag );
371 GLint smaaP3ColorTexParameter =
pass_3_shader->AddParameter(
"colorTex" );
372 checkGlError(
"pass3: getting colorTex uniform", __FILE__, __LINE__ );
373 GLint smaaBlendTexParameter =
pass_3_shader->AddParameter(
"blendTex" );
374 checkGlError(
"pass3: getting blendTex uniform", __FILE__, __LINE__ );
376 checkGlError(
"pass3: getting metrics uniform", __FILE__, __LINE__ );
379 checkGlError(
"pass3: using shader", __FILE__, __LINE__ );
381 checkGlError(
"pass3: setting colorTex uniform", __FILE__, __LINE__ );
383 checkGlError(
"pass3: setting blendTex uniform", __FILE__, __LINE__ );
385 checkGlError(
"pass3: deactivating shader", __FILE__, __LINE__ );
396 checkGlError(
"pass1: using shader", __FILE__, __LINE__ );
398 float( dims.x ),
float( dims.y ) );
399 checkGlError(
"pass1: setting metrics uniform", __FILE__, __LINE__ );
401 checkGlError(
"pass1: deactivating shader", __FILE__, __LINE__ );
404 checkGlError(
"pass2: using shader", __FILE__, __LINE__ );
406 float( dims.x ),
float( dims.y ) );
407 checkGlError(
"pass2: setting metrics uniform", __FILE__, __LINE__ );
409 checkGlError(
"pass2: deactivating shader", __FILE__, __LINE__ );
412 checkGlError(
"pass3: using shader", __FILE__, __LINE__ );
414 float( dims.x ),
float( dims.y ) );
415 checkGlError(
"pass3: setting metrics uniform", __FILE__, __LINE__ );
417 checkGlError(
"pass3: deactivating shader", __FILE__, __LINE__ );
429 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
430 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
433 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
434 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
437 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
438 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
477void draw_fullscreen_triangle()
479 glMatrixMode( GL_MODELVIEW );
482 glMatrixMode( GL_PROJECTION );
486 glBegin( GL_TRIANGLES );
487 glTexCoord2f( 0.0f, 1.0f );
488 glVertex2f( -1.0f, 1.0f );
489 glTexCoord2f( 0.0f, -1.0f );
490 glVertex2f( -1.0f, -3.0f );
491 glTexCoord2f( 2.0f, 1.0f );
492 glVertex2f( 3.0f, 1.0f );
496 glMatrixMode( GL_MODELVIEW );
506 glDisable( GL_BLEND );
507 glDisable( GL_DEPTH_TEST );
508 glEnable( GL_TEXTURE_2D );
516 glActiveTexture( GL_TEXTURE0 );
517 glBindTexture( GL_TEXTURE_2D, sourceTexture );
520 checkGlError(
"using smaa pass 1 shader", __FILE__, __LINE__ );
521 draw_fullscreen_triangle();
532 glActiveTexture( GL_TEXTURE0 );
533 glBindTexture( GL_TEXTURE_2D, edgesTex );
534 glActiveTexture( GL_TEXTURE1 );
536 glActiveTexture( GL_TEXTURE3 );
540 draw_fullscreen_triangle();
550 glActiveTexture( GL_TEXTURE0 );
551 glBindTexture( GL_TEXTURE_2D, sourceTexture );
552 glActiveTexture( GL_TEXTURE1 );
553 glBindTexture( GL_TEXTURE_2D, blendTex );
555 glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE );
558 draw_fullscreen_triangle();
561 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.