diff --git a/dof.cc b/dof.cc index d0f2db5..646bdc0 100644 --- a/dof.cc +++ b/dof.cc @@ -15,8 +15,6 @@ T_DoFPass::T_DoFPass( __rw__ T_Texture& imageInput , __rw__ T_Texture& depthInput ) : imageInput_( imageInput ) , depthInput_( depthInput ) , - spPass1_( GL_FRAGMENT_SHADER ) , - spPass2_( GL_FRAGMENT_SHADER ) , txPass1_( imageInput.width( ) , imageInput.height( ) , E_TexType::RGB16F ) , txOutput_( imageInput.width( ) , imageInput.height( ) , @@ -28,13 +26,10 @@ T_DoFPass::T_DoFPass( { txPass1_.wrap( E_TexWrap::CLAMP_EDGE ); - spPass1_.addFile( "dof-common.glsl" ); - spPass1_.addFile( "dof-pass1.glsl" ); - spPass1_.load( ); - - spPass2_.addFile( "dof-common.glsl" ); - spPass2_.addFile( "dof-pass2.glsl" ); - spPass2_.load( ); + spPass1_ = Globals::Shaders( ).pipeline({ + "fullscreen.v.glsl" , "dof-pass1.f.glsl" }); + spPass2_ = Globals::Shaders( ).pipeline({ + "fullscreen.v.glsl" , "dof-pass2.f.glsl" }); } void T_DoFPass::render( ) @@ -49,32 +44,39 @@ void T_DoFPass::render( ) }; auto& tm( Globals::Textures( ) ); - if ( spPass1_.activate( ) && rtPass1_.activate( ) ) { - glUniform1i( U_INPUT , 0 ); - glUniform1i( U_DEPTH , 1 ); - glUniform4fv( U_PARAMS , 1 , filterParams_ ); - glUniform1f( U_SAMPLES , nSamples_ ); - glUniform3f( U_RES_TIME , imageInput_.width( ) , + rtPass1_.activate( ); + if ( spPass1_.valid( ) ) { + const auto id( spPass1_.program( E_ShaderType::FRAGMENT ) ); + spPass1_.enable( ); + glProgramUniform1i( id , U_INPUT , 0 ); + glProgramUniform1i( id , U_DEPTH , 1 ); + glProgramUniform4fv( id , U_PARAMS , 1 , filterParams_ ); + glProgramUniform1f( id , U_SAMPLES , nSamples_ ); + glProgramUniform3f( id , U_RES_TIME , imageInput_.width( ) , imageInput_.height( ) , 0 ); tm.bind( 0 , imageInput_ , *tm.sampler( "linear-edge" ) ); tm.bind( 1 , depthInput_ , *tm.sampler( "linear-edge" ) ); - glRectf( -1 , -1 , 1 , 1 ); + glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 ); } - if ( spPass2_.activate( ) && rtPass2_.activate( ) ) { - glUniform1i( U_INPUT , 0 ); - glUniform1i( U_DEPTH , 1 ); - glUniform4fv( U_PARAMS , 1 , filterParams_ ); - glUniform1f( U_SAMPLES , nSamples_ ); - glUniform3f( U_RES_TIME , imageInput_.width( ) , + rtPass2_.activate( ); + if ( spPass2_.valid( ) ) { + const auto id( spPass2_.program( E_ShaderType::FRAGMENT ) ); + spPass2_.enable( ); + glProgramUniform1i( id , U_INPUT , 0 ); + glProgramUniform1i( id , U_DEPTH , 1 ); + glProgramUniform4fv( id , U_PARAMS , 1 , filterParams_ ); + glProgramUniform1f( id , U_SAMPLES , nSamples_ ); + glProgramUniform3f( id , U_RES_TIME , + imageInput_.width( ) , imageInput_.height( ) , 0 ); tm.bind( 0 , txPass1_ , *tm.sampler( "linear-edge" ) ); - glRectf( -1 , -1 , 1 , 1 ); + glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 ); } PEND( ); } diff --git a/dof.hh b/dof.hh index 37a5219..c6ad87f 100644 --- a/dof.hh +++ b/dof.hh @@ -1,6 +1,6 @@ #pragma once #include "rendertarget.hh" -#include "programs.hh" +#include "shaders.hh" struct T_DoFPass @@ -21,8 +21,8 @@ struct T_DoFPass T_Texture& imageInput_; T_Texture& depthInput_; - T_ShaderProgram spPass1_; - T_ShaderProgram spPass2_; + T_ShaderPipeline spPass1_; + T_ShaderPipeline spPass2_; T_Texture txPass1_ , txOutput_; T_Rendertarget rtPass1_ , rtPass2_; diff --git a/main.cc b/main.cc index 2f7788e..ded83d7 100644 --- a/main.cc +++ b/main.cc @@ -183,6 +183,7 @@ void T_Main::render( ) glFinish( ); Globals::Profiler( ).end( "Render" ); } glUseProgram( 0 ); + glBindProgramPipeline( 0 ); Globals::Textures( ).reset( ); ImGui::Render( ); } diff --git a/raymarcher.cc b/raymarcher.cc index 7740e4a..41c44d3 100644 --- a/raymarcher.cc +++ b/raymarcher.cc @@ -52,7 +52,6 @@ void T_Raymarcher::render( ) U_RAYMARCHER = 7 , }; -#if 1 const auto id( program_.program( E_ShaderType::FRAGMENT ) ); glProgramUniform1f( id , U_TIME , 0 ); glProgramUniform2f( id , U_RESOLUTION , rtOutput_.width( ) , rtOutput_.height( ) ); @@ -68,22 +67,6 @@ void T_Raymarcher::render( ) rmEpsilon , rmMaxDist ); glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 ); - glBindProgramPipeline( 0 ); -#else - glUniform1f( U_TIME , 0 ); - glUniform2f( U_RESOLUTION , rtOutput_.width( ) , rtOutput_.height( ) ); - - glUniform3fv( U_CAM_POS , 1 , &camera_.pos.x ); - glUniform3fv( U_LOOK_AT , 1 , &camera_.lookAt.x ); - glUniform3fv( U_CAM_UP , 1 , &camera_.up.x ); - glUniform1f( U_NEAR_PLANE , camera_.np ); - - glUniform3f( U_LIGHT_DIR , 0 , 1 , -1 ); - - glUniform4f( U_RAYMARCHER , rmIterations , rmStep , rmEpsilon , rmMaxDist ); - - glRectf( -1 , -1 , 1 , 1 ); -#endif PEND( ); } diff --git a/shaders/dof-common.glsl b/shaders/dof-common.l.glsl similarity index 98% rename from shaders/dof-common.glsl rename to shaders/dof-common.l.glsl index aba3547..7d6f985 100644 --- a/shaders/dof-common.glsl +++ b/shaders/dof-common.l.glsl @@ -1,5 +1,4 @@ -#version 450 core - +//! type chunk //#define USE_RANDOM layout( location = 0 ) uniform sampler2D u_Input; diff --git a/shaders/dof-pass1.glsl b/shaders/dof-pass1.f.glsl similarity index 75% rename from shaders/dof-pass1.glsl rename to shaders/dof-pass1.f.glsl index d55f187..ce8d91f 100644 --- a/shaders/dof-pass1.glsl +++ b/shaders/dof-pass1.f.glsl @@ -1,3 +1,8 @@ +#version 450 core + +//! type fragment +//! include dof-common.l.glsl + void main() { vec2 uv = gl_FragCoord.xy / uResolution; diff --git a/shaders/dof-pass2.glsl b/shaders/dof-pass2.f.glsl similarity index 86% rename from shaders/dof-pass2.glsl rename to shaders/dof-pass2.f.glsl index 77f2298..3c85929 100644 --- a/shaders/dof-pass2.glsl +++ b/shaders/dof-pass2.f.glsl @@ -1,3 +1,8 @@ +#version 450 core + +//! type fragment +//! include dof-common.l.glsl + void main() { vec2 uv = gl_FragCoord.xy / uResolution;