DXGL r81 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r80‎ | r81 | r82 >
Date:02:08, 18 January 2012
Author:admin
Status:new
Tags:
Comment:
Release 0.1.4
Use generic attributes for vertex shaders
Fix debug messages
Modified paths:
  • /common/version.h (modified) (history)
  • /common/version.nsh (modified) (history)
  • /ddraw/common.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glExtensions.cpp (modified) (history)
  • /ddraw/glExtensions.h (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)
  • /ddraw/shaders.cpp (modified) (history)

Diff [purge]

Index: common/version.h
@@ -4,12 +4,12 @@
55
66 #define DXGLMAJOR 0
77 #define DXGLMINOR 1
8 -#define DXGLPOINT 3
 8+#define DXGLPOINT 4
99 #define DXGLBUILD 0
1010
1111 #define DXGLVERNUMBER DXGLMAJOR,DXGLMINOR,DXGLPOINT,DXGLBUILD
1212 #define DXGLVERQWORD (((unsigned __int64)DXGLMAJOR<<48)+((unsigned __int64)DXGLMINOR<<32)+((unsigned __int64)DXGLPOINT<<16)+(unsigned __int64)DXGLBUILD)
13 -#define DXGLVERSTRING "0.1.3.0"
 13+#define DXGLVERSTRING "0.1.4.0"
1414
1515
1616 #endif //__VERSION_H
Index: common/version.nsh
@@ -1 +1 @@
2 -!define PRODUCT_VERSION "0.1.3"
\ No newline at end of file
 2+!define PRODUCT_VERSION "0.1.4"
\ No newline at end of file
Index: ddraw/common.h
@@ -60,7 +60,8 @@
6161 OutputDebugStringA("DEBUG: ");\
6262 OutputDebugStringA(x);\
6363 }
64 -#define STR(x) #x
 64+#define STR2(x) #x
 65+#define STR(x) STR2(x)
6566 #ifdef _DEBUG
6667 #define ERR(error) \
6768 {\
Index: ddraw/glDirectDrawSurface.cpp
@@ -709,16 +709,25 @@
710710 GLint texloc = glGetUniformLocation(shaders[PROG_TEXTURE].prog,"Texture");
711711 glUniform1i(texloc,0);
712712 }
713 - GLint viewloc = glGetUniformLocation(GetProgram()&0xffffffff,"view");
 713+ GLuint prog = GetProgram()&0xffffffff;
 714+ GLint viewloc = glGetUniformLocation(prog,"view");
714715 glUniform4f(viewloc,0,(GLfloat)fakex,0,(GLfloat)fakey);
715716 this->dirty |= 2;
716 - glEnableClientState(GL_VERTEX_ARRAY);
717 - glVertexPointer(2,GL_FLOAT,sizeof(BltVertex),&bltvertices[0].x);
718 - glEnableClientState(GL_COLOR_ARRAY);
719 - glColorPointer(3,GL_UNSIGNED_BYTE,sizeof(BltVertex),&bltvertices[0].r);
720 - glClientActiveTexture(GL_TEXTURE0);
721 - glEnableClientState(GL_TEXTURE_COORD_ARRAY);
722 - glTexCoordPointer(2,GL_FLOAT,sizeof(BltVertex),&bltvertices[0].s);
 717+ GLint xyloc = glGetAttribLocation(prog,"xy");
 718+ glEnableVertexAttribArray(xyloc);
 719+ glVertexAttribPointer(xyloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].x);
 720+ if(dwFlags & DDBLT_COLORFILL)
 721+ {
 722+ GLint rgbloc = glGetAttribLocation(prog,"rgb");
 723+ glEnableVertexAttribArray(rgbloc);
 724+ glVertexAttribPointer(rgbloc,3,GL_UNSIGNED_BYTE,true,sizeof(BltVertex),&bltvertices[0].r);
 725+ }
 726+ else
 727+ {
 728+ GLint stloc = glGetAttribLocation(prog,"st");
 729+ glEnableVertexAttribArray(stloc);
 730+ glVertexAttribPointer(stloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].s);
 731+ }
