From 3d8d7edf6c832b1882ee6aea37339d93b53b66e3 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Thu, 27 Jul 2017 15:47:34 +0200 Subject: single backbuffer --- shader.frag | 16 ++++++++++++++-- sv.c | 21 +++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/shader.frag b/shader.frag index 4741236..c6cc012 100644 --- a/shader.frag +++ b/shader.frag @@ -1,4 +1,4 @@ -#version 440 core +#version 450 core #ifdef GL_ES precision mediump float; #endif @@ -7,6 +7,8 @@ uniform vec2 resolution; uniform float time; uniform sampler2D images[4]; +layout (binding = 0,rgba32f) uniform image2D backbuffer; +//uniform image2DArray buffers; uniform float ratios[4]; uniform float params[32]; @@ -20,11 +22,21 @@ vec4 image(int i) { vec2 st = gl_FragCoord.xy/resolution.xy; st.x *= ratios[i]; st.x += (1-ratios[i])*0.5; + st.x += 0.5*time; return texture2D(images[i],st); } void main (void) { vec4 img1 = mix(image(0),image(1),sin(time)); vec4 img2 = mix(image(2),image(3),cos(time)); - fragColor = mix(img1,img2,params[1]); + ivec2 P = ivec2(gl_FragCoord.xy); + vec4 buf = imageLoad(backbuffer,P); + buf.rg = buf.gr; + //buf.b = 0.0; + vec4 i = mix(img1,img2,0.5); + //P = ivec2(gl_FragCoord.xy); + imageStore(backbuffer,P,i); + i = mix(i,buf,0.8); + //i = image(0); + fragColor = i; } diff --git a/sv.c b/sv.c index 461e434..61d6c06 100644 --- a/sv.c +++ b/sv.c @@ -17,6 +17,7 @@ GLFWwindow* window; GLuint vertex; GLuint fragment; GLuint shaderProgram; +GLuint backbuffer; int bars; typedef struct Shad { @@ -62,6 +63,16 @@ const char * readShader(char * path) { return c_str; } +/* +attach_shader(program, GL_VERTEX_SHADER, R"( + #version 450 core + layout(location=0) in vec2 coord; + void main(void) { + gl_Position = vec4(coord, 0.0, 1.0); + } +)"); +*/ + GLuint compileShader(const char * source, GLenum type) { GLuint sh = glCreateShader(type); glShaderSource(sh, 1, &source, NULL); @@ -137,8 +148,10 @@ void readImage(int i) { glBindTexture(GL_TEXTURE_2D,images[i].id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); stbi_image_free(pixels); } @@ -216,6 +229,10 @@ int main(int argc, char **argv) { strncpy(images[i-1].path, argv[i],40); images[i-1].new = 1; } + //glActiveTexture(GL_TEXTURE4); + glCreateTextures(GL_TEXTURE_2D,1,&backbuffer); + glTextureStorage2D(backbuffer,1,GL_RGBA32F,width,height); + glBindImageTexture(0,backbuffer, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F); pthread_t stdin_t; pthread_create(&stdin_t, NULL, readStdin, NULL); -- cgit v1.2.3