From f51020164ec26a750ae4696bfae630d32ad5f5bf Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 18 Jan 2012 02:08:05 +0000 Subject: [PATCH] Release 0.1.4 Use generic attributes for vertex shaders Fix debug messages git-svn-id: https://www.williamfeely.info/svn/dxgl@81 8a90861a-4eca-46d5-b744-240ff16d0c4d --- common/version.h | 4 ++-- common/version.nsh | 2 +- ddraw/common.h | 3 ++- ddraw/glDirectDrawSurface.cpp | 36 +++++++++++++++++----------- ddraw/glExtensions.cpp | 7 ++++++ ddraw/glExtensions.h | 4 ++++ ddraw/shadergen.cpp | 44 +++++++++++++++++++++++++++++++---- ddraw/shaders.cpp | 12 +++++++--- 8 files changed, 87 insertions(+), 25 deletions(-) diff --git a/common/version.h b/common/version.h index a9d63eb8..3905d600 100644 --- a/common/version.h +++ b/common/version.h @@ -4,12 +4,12 @@ #define DXGLMAJOR 0 #define DXGLMINOR 1 -#define DXGLPOINT 3 +#define DXGLPOINT 4 #define DXGLBUILD 0 #define DXGLVERNUMBER DXGLMAJOR,DXGLMINOR,DXGLPOINT,DXGLBUILD #define DXGLVERQWORD (((unsigned __int64)DXGLMAJOR<<48)+((unsigned __int64)DXGLMINOR<<32)+((unsigned __int64)DXGLPOINT<<16)+(unsigned __int64)DXGLBUILD) -#define DXGLVERSTRING "0.1.3.0" +#define DXGLVERSTRING "0.1.4.0" #endif //__VERSION_H diff --git a/common/version.nsh b/common/version.nsh index 43676d97..acfaa231 100644 --- a/common/version.nsh +++ b/common/version.nsh @@ -1 +1 @@ -!define PRODUCT_VERSION "0.1.3" \ No newline at end of file +!define PRODUCT_VERSION "0.1.4" \ No newline at end of file diff --git a/ddraw/common.h b/ddraw/common.h index a5562c98..1604198e 100644 --- a/ddraw/common.h +++ b/ddraw/common.h @@ -60,7 +60,8 @@ extern const GUID device_template; OutputDebugStringA("DEBUG: ");\ OutputDebugStringA(x);\ } -#define STR(x) #x +#define STR2(x) #x +#define STR(x) STR2(x) #ifdef _DEBUG #define ERR(error) \ {\ diff --git a/ddraw/glDirectDrawSurface.cpp b/ddraw/glDirectDrawSurface.cpp index d6120dd6..d3dc2e5c 100644 --- a/ddraw/glDirectDrawSurface.cpp +++ b/ddraw/glDirectDrawSurface.cpp @@ -709,16 +709,25 @@ HRESULT WINAPI glDirectDrawSurface7::Blt(LPRECT lpDestRect, LPDIRECTDRAWSURFACE7 GLint texloc = glGetUniformLocation(shaders[PROG_TEXTURE].prog,"Texture"); glUniform1i(texloc,0); } - GLint viewloc = glGetUniformLocation(GetProgram()&0xffffffff,"view"); + GLuint prog = GetProgram()&0xffffffff; + GLint viewloc = glGetUniformLocation(prog,"view"); glUniform4f(viewloc,0,(GLfloat)fakex,0,(GLfloat)fakey); this->dirty |= 2; - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2,GL_FLOAT,sizeof(BltVertex),&bltvertices[0].x); - glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(3,GL_UNSIGNED_BYTE,sizeof(BltVertex),&bltvertices[0].r); - glClientActiveTexture(GL_TEXTURE0); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2,GL_FLOAT,sizeof(BltVertex),&bltvertices[0].s); + GLint xyloc = glGetAttribLocation(prog,"xy"); + glEnableVertexAttribArray(xyloc); + glVertexAttribPointer(xyloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].x); + if(dwFlags & DDBLT_COLORFILL) + { + GLint rgbloc = glGetAttribLocation(prog,"rgb"); + glEnableVertexAttribArray(rgbloc); + glVertexAttribPointer(rgbloc,3,GL_UNSIGNED_BYTE,true,sizeof(BltVertex),&bltvertices[0].r); + } + else + { + GLint stloc = glGetAttribLocation(prog,"st"); + glEnableVertexAttribArray(stloc); + glVertexAttribPointer(stloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].s); + } glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices); glDisable(GL_TEXTURE_2D); SetFBO(0,0,false); @@ -1201,11 +1210,12 @@ void glDirectDrawSurface7::RenderScreen(GLuint texture, glDirectDrawSurface7 *su } bltvertices[0].s = bltvertices[0].t = bltvertices[1].t = bltvertices[2].s = 1.; bltvertices[1].s = bltvertices[2].t = bltvertices[3].s = bltvertices[3].t = 0.; - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2,GL_FLOAT,sizeof(BltVertex),&bltvertices[0].x); - glClientActiveTexture(GL_TEXTURE0); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2,GL_FLOAT,sizeof(BltVertex),&bltvertices[0].s); + GLint xyloc = glGetAttribLocation(prog,"xy"); + glEnableVertexAttribArray(xyloc); + glVertexAttribPointer(xyloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].x); + GLint stloc = glGetAttribLocation(prog,"st"); + glEnableVertexAttribArray(stloc); + glVertexAttribPointer(stloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].s); glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices); glDisable(GL_TEXTURE_2D); glFlush(); diff --git a/ddraw/glExtensions.cpp b/ddraw/glExtensions.cpp index 7737bd3b..f60506ee 100644 --- a/ddraw/glExtensions.cpp +++ b/ddraw/glExtensions.cpp @@ -30,6 +30,10 @@ void (APIENTRY *glDetachShader) (GLuint program, GLuint shader) = NULL; void (APIENTRY *glLinkProgram) (GLuint program) = NULL; void (APIENTRY *glUseProgram) (GLuint program) = NULL; +GLint (APIENTRY *glGetAttribLocation) (GLuint program, const GLchar* name) = NULL; +void (APIENTRY *glVertexAttribPointer) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer) = NULL; +void (APIENTRY *glEnableVertexAttribArray) (GLuint index) = NULL; + void (APIENTRY *glGenFramebuffers) (GLsizei n, GLuint* ids) = NULL; void (APIENTRY *glBindFramebuffer) (GLenum target, GLuint framebuffer) = NULL; void (APIENTRY *glGenRenderbuffers) (GLsizei n, GLuint* renderbuffers) = NULL; @@ -107,6 +111,9 @@ void InitGLExt() glUniform3f = (PFNGLUNIFORM3FPROC)wglGetProcAddress("glUniform3f"); glUniform4f = (PFNGLUNIFORM4FPROC)wglGetProcAddress("glUniform4f"); glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)wglGetProcAddress("glUniformMatrix4fv"); + glGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC)wglGetProcAddress("glGetAttribLocation"); + glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)wglGetProcAddress("glVertexAttribPointer"); + glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)wglGetProcAddress("glEnableVertexAttribArray"); } const GLubyte *glextensions = glGetString(GL_EXTENSIONS); if(strstr((char*)glextensions,"GL_ARB_framebuffer_object")) GLEXT_ARB_framebuffer_object = 1; diff --git a/ddraw/glExtensions.h b/ddraw/glExtensions.h index 389f0f89..baecc75e 100644 --- a/ddraw/glExtensions.h +++ b/ddraw/glExtensions.h @@ -50,6 +50,10 @@ GLAPI void (APIENTRY *glDetachShader) (GLuint program, GLuint shader); GLAPI void (APIENTRY *glLinkProgram) (GLuint program); GLAPI void (APIENTRY *glUseProgram) (GLuint program); +GLAPI GLint (APIENTRY *glGetAttribLocation) (GLuint program, const GLchar* name); +GLAPI void (APIENTRY *glVertexAttribPointer) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer); +GLAPI void (APIENTRY *glEnableVertexAttribArray) (GLuint index); + GLAPI void (APIENTRY *glGenFramebuffers) (GLsizei n, GLuint* ids); GLAPI void (APIENTRY *glBindFramebuffer) (GLenum target, GLuint framebuffer); GLAPI void (APIENTRY *glGenRenderbuffers) (GLsizei n, GLuint* renderbuffers); diff --git a/ddraw/shadergen.cpp b/ddraw/shadergen.cpp index dc5bcdc8..7456cc93 100644 --- a/ddraw/shadergen.cpp +++ b/ddraw/shadergen.cpp @@ -19,7 +19,12 @@ #include "shadergen.h" #include "shaders.h" -SHADER genshaders[256]; +struct GenShader +{ + SHADER shader; + __int64 id; +}; +GenShader genshaders[256]; static __int64 current_shader = 0; static int shadercount = 0; static bool initialized = false; @@ -28,10 +33,13 @@ static bool isbuiltin = true; void SetShader(__int64 id, bool builtin) { if(builtin) - { - glUseProgram(shaders[id].prog); - current_shader = shaders[id].prog; - } + { + glUseProgram(shaders[id].prog); + current_shader = shaders[id].prog; + } + else + { + } } GLuint GetProgram() @@ -42,3 +50,29 @@ GLuint GetProgram() return 0; } } + +#define REVISION 1 +static const char header[] = + "//REV" STR(REVISION) "\n\ +#version 110\n"; +static const char vertexshader[] = "//Vertex Shader\n"; +static const char fragshader[] = "//Fragment Shader\n"; +static const char idheader[] = "//ID: 0x"; +static const char linefeed[] = "\n"; +static const char mainstart[] = "void main()\n{\n"; +static const char mainend[] = "} "; +static const char attr_xy[] = "attribute vec2 xy;\n"; +static const char conv_xy[] = "vec4 xyzw = vec4(xy[0],xy[1],0,1);\n"; +static const char attr_xyz[] = "attribute vec3 xyz;\n"; +static const char conv_xyz[] = "vec4 xyzw = vec4(xyz[0],xyz[1],xyz[2],1);\n"; +static const char attr_xyzw[] = "attribute vec4 xyzw;\n"; +static const char attr_rgb[] = "attrib vec3 rgb;\n"; +static const char conv_rgb[] = "vec4 rgba = vec4(rgb[0],rgb[1],rgb[2],1);\n"; +static const char attr_rgba[] = "attrib vec4 rgba;\n"; +static const char attr_s[] = "attrib float sX;\n"; +static const char conv_s[] = "vec4 strqX = vec4(sX,0,0,1);\n"; +static const char attr_st[] = "attrib vec2 stX;\n"; +static const char conv_st[] = "vec4 strqX = vec4(stX[0],stX[1],0,1);\n"; +static const char attr_str[] = "attrib vec3 strX;\n"; +static const char conv_str[] = "vec4 strqX = vec4(strX[0],strX[1],strX[2],1);\n"; +static const char attr_strq[] = "attrib vec4 strqX;\n"; \ No newline at end of file diff --git a/ddraw/shaders.cpp b/ddraw/shaders.cpp index ed8b2e21..f5016e4b 100644 --- a/ddraw/shaders.cpp +++ b/ddraw/shaders.cpp @@ -90,17 +90,23 @@ void main (void)\n\ const char vert_ortho[] = "\ #version 110\n\ uniform vec4 view;\n\ +attribute vec2 xy;\n\ +attribute vec3 rgb;\n\ +attribute vec2 st;\n\ void main()\n\ {\n\ + vec4 xyzw = vec4(xy[0],xy[1],0,1);\n\ + vec4 rgba = vec4(rgb[0],rgb[1],rgb[2],1);\n\ + vec4 strq = vec4(st[0],st[1],0,1);\n\ mat4 proj = mat4(\n\ vec4(2.0 / (view[1] - view[0]), 0, 0, 0),\n\ vec4(0, 2.0 / (view[2] - view[3]), 0, 0),\n\ vec4(0, 0, -2.0, 0),\n\ vec4(-(view[1] + view[0]) / (view[1] - view[0]),\n\ -(view[2] + view[3]) / (view[2] - view[3]), -1 , 1));\n\ - gl_Position = proj * gl_Vertex;\n\ - gl_FrontColor = gl_Color;\n\ - gl_TexCoord[0] = gl_MultiTexCoord0;\n\ + gl_Position = proj * xyzw;\n\ + gl_FrontColor = rgba;\n\ + gl_TexCoord[0] = strq;\n\ } ";