723732 glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
724733 glDisable(GL_TEXTURE_2D);
725734 SetFBO(0,0,false);
@@ -1201,11 +1210,12 @@
12021211 }
12031212 bltvertices[0].s = bltvertices[0].t = bltvertices[1].t = bltvertices[2].s = 1.;
12041213 bltvertices[1].s = bltvertices[2].t = bltvertices[3].s = bltvertices[3].t = 0.;
1205 - glEnableClientState(GL_VERTEX_ARRAY);
1206 - glVertexPointer(2,GL_FLOAT,sizeof(BltVertex),&bltvertices[0].x);
1207 - glClientActiveTexture(GL_TEXTURE0);
1208 - glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1209 - glTexCoordPointer(2,GL_FLOAT,sizeof(BltVertex),&bltvertices[0].s);
 1214+ GLint xyloc = glGetAttribLocation(prog,"xy");
 1215+ glEnableVertexAttribArray(xyloc);
 1216+ glVertexAttribPointer(xyloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].x);
 1217+ GLint stloc = glGetAttribLocation(prog,"st");
 1218+ glEnableVertexAttribArray(stloc);
 1219+ glVertexAttribPointer(stloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].s);
12101220 glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
12111221 glDisable(GL_TEXTURE_2D);
12121222 glFlush();
Index: ddraw/glExtensions.cpp
@@ -30,6 +30,10 @@
3131 void (APIENTRY *glLinkProgram) (GLuint program) = NULL;
3232 void (APIENTRY *glUseProgram) (GLuint program) = NULL;
3333
 34+GLint (APIENTRY *glGetAttribLocation) (GLuint program, const GLchar* name) = NULL;
 35+void (APIENTRY *glVertexAttribPointer) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer) = NULL;
 36+void (APIENTRY *glEnableVertexAttribArray) (GLuint index) = NULL;
 37+
3438 void (APIENTRY *glGenFramebuffers) (GLsizei n, GLuint* ids) = NULL;
3539 void (APIENTRY *glBindFramebuffer) (GLenum target, GLuint framebuffer) = NULL;
3640 void (APIENTRY *glGenRenderbuffers) (GLsizei n, GLuint* renderbuffers) = NULL;
@@ -107,6 +111,9 @@
108112 glUniform3f = (PFNGLUNIFORM3FPROC)wglGetProcAddress("glUniform3f");
109113 glUniform4f = (PFNGLUNIFORM4FPROC)wglGetProcAddress("glUniform4f");
110114 glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)wglGetProcAddress("glUniformMatrix4fv");
 115+ glGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC)wglGetProcAddress("glGetAttribLocation");
 116+ glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)wglGetProcAddress("glVertexAttribPointer");
 117+ glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)wglGetProcAddress("glEnableVertexAttribArray");
111118 }
112119 const GLubyte *glextensions = glGetString(GL_EXTENSIONS);
113120 if(strstr((char*)glextensions,"GL_ARB_framebuffer_object")) GLEXT_ARB_framebuffer_object = 1;
Index: ddraw/glExtensions.h
@@ -50,6 +50,10 @@
5151 GLAPI void (APIENTRY *glLinkProgram) (GLuint program);
5252 GLAPI void (APIENTRY *glUseProgram) (GLuint program);
5353
 54+GLAPI GLint (APIENTRY *glGetAttribLocation) (GLuint program, const GLchar* name);
 55+GLAPI void (APIENTRY *glVertexAttribPointer) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer);
 56+GLAPI void (APIENTRY *glEnableVertexAttribArray) (GLuint index);
 57+
5458 GLAPI void (APIENTRY *glGenFramebuffers) (GLsizei n, GLuint* ids);
5559 GLAPI void (APIENTRY *glBindFramebuffer) (GLenum target, GLuint framebuffer);
5660 GLAPI void (APIENTRY *glGenRenderbuffers) (GLsizei n, GLuint* renderbuffers);
Index: ddraw/shadergen.cpp
@@ -19,7 +19,12 @@
2020 #include "shadergen.h"
2121 #include "shaders.h"
2222
23 -SHADER genshaders[256];
 23+struct GenShader
 24+{
 25+ SHADER shader;
 26+ __int64 id;
 27+};
 28+GenShader genshaders[256];
