DXGL r80 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r79‎ | r80 | r81 >
Date:02:38, 17 January 2012
Author:admin
Status:new
Tags:
Comment:
Clean up GL objects on shutdown
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glExtensions.cpp (modified) (history)
  • /ddraw/glExtensions.h (modified) (history)
  • /ddraw/glutil.cpp (modified) (history)
  • /ddraw/glutil.h (modified) (history)
  • /ddraw/shaders.cpp (modified) (history)
  • /ddraw/shaders.h (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -1264,6 +1264,8 @@
12651265 {
12661266 if(hRC)
12671267 {
 1268+ DeleteShaders();
 1269+ DeleteFBO();
12681270 wglMakeCurrent(NULL,NULL);
12691271 wglDeleteContext(hRC);
12701272 };
Index: ddraw/glExtensions.cpp
@@ -21,6 +21,7 @@
2222 GLuint (APIENTRY *glCreateShader) (GLenum type) = NULL;
2323 void (APIENTRY *glShaderSource) (GLuint shader, GLsizei count, const GLchar** string, const GLint* length) = NULL;
2424 void (APIENTRY *glCompileShader) (GLuint shader) = NULL;
 25+void (APIENTRY *glDeleteShader) (GLuint shader) = NULL;
2526 GLuint (APIENTRY *glCreateProgram) () = NULL;
2627 void (APIENTRY *glDeleteProgram) (GLuint program) = NULL;
2728 void (APIENTRY *glGetProgramiv) (GLuint program, GLenum pname, GLint* params) = NULL;
@@ -35,6 +36,7 @@
3637 void (APIENTRY *glBindRenderbuffer) (GLenum target, GLuint renderbuffer) = NULL;
3738 void (APIENTRY *glFramebufferTexture2D) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) = NULL;
3839 GLenum (APIENTRY *glCheckFramebufferStatus) (GLenum target) = NULL;
 40+void (APIENTRY *glDeleteFramebuffers) (GLsizei n, const GLuint *framebuffers) = NULL;
3941
4042 void (APIENTRY *glGenFramebuffersEXT) (GLsizei n, GLuint* ids) = NULL;
4143 void (APIENTRY *glBindFramebufferEXT) (GLenum target, GLuint framebuffer) = NULL;
@@ -42,6 +44,7 @@
4345 void (APIENTRY *glBindRenderbufferEXT) (GLenum target, GLuint renderbuffer) = NULL;
4446 void (APIENTRY *glFramebufferTexture2DEXT) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) = NULL;
4547 GLenum (APIENTRY *glCheckFramebufferStatusEXT) (GLenum target) = NULL;
 48+void (APIENTRY *glDeleteFramebuffersEXT) (GLsizei n, const GLuint *framebuffers) = NULL;
4649
4750 GLint (APIENTRY *glGetUniformLocation) (GLuint program, const GLchar* name) = NULL;
4851 void (APIENTRY *glUniform1i) (GLint location, GLint v0) = NULL;
@@ -86,6 +89,7 @@
8790 glCreateShader = (PFNGLCREATESHADERPROC)wglGetProcAddress("glCreateShader");
8891 glShaderSource = (PFNGLSHADERSOURCEPROC)wglGetProcAddress("glShaderSource");
8992 glCompileShader = (PFNGLCOMPILESHADERPROC)wglGetProcAddress("glCompileShader");
 93+ glDeleteShader = (PFNGLDELETESHADERPROC)wglGetProcAddress("glDeleteShader");
9094 glCreateProgram = (PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram");
9195 glDeleteProgram = (PFNGLDELETEPROGRAMPROC)wglGetProcAddress("glDeleteProgram");
9296 glGetProgramiv = (PFNGLGETPROGRAMIVPROC)wglGetProcAddress("glGetProgramiv");
@@ -119,6 +123,7 @@
120124 glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)wglGetProcAddress("glBindRenderbuffer");
121125 glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)wglGetProcAddress("glFramebufferTexture2D");
122126 glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)wglGetProcAddress("glCheckFramebufferStatus");
 127+ glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)wglGetProcAddress("glDeleteFramebuffers");
123128 }
124129 if(GLEXT_EXT_framebuffer_object)
125130 {
@@ -128,6 +133,7 @@
129134 glBindRenderbufferEXT = (PFNGLBINDRENDERBUFFEREXTPROC)wglGetProcAddress("glBindRenderbufferEXT");
130135 glFramebufferTexture2DEXT = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC)wglGetProcAddress("glFramebufferTexture2D");
131136 glCheckFramebufferStatusEXT = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)wglGetProcAddress("glCheckFramebufferStatusEXT");
 137+ glDeleteFramebuffersEXT = (PFNGLDELETEFRAMEBUFFERSEXTPROC)wglGetProcAddress("glDeleteFramebuffersEXT");
