|
@@ -1,17 +1,17 @@
|
1
|
1
|
#include "framebuffer.hpp"
|
2
|
2
|
|
3
|
3
|
slop::Framebuffer::Framebuffer( int w, int h ) {
|
4
|
|
- glGenFramebuffers( 1, &fbuffer );
|
5
|
|
- glBindFramebuffer( GL_FRAMEBUFFER, fbuffer );
|
6
|
|
- glGenTextures(1, &image);
|
7
|
|
- glBindTexture(GL_TEXTURE_2D, image);
|
8
|
|
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
9
|
|
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
10
|
|
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
11
|
|
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
12
|
|
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
13
|
|
- glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, image, 0);
|
14
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
4
|
+ gl::GenFramebuffers( 1, &fbuffer );
|
|
5
|
+ gl::BindFramebuffer( gl::FRAMEBUFFER, fbuffer );
|
|
6
|
+ gl::GenTextures( 1, &image );
|
|
7
|
+ gl::BindTexture( gl::TEXTURE_2D, image );
|
|
8
|
+ gl::TexImage2D( gl::TEXTURE_2D, 0, gl::RGBA, w, h, 0, gl::RGBA, gl::UNSIGNED_BYTE, NULL );
|
|
9
|
+ gl::TexParameteri( gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST );
|
|
10
|
+ gl::TexParameteri( gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST );
|
|
11
|
+ gl::TexParameteri( gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, gl::CLAMP_TO_EDGE );
|
|
12
|
+ gl::TexParameteri( gl::TEXTURE_2D, gl::TEXTURE_WRAP_T, gl::CLAMP_TO_EDGE );
|
|
13
|
+ gl::FramebufferTexture2D( gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, image, 0 );
|
|
14
|
+ gl::BindFramebuffer( gl::FRAMEBUFFER, 0 );
|
15
|
15
|
// generate our vertex and uv buffers
|
16
|
16
|
std::vector<glm::vec2> verts;
|
17
|
17
|
std::vector<glm::vec2> uvs;
|
|
@@ -29,11 +29,11 @@ slop::Framebuffer::Framebuffer( int w, int h ) {
|
29
|
29
|
verts.push_back( glm::vec2(1,-1) );
|
30
|
30
|
uvs.push_back( glm::vec2( 1, 0 ) );
|
31
|
31
|
|
32
|
|
- glGenBuffers( 2, buffers );
|
33
|
|
- glBindBuffer( GL_ARRAY_BUFFER, buffers[0] );
|
34
|
|
- glBufferData( GL_ARRAY_BUFFER, verts.size() * sizeof( glm::vec2 ), &verts[0], GL_STATIC_DRAW );
|
35
|
|
- glBindBuffer( GL_ARRAY_BUFFER, buffers[1] );
|
36
|
|
- glBufferData( GL_ARRAY_BUFFER, uvs.size() * sizeof( glm::vec2 ), &uvs[0], GL_STATIC_DRAW );
|
|
32
|
+ gl::GenBuffers( 2, buffers );
|
|
33
|
+ gl::BindBuffer( gl::ARRAY_BUFFER, buffers[0] );
|
|
34
|
+ gl::BufferData( gl::ARRAY_BUFFER, verts.size() * sizeof( glm::vec2 ), &verts[0], gl::STATIC_DRAW );
|
|
35
|
+ gl::BindBuffer( gl::ARRAY_BUFFER, buffers[1] );
|
|
36
|
+ gl::BufferData( gl::ARRAY_BUFFER, uvs.size() * sizeof( glm::vec2 ), &uvs[0], gl::STATIC_DRAW );
|
37
|
37
|
vertCount = verts.size();
|
38
|
38
|
generatedDesktopImage = false;
|
39
|
39
|
}
|
|
@@ -45,44 +45,44 @@ void slop::Framebuffer::setShader( slop::Shader* shader ) {
|
45
|
45
|
XGrabServer(x11->display);
|
46
|
46
|
XImage* image = XGetImage( x11->display, x11->root, 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ), 0xffffffff, ZPixmap );
|
47
|
47
|
XUngrabServer(x11->display);
|
48
|
|
- glEnable(GL_TEXTURE_2D);
|
49
|
|
- glGenTextures(1, &desktopImage);
|
50
|
|
- glBindTexture(GL_TEXTURE_2D, desktopImage);
|
51
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
52
|
|
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
53
|
|
- //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
54
|
|
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ), 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)(&(image->data[0])));
|
|
48
|
+ gl::Enable(gl::TEXTURE_2D);
|
|
49
|
+ gl::GenTextures(1, &desktopImage);
|
|
50
|
+ gl::BindTexture(gl::TEXTURE_2D, desktopImage);
|
|
51
|
+ gl::TexParameterf(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST);
|
|
52
|
+ gl::TexParameterf(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST);
|
|
53
|
+ //gl::TexEnvf(gl::TEXTURE_ENV, gl::TEXTURE_ENV_MODE, gl::MODULATE);
|
|
54
|
+ gl::TexImage2D( gl::TEXTURE_2D, 0, gl::RGB, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ), 0, gl::BGRA, gl::UNSIGNED_BYTE, (void*)(&(image->data[0])));
|
55
|
55
|
XDestroyImage( image );
|
56
|
56
|
generatedDesktopImage = true;
|
57
|
57
|
}
|
58
|
58
|
}
|
59
|
59
|
|
60
|
60
|
slop::Framebuffer::~Framebuffer() {
|
61
|
|
- glDeleteTextures(1, &image);
|
62
|
|
- glDeleteFramebuffers(1,&fbuffer);
|
63
|
|
- glDeleteBuffers(2,buffers);
|
|
61
|
+ gl::DeleteTextures(1, &image);
|
|
62
|
+ gl::DeleteFramebuffers(1,&fbuffer);
|
|
63
|
+ gl::DeleteBuffers(2,buffers);
|
64
|
64
|
}
|
65
|
65
|
|
66
|
66
|
void slop::Framebuffer::resize( int w, int h ) {
|
67
|
67
|
// Regenerate the image
|
68
|
|
- glDeleteTextures(1, &image);
|
69
|
|
- glBindTexture(GL_TEXTURE_2D, image);
|
70
|
|
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
71
|
|
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
72
|
|
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
68
|
+ gl::DeleteTextures(1, &image);
|
|
69
|
+ gl::BindTexture(gl::TEXTURE_2D, image);
|
|
70
|
+ gl::TexImage2D( gl::TEXTURE_2D, 0, gl::RGBA, w, h, 0, gl::RGBA, gl::UNSIGNED_BYTE, NULL);
|
|
71
|
+ gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR);
|
|
72
|
+ gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR);
|
73
|
73
|
|
74
|
74
|
// Re-bind it to the framebuffer
|
75
|
|
- glBindFramebuffer( GL_FRAMEBUFFER, fbuffer );
|
76
|
|
- glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, image, 0);
|
77
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
75
|
+ gl::BindFramebuffer( gl::FRAMEBUFFER, fbuffer );
|
|
76
|
+ gl::FramebufferTexture2D( gl::FRAMEBUFFER, gl::COLOR_ATTACHMENT0, gl::TEXTURE_2D, image, 0);
|
|
77
|
+ gl::BindFramebuffer(gl::FRAMEBUFFER, 0);
|
78
|
78
|
}
|
79
|
79
|
|
80
|
80
|
void slop::Framebuffer::bind() {
|
81
|
|
- glBindFramebuffer( GL_FRAMEBUFFER, fbuffer );
|
|
81
|
+ gl::BindFramebuffer( gl::FRAMEBUFFER, fbuffer );
|
82
|
82
|
}
|
83
|
83
|
|
84
|
84
|
void slop::Framebuffer::unbind() {
|
85
|
|
- glBindFramebuffer( GL_FRAMEBUFFER, 0 );
|
|
85
|
+ gl::BindFramebuffer( gl::FRAMEBUFFER, 0 );
|
86
|
86
|
}
|
87
|
87
|
|
88
|
88
|
void slop::Framebuffer::draw(glm::vec2 mouse, float time, glm::vec4 color){
|
|
@@ -102,15 +102,15 @@ void slop::Framebuffer::draw(glm::vec2 mouse, float time, glm::vec4 color){
|
102
|
102
|
if ( shader->hasParameter( "time" ) ) {
|
103
|
103
|
shader->setParameter( "time", time );
|
104
|
104
|
}
|
105
|
|
- glActiveTexture(GL_TEXTURE0);
|
106
|
|
- glBindTexture( GL_TEXTURE_2D, image );
|
|
105
|
+ gl::ActiveTexture(gl::TEXTURE0);
|
|
106
|
+ gl::BindTexture( gl::TEXTURE_2D, image );
|
107
|
107
|
if ( shader->hasParameter( "desktop" ) ) {
|
108
|
108
|
shader->setParameter( "desktop", 1 );
|
109
|
|
- glActiveTexture(GL_TEXTURE0 + 1);
|
110
|
|
- glBindTexture( GL_TEXTURE_2D, desktopImage );
|
|
109
|
+ gl::ActiveTexture(gl::TEXTURE0 + 1);
|
|
110
|
+ gl::BindTexture( gl::TEXTURE_2D, desktopImage );
|
111
|
111
|
}
|
112
|
|
- glEnable( GL_TEXTURE_2D );
|
113
|
|
- glDrawArrays( GL_TRIANGLES, 0, vertCount );
|
114
|
|
- glDisable( GL_TEXTURE_2D );
|
|
112
|
+ gl::Enable( gl::TEXTURE_2D );
|
|
113
|
+ gl::DrawArrays( gl::TRIANGLES, 0, vertCount );
|
|
114
|
+ gl::Disable( gl::TEXTURE_2D );
|
115
|
115
|
shader->unbind();
|
116
|
116
|
}
|