2429 static __int64 current_shader = 0;
2530 static int shadercount = 0;
2631 static bool initialized = false;
@@ -28,10 +33,13 @@
2934 void SetShader(__int64 id, bool builtin)
3035 {
3136 if(builtin)
32 - {
33 - glUseProgram(shaders[id].prog);
34 - current_shader = shaders[id].prog;
35 - }
 37+ {
 38+ glUseProgram(shaders[id].prog);
 39+ current_shader = shaders[id].prog;
 40+ }
 41+ else
 42+ {
 43+ }
3644 }
3745
3846 GLuint GetProgram()
@@ -42,3 +50,29 @@
4351 return 0;
4452 }
4553 }
 54+
 55+#define REVISION 1
 56+static const char header[] =
 57+ "//REV" STR(REVISION) "\n\
 58+#version 110\n";
 59+static const char vertexshader[] = "//Vertex Shader\n";
 60+static const char fragshader[] = "//Fragment Shader\n";
 61+static const char idheader[] = "//ID: 0x";
 62+static const char linefeed[] = "\n";
 63+static const char mainstart[] = "void main()\n{\n";
 64+static const char mainend[] = "} ";
 65+static const char attr_xy[] = "attribute vec2 xy;\n";
 66+static const char conv_xy[] = "vec4 xyzw = vec4(xy[0],xy[1],0,1);\n";
 67+static const char attr_xyz[] = "attribute vec3 xyz;\n";
 68+static const char conv_xyz[] = "vec4 xyzw = vec4(xyz[0],xyz[1],xyz[2],1);\n";
 69+static const char attr_xyzw[] = "attribute vec4 xyzw;\n";
 70+static const char attr_rgb[] = "attrib vec3 rgb;\n";
 71+static const char conv_rgb[] = "vec4 rgba = vec4(rgb[0],rgb[1],rgb[2],1);\n";
 72+static const char attr_rgba[] = "attrib vec4 rgba;\n";
 73+static const char attr_s[] = "attrib float sX;\n";
 74+static const char conv_s[] = "vec4 strqX = vec4(sX,0,0,1);\n";
 75+static const char attr_st[] = "attrib vec2 stX;\n";
 76+static const char conv_st[] = "vec4 strqX = vec4(stX[0],stX[1],0,1);\n";
 77+static const char attr_str[] = "attrib vec3 strX;\n";
 78+static const char conv_str[] = "vec4 strqX = vec4(strX[0],strX[1],strX[2],1);\n";
 79+static const char attr_strq[] = "attrib vec4 strqX;\n";
\ No newline at end of file
Index: ddraw/shaders.cpp
@@ -90,8 +90,14 @@
9191 const char vert_ortho[] = "\
9292 #version 110\n\
9393 uniform vec4 view;\n\
 94+attribute vec2 xy;\n\
 95+attribute vec3 rgb;\n\
 96+attribute vec2 st;\n\
9497 void main()\n\
9598 {\n\
 99+ vec4 xyzw = vec4(xy[0],xy[1],0,1);\n\
 100+ vec4 rgba = vec4(rgb[0],rgb[1],rgb[2],1);\n\
 101+ vec4 strq = vec4(st[0],st[1],0,1);\n\
96102 mat4 proj = mat4(\n\
97103 vec4(2.0 / (view[1] - view[0]), 0, 0, 0),\n\
98104 vec4(0, 2.0 / (view[2] - view[3]), 0, 0),\n\
@@ -98,9 +104,9 @@
99105 vec4(0, 0, -2.0, 0),\n\
100106 vec4(-(view[1] + view[0]) / (view[1] - view[0]),\n\
101107 -(view[2] + view[3]) / (view[2] - view[3]), -1 , 1));\n\
102 - gl_Position = proj * gl_Vertex;\n\
103 - gl_FrontColor = gl_Color;\n\
104 - gl_TexCoord[0] = gl_MultiTexCoord0;\n\
 108+ gl_Position = proj * xyzw;\n\
 109+ gl_FrontColor = rgba;\n\
 110+ gl_TexCoord[0] = strq;\n\
105111 } ";
106112
107113