132138 }
133139 wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
134140 wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC)wglGetProcAddress("wglGetSwapIntervalEXT");
Index: ddraw/glExtensions.h
@@ -41,6 +41,7 @@
4242 GLAPI GLuint (APIENTRY *glCreateShader) (GLenum type);
4343 GLAPI void (APIENTRY *glShaderSource) (GLuint shader, GLsizei count, const GLchar** string, const GLint* length);
4444 GLAPI void (APIENTRY *glCompileShader) (GLuint shader);
 45+GLAPI void (APIENTRY *glDeleteShader) (GLuint shader);
4546 GLAPI GLuint (APIENTRY *glCreateProgram) ();
4647 GLAPI void (APIENTRY *glDeleteProgram) (GLuint program);
4748 GLAPI void (APIENTRY *glGetProgramiv) (GLuint program, GLenum pname, GLint* params);
@@ -55,6 +56,7 @@
5657 GLAPI void (APIENTRY *glBindRenderbuffer) (GLenum target, GLuint renderbuffer);
5758 GLAPI void (APIENTRY *glFramebufferTexture2D) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
5859 GLAPI GLenum (APIENTRY *glCheckFramebufferStatus) (GLenum target);
 60+GLAPI void (APIENTRY *glDeleteFramebuffers) (GLsizei n, const GLuint *framebuffers);
5961
6062 GLAPI void (APIENTRY *glGenFramebuffersEXT) (GLsizei n, GLuint* ids);
6163 GLAPI void (APIENTRY *glBindFramebufferEXT) (GLenum target, GLuint framebuffer);
@@ -62,6 +64,7 @@
6365 GLAPI void (APIENTRY *glBindRenderbufferEXT) (GLenum target, GLuint renderbuffer);
6466 GLAPI void (APIENTRY *glFramebufferTexture2DEXT) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
6567 GLAPI GLenum (APIENTRY *glCheckFramebufferStatusEXT) (GLenum target);
 68+GLAPI void (APIENTRY *glDeleteFramebuffersEXT) (GLsizei n, const GLuint *framebuffers);
6669
6770 GLAPI GLint (APIENTRY *glGetUniformLocation) (GLuint program, const GLchar* name);
6871 GLAPI void (APIENTRY *glUniform1i) (GLint location, GLint v0);
Index: ddraw/glutil.cpp
@@ -38,6 +38,15 @@
3939 }
4040 }
4141
 42+void DeleteFBO()
 43+{
 44+ glBindFramebuffer(GL_FRAMEBUFFER,0);
 45+ if(GLEXT_ARB_framebuffer_object)
 46+ glDeleteFramebuffers(1,&fbo);
 47+ else if(GLEXT_EXT_framebuffer_object)
 48+ glDeleteFramebuffersEXT(1,&fbo);
 49+}
 50+
4251 GLenum SetFBO(GLint color, GLint z, bool stencil)
4352 {
4453 GLenum error;
Index: ddraw/glutil.h
@@ -24,6 +24,7 @@
2525 extern bool stencil;
2626
2727 void InitFBO();
 28+void DeleteFBO();
2829 GLenum SetFBO(GLint color, GLint z, bool stencil);
2930
3031 #endif //_GLUTIL_H
\ No newline at end of file
Index: ddraw/shaders.cpp
@@ -147,3 +147,26 @@
148148 glLinkProgram(shaders[i].prog);
149149 }
150150 }
 151+
 152+void DeleteShaders()
 153+{
 154+ glUseProgram(0);
 155+ for(int i = 0; i < NumberOfShaders; i++)
 156+ {
 157+ if(shaders[i].prog)
 158+ {
 159+ glDeleteProgram(shaders[i].prog);
 160+ shaders[i].prog = 0;
 161+ }
 162+ if(shaders[i].vs)
 163+ {
 164+ glDeleteShader(shaders[i].vs);
 165+ shaders[i].vs = 0;
 166+ }
 167+ if(shaders[i].fs)
 168+ {
 169+ glDeleteShader(shaders[i].fs);
 170+ shaders[i].fs = 0;
 171+ }
 172+ }
 173+}
\ No newline at end of file
Index: ddraw/shaders.h
@@ -38,5 +38,6 @@
3939 #define PROG_2CKEY 5
4040
4141 void CompileShaders();
 42+void DeleteShaders();
4243
4344 #endif //__SHADERS_H
\ No newline at end of file