From 49663217e29a5ff93920c8d808912e5e3ff7ec2d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= <tseeker@nocternity.net>
Date: Wed, 4 Oct 2017 18:06:39 +0200
Subject: [PATCH] Combine ported

---
 combine.cc                               | 22 ++++++++++++----------
 combine.hh                               |  4 ++--
 shaders/{combine.glsl => combine.f.glsl} |  2 ++
 3 files changed, 16 insertions(+), 12 deletions(-)
 rename shaders/{combine.glsl => combine.f.glsl} (97%)

diff --git a/combine.cc b/combine.cc
index 60c39e4..a24cea9 100644
--- a/combine.cc
+++ b/combine.cc
@@ -16,12 +16,11 @@ T_CombinePass::T_CombinePass(
 		__rw__ T_Texture& image ,
 		__rw__ T_Texture& bloom )
 	: txImage_( image ) , txBloom_( bloom ) ,
-		program_( GL_FRAGMENT_SHADER ) ,
 		bloomStrength_( 0.45 ) ,
 		bloomAttenuation_( 0.3 )
 {
-	program_.addFile( "combine.glsl" );
-	program_.load( );
+	program_ = Globals::Shaders( ).pipeline({
+			"fullscreen.v.glsl" , "combine.f.glsl" });
 }
 
 void T_CombinePass::render( )
@@ -30,16 +29,19 @@ void T_CombinePass::render( )
 	T_Rendertarget::MainOutput( );
 	glClearColor( 1 , 0 , 1 , 1 );
 	glClear( GL_COLOR_BUFFER_BIT );
-	if ( program_.activate( ) ) {
+	if ( program_.valid( ) ) {
 		auto& tm( Globals::Textures( ) );
 		tm.bind( 0 , txImage_ );
 		tm.bind( 1 , txBloom_ );
-		glUniform1i( 0 , 0 );
-		glUniform1i( 1 , 1 );
-		glUniform2f( 2 , txImage_.width( ) , txImage_.height( ) );
-		glUniform2f( 3 , bloomStrength_ , bloomAttenuation_ );
-		glRectf( -1, -1 , 1 , 1 );
-		glBindTexture( GL_TEXTURE_2D , 0 );
+
+		const auto id( program_.program( E_ShaderType::FRAGMENT ) );
+		program_.enable( );
+		glProgramUniform1i( id , 0 , 0 );
+		glProgramUniform1i( id , 1 , 1 );
+		glProgramUniform2f( id , 2 , txImage_.width( ) , txImage_.height( ) );
+		glProgramUniform2f( id , 3 , bloomStrength_ , bloomAttenuation_ );
+
+		glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
 	}
 	PEND( );
 }
diff --git a/combine.hh b/combine.hh
index 6406b31..396d3e9 100644
--- a/combine.hh
+++ b/combine.hh
@@ -1,7 +1,7 @@
 #pragma once
 
 #include "rendertarget.hh"
-#include "programs.hh"
+#include "shaders.hh"
 
 
 struct T_CombinePass
@@ -20,7 +20,7 @@ struct T_CombinePass
 	T_Texture& txImage_;
 	T_Texture& txBloom_;
 
-	T_ShaderProgram program_;
+	T_ShaderPipeline program_;
 
 	float bloomStrength_;
 	float bloomAttenuation_;
diff --git a/shaders/combine.glsl b/shaders/combine.f.glsl
similarity index 97%
rename from shaders/combine.glsl
rename to shaders/combine.f.glsl
index fde6986..4b9a99a 100644
--- a/shaders/combine.glsl
+++ b/shaders/combine.f.glsl
@@ -1,5 +1,7 @@
 #version 450 core
 
+//! type fragment
+
 layout( location = 0 ) uniform sampler2D u_MainInput;
 layout( location = 1 ) uniform sampler2D u_BlurInput;
 layout( location = 2 ) uniform vec2 u_OutputSize;