Browse Source

got rid of a memory leak

naelstrof 7 years ago
parent
commit
2fbfd34067
3 changed files with 1 additions and 25 deletions
  1. 0
    20
      src/shader.cpp
  2. 0
    1
      src/shader.hpp
  3. 1
    4
      src/window.cpp

+ 0
- 20
src/shader.cpp View File

3
 Shader::Shader( std::string vert, std::string frag) {
3
 Shader::Shader( std::string vert, std::string frag) {
4
     vert = resource->getRealPath(vert);
4
     vert = resource->getRealPath(vert);
5
     frag = resource->getRealPath(frag);
5
     frag = resource->getRealPath(frag);
6
-    m_good = false;
7
     // Create the program to link to.
6
     // Create the program to link to.
8
     m_program = glCreateProgram();
7
     m_program = glCreateProgram();
9
 
8
 
64
     // Clean up :)
63
     // Clean up :)
65
     glDeleteShader( vertShader );
64
     glDeleteShader( vertShader );
66
     glDeleteShader( fragShader );
65
     glDeleteShader( fragShader );
67
-    m_good = true;
68
     glUseProgram( 0 );
66
     glUseProgram( 0 );
69
 }
67
 }
70
 
68
 
119
 }
117
 }
120
 
118
 
121
 unsigned int Shader::getUniformLocation( std::string name ) {
119
 unsigned int Shader::getUniformLocation( std::string name ) {
122
-    if ( !m_good ) {
123
-        return 0;
124
-    }
125
     glUseProgram( m_program );
120
     glUseProgram( m_program );
126
     return glGetUniformLocation( m_program, name.c_str() );
121
     return glGetUniformLocation( m_program, name.c_str() );
127
 }
122
 }
128
 
123
 
129
 void Shader::setParameter( std::string name, int foo ) {
124
 void Shader::setParameter( std::string name, int foo ) {
130
-    if ( !m_good ) {
131
-        return;
132
-    }
133
     glUniform1i( getUniformLocation( name ), foo );
125
     glUniform1i( getUniformLocation( name ), foo );
134
 }
126
 }
135
 
127
 
136
 void Shader::setParameter( std::string name, float foo ) {
128
 void Shader::setParameter( std::string name, float foo ) {
137
-    if ( !m_good ) {
138
-        return;
139
-    }
140
     glUniform1f( getUniformLocation( name ), foo );
129
     glUniform1f( getUniformLocation( name ), foo );
141
 }
130
 }
142
 
131
 
143
 void Shader::setParameter( std::string name, glm::mat4& foo ) {
132
 void Shader::setParameter( std::string name, glm::mat4& foo ) {
144
-    if ( !m_good ) {
145
-        return;
146
-    }
147
     glUniformMatrix4fv( getUniformLocation( name ), 1, GL_FALSE, glm::value_ptr( foo ) );
133
     glUniformMatrix4fv( getUniformLocation( name ), 1, GL_FALSE, glm::value_ptr( foo ) );
148
 }
134
 }
149
 
135
 
150
 void Shader::setParameter( std::string name, glm::vec4 foo ) {
136
 void Shader::setParameter( std::string name, glm::vec4 foo ) {
151
-    if ( !m_good ) {
152
-        return;
153
-    }
154
     glUniform4f( getUniformLocation( name ), foo.x, foo.y, foo.z, foo.w );
137
     glUniform4f( getUniformLocation( name ), foo.x, foo.y, foo.z, foo.w );
155
 }
138
 }
156
 
139
 
157
 void Shader::setParameter( std::string name, glm::vec2 foo ) {
140
 void Shader::setParameter( std::string name, glm::vec2 foo ) {
158
-    if ( !m_good ) {
159
-        return;
160
-    }
161
     glUniform2f( getUniformLocation( name ), foo.x, foo.y );
141
     glUniform2f( getUniformLocation( name ), foo.x, foo.y );
162
 }
142
 }
163
 
143
 

+ 0
- 1
src/shader.hpp View File

49
     void            setAttribute( std::string name, unsigned int buffer, unsigned int stepsize );
49
     void            setAttribute( std::string name, unsigned int buffer, unsigned int stepsize );
50
 private:
50
 private:
51
     std::vector<unsigned int>   m_activeattribs;
51
     std::vector<unsigned int>   m_activeattribs;
52
-    bool                        m_good;
53
     unsigned int                getUniformLocation( std::string );
52
     unsigned int                getUniformLocation( std::string );
54
     int                         compile( unsigned int shader, std::string& error );
53
     int                         compile( unsigned int shader, std::string& error );
55
     int                         link( unsigned int vert, unsigned int frag, std::string& error );
54
     int                         link( unsigned int vert, unsigned int frag, std::string& error );

+ 1
- 4
src/window.cpp View File

62
     }
62
     }
63
     framebuffer = new Framebuffer( WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
63
     framebuffer = new Framebuffer( WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
64
 
64
 
65
-    // Then we do a basic double clear (double buffered).
66
     glViewport( 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
65
     glViewport( 0, 0, WidthOfScreen( x11->screen ), HeightOfScreen( x11->screen ) );
67
     camera = glm::ortho( 0.0f, (float)WidthOfScreen( x11->screen ), (float)HeightOfScreen( x11->screen ), 0.0f, -1.0f, 1.0f);
66
     camera = glm::ortho( 0.0f, (float)WidthOfScreen( x11->screen ), (float)HeightOfScreen( x11->screen ), 0.0f, -1.0f, 1.0f);
68
-    glClearColor( 0, 0, 0, 0 );
69
-    glClear( GL_COLOR_BUFFER_BIT );
70
-    display();
71
 
67
 
72
     // Make it so all input falls through
68
     // Make it so all input falls through
73
     XRectangle rect;
69
     XRectangle rect;
87
     glClearColor( 0, 0, 0, 0 );
83
     glClearColor( 0, 0, 0, 0 );
88
     glClear( GL_COLOR_BUFFER_BIT );
84
     glClear( GL_COLOR_BUFFER_BIT );
89
     display();
85
     display();
86
+    glXDestroyContext( x11->display, context );
90
     XDestroyWindow( x11->display, window );
87
     XDestroyWindow( x11->display, window );
91
 }
88
 }
92
 
89