| Index: ddraw/ddraw.vcxproj |
| — | — | @@ -183,6 +183,7 @@ |
| 184 | 184 | <ClInclude Include="include\GL\glext.h" />
|
| 185 | 185 | <ClInclude Include="include\GL\wglext.h" />
|
| 186 | 186 | <ClInclude Include="include\winedef.h" />
|
| | 187 | + <ClInclude Include="matrix.h" />
|
| 187 | 188 | <ClInclude Include="scalers.h" />
|
| 188 | 189 | <ClInclude Include="shadergen.h" />
|
| 189 | 190 | <ClInclude Include="shaders.h" />
|
| — | — | @@ -220,6 +221,7 @@ |
| 221 | 222 | <ClCompile Include="glExtensions.cpp" />
|
| 222 | 223 | <ClCompile Include="glRenderer.cpp" />
|
| 223 | 224 | <ClCompile Include="glutil.cpp" />
|
| | 225 | + <ClCompile Include="matrix.cpp" />
|
| 224 | 226 | <ClCompile Include="precomp.cpp">
|
| 225 | 227 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">Create</PrecompiledHeader>
|
| 226 | 228 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
| Index: ddraw/ddraw.vcxproj.filters |
| — | — | @@ -95,6 +95,9 @@ |
| 96 | 96 | <ClInclude Include="glRenderer.h">
|
| 97 | 97 | <Filter>Header Files</Filter>
|
| 98 | 98 | </ClInclude>
|
| | 99 | + <ClInclude Include="matrix.h">
|
| | 100 | + <Filter>Header Files</Filter>
|
| | 101 | + </ClInclude>
|
| 99 | 102 | </ItemGroup>
|
| 100 | 103 | <ItemGroup>
|
| 101 | 104 | <ClCompile Include="ddraw.cpp">
|
| — | — | @@ -151,6 +154,9 @@ |
| 152 | 155 | <ClCompile Include="glRenderer.cpp">
|
| 153 | 156 | <Filter>Source Files</Filter>
|
| 154 | 157 | </ClCompile>
|
| | 158 | + <ClCompile Include="matrix.cpp">
|
| | 159 | + <Filter>Source Files</Filter>
|
| | 160 | + </ClCompile>
|
| 155 | 161 | </ItemGroup>
|
| 156 | 162 | <ItemGroup>
|
| 157 | 163 | <ResourceCompile Include="ddraw.rc">
|
| Index: ddraw/glDirect3DDevice.cpp |
| — | — | @@ -24,6 +24,7 @@ |
| 25 | 25 | #include "glRenderer.h"
|
| 26 | 26 | #include "shadergen.h"
|
| 27 | 27 | #include "glutil.h"
|
| | 28 | +#include "matrix.h"
|
| 28 | 29 |
|
| 29 | 30 | const DWORD renderstate_default[153] = {0, // 0
|
| 30 | 31 | NULL, //texturehandle
|
| — | — | @@ -119,7 +120,6 @@ |
| 120 | 121 | FALSE, //clipplaneenable
|
| 121 | 122 | };
|
| 122 | 123 |
|
| 123 | | -D3DMATRIX identity;
|
| 124 | 124 |
|
| 125 | 125 | glDirect3DDevice7::glDirect3DDevice7(glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7)
|
| 126 | 126 | {
|
| — | — | @@ -128,14 +128,13 @@ |
| 129 | 129 | diffuse = specular = NULL;
|
| 130 | 130 | ZeroMemory(texcoords,8*sizeof(GLfloat*));
|
| 131 | 131 | memcpy(renderstate,renderstate_default,153*sizeof(DWORD));
|
| 132 | | - identity._11 = identity._22 = identity._33 = identity._44 = 1.0;
|
| 133 | | - identity._12 = identity._13 = identity._14 =
|
| 134 | | - identity._21 = identity._23 = identity._24 =
|
| 135 | | - identity._31 = identity._32 = identity._34 =
|
| 136 | | - identity._41 = identity._42 = identity._43 = 0.0;
|
| 137 | | - matWorld = matView = matProjection = identity;
|
| | 132 | + __gluMakeIdentityf(matWorld);
|
| | 133 | + __gluMakeIdentityf(matView);
|
| | 134 | + __gluMakeIdentityf(matProjection);
|
| | 135 | + __gluMakeIdentityf(matNormal);
|
| 138 | 136 | refcount = 1;
|
| 139 | 137 | inscene = false;
|
| | 138 | + normal_dirty = false;
|
| 140 | 139 | this->glD3D7 = glD3D7;
|
| 141 | 140 | glD3D7->AddRef();
|
| 142 | 141 | this->glDDS7 = glDDS7;
|
| — | — | @@ -605,9 +604,11 @@ |
| 606 | 605 | {
|
| 607 | 606 | case D3DTRANSFORMSTATE_WORLD:
|
| 608 | 607 | memcpy(&matWorld,lpD3DMatrix,sizeof(D3DMATRIX));
|
| | 608 | + normal_dirty = true;
|
| 609 | 609 | return D3D_OK;
|
| 610 | 610 | case D3DTRANSFORMSTATE_VIEW:
|
| 611 | 611 | memcpy(&matView,lpD3DMatrix,sizeof(D3DMATRIX));
|
| | 612 | + normal_dirty = true;
|
| 612 | 613 | return D3D_OK;
|
| 613 | 614 | case D3DTRANSFORMSTATE_PROJECTION:
|
| 614 | 615 | memcpy(&matProjection,lpD3DMatrix,sizeof(D3DMATRIX));
|
| — | — | @@ -627,4 +628,17 @@ |
| 628 | 629 | if(!this) return DDERR_INVALIDPARAMS;
|
| 629 | 630 | FIXME("glDirect3DDevice7::ValidateDevice: stub");
|
| 630 | 631 | ERR(DDERR_GENERIC);
|
| | 632 | +}
|
| | 633 | +
|
| | 634 | +void glDirect3DDevice7::UpdateNormalMatrix()
|
| | 635 | +{
|
| | 636 | + GLfloat worldview[16];
|
| | 637 | + GLfloat tmp[16];
|
| | 638 | + ZeroMemory(&worldview,sizeof(D3DMATRIX));
|
| | 639 | + ZeroMemory(&tmp,sizeof(D3DMATRIX));
|
| | 640 | + __gluMultMatricesf(matWorld,matView,worldview); // Get worldview
|
| | 641 | + if(__gluInvertMatrixf(worldview,tmp)) // Invert
|
| | 642 | + memcpy(matNormal,tmp,16*sizeof(GLfloat));
|
| | 643 | + else memcpy(matNormal,worldview,16*sizeof(GLfloat));
|
| | 644 | + normal_dirty = false;
|
| 631 | 645 | } |
| \ No newline at end of file |
| Index: ddraw/glDirect3DDevice.h |
| — | — | @@ -87,17 +87,22 @@ |
| 88 | 88 | HRESULT WINAPI ValidateDevice(LPDWORD lpdwPasses);
|
| 89 | 89 | void SetArraySize(DWORD size, DWORD vertex, DWORD texcoord);
|
| 90 | 90 | __int64 SelectShader(DWORD VertexType);
|
| | 91 | + void UpdateNormalMatrix();
|
| | 92 | + GLfloat matWorld[16];
|
| | 93 | + GLfloat matView[16];
|
| | 94 | + GLfloat matProjection[16];
|
| | 95 | + GLfloat matNormal[16];
|
| | 96 | + bool normal_dirty;
|
| | 97 | + D3DMATERIAL7 material;
|
| | 98 | + D3DVIEWPORT7 viewport;
|
| | 99 | + glDirect3DLight **lights;
|
| | 100 | + int gllights[8];
|
| 91 | 101 |
|
| 92 | 102 | private:
|
| 93 | | - D3DMATRIX matWorld,matView,matProjection;
|
| 94 | 103 | glDirect3D7 *glD3D7;
|
| 95 | 104 | glDirectDrawSurface7 *glDDS7;
|
| 96 | 105 | ULONG refcount;
|
| 97 | | - D3DVIEWPORT7 viewport;
|
| 98 | 106 | DWORD renderstate[153];
|
| 99 | | - D3DMATERIAL7 material;
|
| 100 | | - glDirect3DLight **lights;
|
| 101 | | - int gllights[8];
|
| 102 | 107 | GLuint gltextures[8];
|
| 103 | 108 | DWORD lightsmax;
|
| 104 | 109 | bool inscene;
|
| Index: ddraw/glExtensions.cpp |
| — | — | @@ -29,6 +29,9 @@ |
| 30 | 30 | void (APIENTRY *glDetachShader) (GLuint program, GLuint shader) = NULL;
|
| 31 | 31 | void (APIENTRY *glLinkProgram) (GLuint program) = NULL;
|
| 32 | 32 | void (APIENTRY *glUseProgram) (GLuint program) = NULL;
|
| | 33 | +void (APIENTRY *glGetShaderiv) (GLuint shader, GLenum pname, GLint* params) = NULL;
|
| | 34 | +void (APIENTRY *glGetShaderInfoLog) (GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog) = NULL;
|
| | 35 | +void (APIENTRY *glGetProgramInfoLog) (GLuint program, GLsizei maxLength, GLsizei *length, GLchar *infolog) = NULL;
|
| 33 | 36 |
|
| 34 | 37 | GLint (APIENTRY *glGetAttribLocation) (GLuint program, const GLchar* name) = NULL;
|
| 35 | 38 | void (APIENTRY *glVertexAttribPointer) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer) = NULL;
|
| — | — | @@ -59,6 +62,8 @@ |
| 60 | 63 | void (APIENTRY *glUniform2f) (GLint location, GLfloat v0, GLfloat v1) = NULL;
|
| 61 | 64 | void (APIENTRY *glUniform3f) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2) = NULL;
|
| 62 | 65 | void (APIENTRY *glUniform4f) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) = NULL;
|
| | 66 | +void (APIENTRY *glUniform3fv) (GLint location, GLsizei count, const GLfloat* value) = NULL;
|
| | 67 | +void (APIENTRY *glUniform4fv) (GLint location, GLsizei count, const GLfloat* value) = NULL;
|
| 63 | 68 | void (APIENTRY *glUniformMatrix4fv) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) = NULL;
|
| 64 | 69 |
|
| 65 | 70 | void (APIENTRY *glDrawRangeElements) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
|
| — | — | @@ -117,6 +122,9 @@ |
| 118 | 123 | glDetachShader = (PFNGLDETACHSHADERPROC)wglGetProcAddress("glDetachShader");
|
| 119 | 124 | glLinkProgram = (PFNGLLINKPROGRAMPROC)wglGetProcAddress("glLinkProgram");
|
| 120 | 125 | glUseProgram = (PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram");
|
| | 126 | + glGetShaderiv = (PFNGLGETSHADERIVPROC)wglGetProcAddress("glGetShaderiv");
|
| | 127 | + glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)wglGetProcAddress("glGetShaderInfoLog");
|
| | 128 | + glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)wglGetProcAddress("glGetProgramInfoLog");
|
| 121 | 129 | glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation");
|
| 122 | 130 | glUniform1i = (PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i");
|
| 123 | 131 | glUniform2i = (PFNGLUNIFORM2IPROC)wglGetProcAddress("glUniform2i");
|
| — | — | @@ -126,6 +134,8 @@ |
| 127 | 135 | glUniform2f = (PFNGLUNIFORM2FPROC)wglGetProcAddress("glUniform2f");
|
| 128 | 136 | glUniform3f = (PFNGLUNIFORM3FPROC)wglGetProcAddress("glUniform3f");
|
| 129 | 137 | glUniform4f = (PFNGLUNIFORM4FPROC)wglGetProcAddress("glUniform4f");
|
| | 138 | + glUniform3fv = (PFNGLUNIFORM3FVPROC)wglGetProcAddress("glUniform3fv");
|
| | 139 | + glUniform4fv = (PFNGLUNIFORM4FVPROC)wglGetProcAddress("glUniform4fv");
|
| 130 | 140 | glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)wglGetProcAddress("glUniformMatrix4fv");
|
| 131 | 141 | glGetAttribLocation = (PFNGLGETATTRIBLOCATIONPROC)wglGetProcAddress("glGetAttribLocation");
|
| 132 | 142 | glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)wglGetProcAddress("glVertexAttribPointer");
|
| Index: ddraw/glExtensions.h |
| — | — | @@ -49,6 +49,9 @@ |
| 50 | 50 | GLAPI void (APIENTRY *glDetachShader) (GLuint program, GLuint shader);
|
| 51 | 51 | GLAPI void (APIENTRY *glLinkProgram) (GLuint program);
|
| 52 | 52 | GLAPI void (APIENTRY *glUseProgram) (GLuint program);
|
| | 53 | +GLAPI void (APIENTRY *glGetShaderiv) (GLuint shader, GLenum pname, GLint* params);
|
| | 54 | +GLAPI void (APIENTRY *glGetShaderInfoLog) (GLuint shader, GLsizei maxLength, GLsizei *length, GLchar *infoLog);
|
| | 55 | +GLAPI void (APIENTRY *glGetProgramInfoLog) (GLuint program, GLsizei maxLength, GLsizei *length, GLchar *infolog);
|
| 53 | 56 |
|
| 54 | 57 | GLAPI GLint (APIENTRY *glGetAttribLocation) (GLuint program, const GLchar* name);
|
| 55 | 58 | GLAPI void (APIENTRY *glVertexAttribPointer) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* pointer);
|
| — | — | @@ -79,6 +82,8 @@ |
| 80 | 83 | GLAPI void (APIENTRY *glUniform2f) (GLint location, GLfloat v0, GLfloat v1);
|
| 81 | 84 | GLAPI void (APIENTRY *glUniform3f) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
|
| 82 | 85 | GLAPI void (APIENTRY *glUniform4f) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
|
| | 86 | +GLAPI void (APIENTRY *glUniform3fv) (GLint location, GLsizei count, const GLfloat* value);
|
| | 87 | +GLAPI void (APIENTRY *glUniform4fv) (GLint location, GLsizei count, const GLfloat* value);
|
| 83 | 88 | GLAPI void (APIENTRY *glUniformMatrix4fv) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
| 84 | 89 |
|
| 85 | 90 | GLAPI void (APIENTRY *glDrawRangeElements) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
|
| Index: ddraw/glRenderer.cpp |
| — | — | @@ -20,6 +20,7 @@ |
| 21 | 21 | #include "glDirectDrawSurface.h"
|
| 22 | 22 | #include "glDirectDrawPalette.h"
|
| 23 | 23 | #include "glDirect3DDevice.h"
|
| | 24 | +#include "glDirect3DLight.h"
|
| 24 | 25 | #include "glRenderer.h"
|
| 25 | 26 | #include "glutil.h"
|
| 26 | 27 | #include "ddraw.h"
|
| — | — | @@ -1024,6 +1025,19 @@ |
| 1025 | 1026 | void glRenderer::_DrawIndexedPrimitive(glDirect3DDevice7 *device, D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
| 1026 | 1027 | LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
|
| 1027 | 1028 | {
|
| | 1029 | + bool transformed;
|
| | 1030 | + int normalptr = 0;
|
| | 1031 | + int colorptr[2] = {0,0};
|
| | 1032 | + int blendptr[5] = {0,0,0,0,0};
|
| | 1033 | + int texptr[8] = {0,0,0,0,0,0,0,0};
|
| | 1034 | + char blendvar[] = "blendX";
|
| | 1035 | + char rgbavar[] = "rgbaX";
|
| | 1036 | + char svar[] = "sX";
|
| | 1037 | + char stvar[] = "stX";
|
| | 1038 | + char strvar[] = "strX";
|
| | 1039 | + char strqvar[] = "strqX";
|
| | 1040 | + int i;
|
| | 1041 | + GLfloat* vertices = (GLfloat*)lpvVertices;
|
| 1028 | 1042 | int drawmode = setdrawmode(d3dptPrimitiveType);
|
| 1029 | 1043 | if(drawmode == -1)
|
| 1030 | 1044 | {
|
| — | — | @@ -1031,8 +1045,132 @@ |
| 1032 | 1046 | wndbusy = false;
|
| 1033 | 1047 | return;
|
| 1034 | 1048 | }
|
| | 1049 | + if((dwVertexTypeDesc & D3DFVF_XYZ) && (dwVertexTypeDesc & D3DFVF_XYZRHW))
|
| | 1050 | + {
|
| | 1051 | + outputs[0] = (void*)DDERR_INVALIDPARAMS;
|
| | 1052 | + wndbusy = false;
|
| | 1053 | + return;
|
| | 1054 | + }
|
| | 1055 | + int ptr = 0;
|
| | 1056 | + if(dwVertexTypeDesc & D3DFVF_XYZ)
|
| | 1057 | + {
|
| | 1058 | + transformed = false;
|
| | 1059 | + ptr+= 3;
|
| | 1060 | + }
|
| | 1061 | + if(dwVertexTypeDesc & D3DFVF_XYZRHW)
|
| | 1062 | + {
|
| | 1063 | + transformed = true;
|
| | 1064 | + ptr+= 4;
|
| | 1065 | + }
|
| | 1066 | + if(!ptr)
|
| | 1067 | + {
|
| | 1068 | + outputs[0] = (void*)DDERR_INVALIDPARAMS;
|
| | 1069 | + wndbusy = false;
|
| | 1070 | + return;
|
| | 1071 | + }
|
| | 1072 | + if(((dwVertexTypeDesc >> 1) & 7) >= 3)
|
| | 1073 | + {
|
| | 1074 | + for(i = 0; i < (signed)(((dwVertexTypeDesc >> 1) & 7) - 2); i++)
|
| | 1075 | + {
|
| | 1076 | + blendptr[(((dwVertexTypeDesc >> 1) & 7) - 2)] = ptr;
|
| | 1077 | + ptr++;
|
| | 1078 | + }
|
| | 1079 | + }
|
| | 1080 | + if(dwVertexTypeDesc & D3DFVF_NORMAL)
|
| | 1081 | + {
|
| | 1082 | + normalptr = ptr;
|
| | 1083 | + ptr+= 3;
|
| | 1084 | + }
|
| | 1085 | + if(dwVertexTypeDesc & D3DFVF_DIFFUSE)
|
| | 1086 | + {
|
| | 1087 | + colorptr[0] = ptr;
|
| | 1088 | + ptr++;
|
| | 1089 | + }
|
| | 1090 | + if(dwVertexTypeDesc & D3DFVF_SPECULAR)
|
| | 1091 | + {
|
| | 1092 | + colorptr[1] = ptr;
|
| | 1093 | + ptr++;
|
| | 1094 | + }
|
| | 1095 | + int stride = NextMultipleOf8(ptr*4);
|
| 1035 | 1096 | SetShader(device->SelectShader(dwVertexTypeDesc),NULL,0);
|
| 1036 | | -
|
| | 1097 | + GLuint prog = GetProgram();
|
| | 1098 | + if(transformed)
|
| | 1099 | + {
|
| | 1100 | + GLint xyzwloc = glGetAttribLocation(prog,"xyzw");
|
| | 1101 | + glEnableVertexAttribArray(xyzwloc);
|
| | 1102 | + glVertexAttribPointer(xyzwloc,4,GL_FLOAT,false,stride,vertices);
|
| | 1103 | + }
|
| | 1104 | + else
|
| | 1105 | + {
|
| | 1106 | + GLint xyzloc = glGetAttribLocation(prog,"xyz");
|
| | 1107 | + glEnableVertexAttribArray(xyzloc);
|
| | 1108 | + glVertexAttribPointer(xyzloc,3,GL_FLOAT,false,stride,vertices);
|
| | 1109 | + }
|
| | 1110 | + for(i = 0; i < 5; i++)
|
| | 1111 | + {
|
| | 1112 | + GLint blendloc;
|
| | 1113 | + if(blendptr[i])
|
| | 1114 | + {
|
| | 1115 | + blendvar[5] = i+'0';
|
| | 1116 | + blendloc = glGetAttribLocation(prog,blendvar);
|
| | 1117 | + glVertexAttribPointer(blendloc,1,GL_FLOAT,false,stride,vertices+blendptr[i]);
|
| | 1118 | + }
|
| | 1119 | + }
|
| | 1120 | + if(normalptr)
|
| | 1121 | + {
|
| | 1122 | + GLint normalloc = glGetAttribLocation(prog,"nxyz");
|
| | 1123 | + glEnableVertexAttribArray(normalloc);
|
| | 1124 | + glVertexAttribPointer(normalloc,3,GL_FLOAT,false,stride,vertices+normalptr);
|
| | 1125 | + }
|
| | 1126 | + for(i = 0; i < 2; i++)
|
| | 1127 | + {
|
| | 1128 | + GLint colorloc;
|
| | 1129 | + if(colorptr[i])
|
| | 1130 | + {
|
| | 1131 | + rgbavar[4] = i + '0';
|
| | 1132 | + colorloc = glGetAttribLocation(prog,rgbavar);
|
| | 1133 | + glVertexAttribPointer(colorloc,4,GL_UNSIGNED_BYTE,true,stride,vertices+colorptr[i]);
|
| | 1134 | + }
|
| | 1135 | + }
|
| | 1136 | + if(device->normal_dirty) device->UpdateNormalMatrix();
|
| | 1137 | + GLint loc = glGetUniformLocation(prog,"world");
|
| | 1138 | + glUniformMatrix4fv(loc,1,false,device->matWorld);
|
| | 1139 | + loc = glGetUniformLocation(prog,"view");
|
| | 1140 | + glUniformMatrix4fv(loc,1,false,device->matView);
|
| | 1141 | + loc = glGetUniformLocation(prog,"projection");
|
| | 1142 | + glUniformMatrix4fv(loc,1,false,device->matProjection);
|
| | 1143 | + loc = glGetUniformLocation(prog,"normalmat");
|
| | 1144 | + glUniformMatrix4fv(loc,1,true,device->matNormal);
|
| | 1145 | + loc = glGetUniformLocation(prog,"material.diffuse");
|
| | 1146 | + glUniform4fv(prog,4,(GLfloat*)&device->material.diffuse);
|
| | 1147 | + loc = glGetUniformLocation(prog,"material.ambient");
|
| | 1148 | + glUniform4fv(prog,4,(GLfloat*)&device->material.ambient);
|
| | 1149 | + loc = glGetUniformLocation(prog,"material.specular");
|
| | 1150 | + glUniform4fv(prog,4,(GLfloat*)&device->material.specular);
|
| | 1151 | + loc = glGetUniformLocation(prog,"material.emissive");
|
| | 1152 | + glUniform4fv(prog,4,(GLfloat*)&device->material.emissive);
|
| | 1153 | + loc = glGetUniformLocation(prog,"material.power");
|
| | 1154 | + glUniform1f(prog,device->material.power);
|
| | 1155 | + int lightindex = 0;
|
| | 1156 | + char lightname[] = "lightX.xxxxxxxxxxxxxxxx";
|
| | 1157 | + for(i = 0; i < 8; i++)
|
| | 1158 | + {
|
| | 1159 | + if(device->gllights[i] != -1)
|
| | 1160 | + {
|
| | 1161 | + lightname[5] = lightindex+'0';
|
| | 1162 | + memcpy((void*)(lightindex+7),"diffuse",8);
|
| | 1163 | + loc = glGetUniformLocation(prog,lightname);
|
| | 1164 | + glUniform4fv(prog,1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvDiffuse);
|
| | 1165 | + memcpy((void*)(lightindex+7),"specular",9);
|
| | 1166 | + loc = glGetUniformLocation(prog,lightname);
|
| | 1167 | + glUniform4fv(prog,1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvSpecular);
|
| | 1168 | + memcpy((void*)(lightindex+7),"ambient",8);
|
| | 1169 | + loc = glGetUniformLocation(prog,lightname);
|
| | 1170 | + glUniform4fv(prog,1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvAmbient);
|
| | 1171 | + }
|
| | 1172 | + }
|
| | 1173 | + // Uniforms
|
| | 1174 | + // struct Light vec3 position,direction float range,falloff,constant,linear,quad,theta,pi uniform lightX
|
| 1037 | 1175 | FIXME("glDirect3DDevice::DrawIndexedPrimitive: stub");
|
| 1038 | 1176 | outputs[0] = (void*)DDERR_GENERIC;
|
| 1039 | 1177 | wndbusy = false;
|
| Index: ddraw/matrix.cpp |
| — | — | @@ -0,0 +1,130 @@ |
| | 2 | +// DXGL
|
| | 3 | +// Copyright (C) 2012 William Feely
|
| | 4 | +
|
| | 5 | +// This library is free software; you can redistribute it and/or
|
| | 6 | +// modify it under the terms of the GNU Lesser General Public
|
| | 7 | +// License as published by the Free Software Foundation; either
|
| | 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| | 9 | +
|
| | 10 | +// This library is distributed in the hope that it will be useful,
|
| | 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| | 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| | 13 | +// Lesser General Public License for more details.
|
| | 14 | +
|
| | 15 | +// You should have received a copy of the GNU Lesser General Public
|
| | 16 | +// License along with this library; if not, write to the Free Software
|
| | 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| | 18 | +
|
| | 19 | +// Portions of this file are from the Mesa library, found in src/glu/sgi/libutil/project.c
|
| | 20 | +// project.c is licensed under the SGI Free Software License B, version 2.0.
|
| | 21 | +/*
|
| | 22 | + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
|
| | 23 | + * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
|
| | 24 | + *
|
| | 25 | + * Permission is hereby granted, free of charge, to any person obtaining a
|
| | 26 | + * copy of this software and associated documentation files (the "Software"),
|
| | 27 | + * to deal in the Software without restriction, including without limitation
|
| | 28 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
| | 29 | + * and/or sell copies of the Software, and to permit persons to whom the
|
| | 30 | + * Software is furnished to do so, subject to the following conditions:
|
| | 31 | + *
|
| | 32 | + * The above copyright notice including the dates of first publication and
|
| | 33 | + * either this permission notice or a reference to
|
| | 34 | + * http://oss.sgi.com/projects/FreeB/
|
| | 35 | + * shall be included in all copies or substantial portions of the Software.
|
| | 36 | + *
|
| | 37 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
| | 38 | + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| | 39 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
| | 40 | + * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| | 41 | + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
| | 42 | + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| | 43 | + * SOFTWARE.
|
| | 44 | + *
|
| | 45 | + * Except as contained in this notice, the name of Silicon Graphics, Inc.
|
| | 46 | + * shall not be used in advertising or otherwise to promote the sale, use or
|
| | 47 | + * other dealings in this Software without prior written authorization from
|
| | 48 | + * Silicon Graphics, Inc.
|
| | 49 | + */
|
| | 50 | +
|
| | 51 | +#include "common.h"
|
| | 52 | +#include "matrix.h"
|
| | 53 | +
|
| | 54 | +/*
|
| | 55 | +** Invert 4x4 matrix.
|
| | 56 | +** Contributed by David Moore (See Mesa bug #6748)
|
| | 57 | +*/
|
| | 58 | +// Converted to float
|
| | 59 | +int __gluInvertMatrixf(const GLfloat m[16], GLfloat invOut[16])
|
| | 60 | +{
|
| | 61 | + GLfloat inv[16], det;
|
| | 62 | + int i;
|
| | 63 | +
|
| | 64 | + inv[0] = m[5]*m[10]*m[15] - m[5]*m[11]*m[14] - m[9]*m[6]*m[15]
|
| | 65 | + + m[9]*m[7]*m[14] + m[13]*m[6]*m[11] - m[13]*m[7]*m[10];
|
| | 66 | + inv[4] = -m[4]*m[10]*m[15] + m[4]*m[11]*m[14] + m[8]*m[6]*m[15]
|
| | 67 | + - m[8]*m[7]*m[14] - m[12]*m[6]*m[11] + m[12]*m[7]*m[10];
|
| | 68 | + inv[8] = m[4]*m[9]*m[15] - m[4]*m[11]*m[13] - m[8]*m[5]*m[15]
|
| | 69 | + + m[8]*m[7]*m[13] + m[12]*m[5]*m[11] - m[12]*m[7]*m[9];
|
| | 70 | + inv[12] = -m[4]*m[9]*m[14] + m[4]*m[10]*m[13] + m[8]*m[5]*m[14]
|
| | 71 | + - m[8]*m[6]*m[13] - m[12]*m[5]*m[10] + m[12]*m[6]*m[9];
|
| | 72 | + inv[1] = -m[1]*m[10]*m[15] + m[1]*m[11]*m[14] + m[9]*m[2]*m[15]
|
| | 73 | + - m[9]*m[3]*m[14] - m[13]*m[2]*m[11] + m[13]*m[3]*m[10];
|
| | 74 | + inv[5] = m[0]*m[10]*m[15] - m[0]*m[11]*m[14] - m[8]*m[2]*m[15]
|
| | 75 | + + m[8]*m[3]*m[14] + m[12]*m[2]*m[11] - m[12]*m[3]*m[10];
|
| | 76 | + inv[9] = -m[0]*m[9]*m[15] + m[0]*m[11]*m[13] + m[8]*m[1]*m[15]
|
| | 77 | + - m[8]*m[3]*m[13] - m[12]*m[1]*m[11] + m[12]*m[3]*m[9];
|
| | 78 | + inv[13] = m[0]*m[9]*m[14] - m[0]*m[10]*m[13] - m[8]*m[1]*m[14]
|
| | 79 | + + m[8]*m[2]*m[13] + m[12]*m[1]*m[10] - m[12]*m[2]*m[9];
|
| | 80 | + inv[2] = m[1]*m[6]*m[15] - m[1]*m[7]*m[14] - m[5]*m[2]*m[15]
|
| | 81 | + + m[5]*m[3]*m[14] + m[13]*m[2]*m[7] - m[13]*m[3]*m[6];
|
| | 82 | + inv[6] = -m[0]*m[6]*m[15] + m[0]*m[7]*m[14] + m[4]*m[2]*m[15]
|
| | 83 | + - m[4]*m[3]*m[14] - m[12]*m[2]*m[7] + m[12]*m[3]*m[6];
|
| | 84 | + inv[10] = m[0]*m[5]*m[15] - m[0]*m[7]*m[13] - m[4]*m[1]*m[15]
|
| | 85 | + + m[4]*m[3]*m[13] + m[12]*m[1]*m[7] - m[12]*m[3]*m[5];
|
| | 86 | + inv[14] = -m[0]*m[5]*m[14] + m[0]*m[6]*m[13] + m[4]*m[1]*m[14]
|
| | 87 | + - m[4]*m[2]*m[13] - m[12]*m[1]*m[6] + m[12]*m[2]*m[5];
|
| | 88 | + inv[3] = -m[1]*m[6]*m[11] + m[1]*m[7]*m[10] + m[5]*m[2]*m[11]
|
| | 89 | + - m[5]*m[3]*m[10] - m[9]*m[2]*m[7] + m[9]*m[3]*m[6];
|
| | 90 | + inv[7] = m[0]*m[6]*m[11] - m[0]*m[7]*m[10] - m[4]*m[2]*m[11]
|
| | 91 | + + m[4]*m[3]*m[10] + m[8]*m[2]*m[7] - m[8]*m[3]*m[6];
|
| | 92 | + inv[11] = -m[0]*m[5]*m[11] + m[0]*m[7]*m[9] + m[4]*m[1]*m[11]
|
| | 93 | + - m[4]*m[3]*m[9] - m[8]*m[1]*m[7] + m[8]*m[3]*m[5];
|
| | 94 | + inv[15] = m[0]*m[5]*m[10] - m[0]*m[6]*m[9] - m[4]*m[1]*m[10]
|
| | 95 | + + m[4]*m[2]*m[9] + m[8]*m[1]*m[6] - m[8]*m[2]*m[5];
|
| | 96 | +
|
| | 97 | + det = m[0]*inv[0] + m[1]*inv[4] + m[2]*inv[8] + m[3]*inv[12];
|
| | 98 | + if (det == 0)
|
| | 99 | + return GL_FALSE;
|
| | 100 | +
|
| | 101 | + det = 1.0f / det;
|
| | 102 | +
|
| | 103 | + for (i = 0; i < 16; i++)
|
| | 104 | + invOut[i] = inv[i] * det;
|
| | 105 | +
|
| | 106 | + return GL_TRUE;
|
| | 107 | +}
|
| | 108 | +
|
| | 109 | +void __gluMultMatricesf(const GLfloat a[16], const GLfloat b[16],
|
| | 110 | + GLfloat r[16])
|
| | 111 | +{
|
| | 112 | + int i, j;
|
| | 113 | +
|
| | 114 | + for (i = 0; i < 4; i++) {
|
| | 115 | + for (j = 0; j < 4; j++) {
|
| | 116 | + r[i*4+j] =
|
| | 117 | + a[i*4+0]*b[0*4+j] +
|
| | 118 | + a[i*4+1]*b[1*4+j] +
|
| | 119 | + a[i*4+2]*b[2*4+j] +
|
| | 120 | + a[i*4+3]*b[3*4+j];
|
| | 121 | + }
|
| | 122 | + }
|
| | 123 | +}
|
| | 124 | +
|
| | 125 | +void __gluMakeIdentityf(GLfloat m[16])
|
| | 126 | +{
|
| | 127 | + m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0;
|
| | 128 | + m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
|
| | 129 | + m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
|
| | 130 | + m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
|
| | 131 | +}
|
| Index: ddraw/matrix.h |
| — | — | @@ -0,0 +1,58 @@ |
| | 2 | +// DXGL
|
| | 3 | +// Copyright (C) 2012 William Feely
|
| | 4 | +
|
| | 5 | +// This library is free software; you can redistribute it and/or
|
| | 6 | +// modify it under the terms of the GNU Lesser General Public
|
| | 7 | +// License as published by the Free Software Foundation; either
|
| | 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| | 9 | +
|
| | 10 | +// This library is distributed in the hope that it will be useful,
|
| | 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| | 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| | 13 | +// Lesser General Public License for more details.
|
| | 14 | +
|
| | 15 | +// You should have received a copy of the GNU Lesser General Public
|
| | 16 | +// License along with this library; if not, write to the Free Software
|
| | 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| | 18 | +
|
| | 19 | +// Portions of this file are from the Mesa library, found in src/glu/sgi/libutil/project.c
|
| | 20 | +// project.c is licensed under the SGI Free Software License B, version 2.0.
|
| | 21 | +/*
|
| | 22 | + * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
|
| | 23 | + * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
|
| | 24 | + *
|
| | 25 | + * Permission is hereby granted, free of charge, to any person obtaining a
|
| | 26 | + * copy of this software and associated documentation files (the "Software"),
|
| | 27 | + * to deal in the Software without restriction, including without limitation
|
| | 28 | + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
| | 29 | + * and/or sell copies of the Software, and to permit persons to whom the
|
| | 30 | + * Software is furnished to do so, subject to the following conditions:
|
| | 31 | + *
|
| | 32 | + * The above copyright notice including the dates of first publication and
|
| | 33 | + * either this permission notice or a reference to
|
| | 34 | + * http://oss.sgi.com/projects/FreeB/
|
| | 35 | + * shall be included in all copies or substantial portions of the Software.
|
| | 36 | + *
|
| | 37 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
| | 38 | + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| | 39 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
| | 40 | + * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| | 41 | + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
| | 42 | + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| | 43 | + * SOFTWARE.
|
| | 44 | + *
|
| | 45 | + * Except as contained in this notice, the name of Silicon Graphics, Inc.
|
| | 46 | + * shall not be used in advertising or otherwise to promote the sale, use or
|
| | 47 | + * other dealings in this Software without prior written authorization from
|
| | 48 | + * Silicon Graphics, Inc.
|
| | 49 | + */
|
| | 50 | +#pragma once
|
| | 51 | +#ifndef _MATRIX_H
|
| | 52 | +#define _MATRIX_H
|
| | 53 | +
|
| | 54 | +int __gluInvertMatrixf(const GLfloat m[16], GLfloat invOut[16]);
|
| | 55 | +void __gluMultMatricesf(const GLfloat a[16], const GLfloat b[16],
|
| | 56 | + GLfloat r[16]);
|
| | 57 | +void __gluMakeIdentityf(GLfloat m[16]);
|
| | 58 | +
|
| | 59 | +#endif //_MATRIX_H |
| \ No newline at end of file |
| Index: ddraw/shadergen.cpp |
| — | — | @@ -43,6 +43,7 @@ |
| 44 | 44 | static int genindex = 0;
|
| 45 | 45 | static bool initialized = false;
|
| 46 | 46 | static bool isbuiltin = true;
|
| | 47 | +GLuint current_prog;
|
| 47 | 48 |
|
| 48 | 49 | /* Bits in Shader ID:
|
| 49 | 50 | Bits 0-1 - Shading mode: 00=flat 01=gouraud 11=phong 10=flat per-pixel
|
| — | — | @@ -148,7 +149,9 @@ |
| 149 | 150 | genindex++;
|
| 150 | 151 | if(genindex == 256) genindex = 0;
|
| 151 | 152 | }
|
| 152 | | - glUseProgram(shaderindex);
|
| | 153 | + genshaders[shaderindex].id = id;
|
| | 154 | + glUseProgram(genshaders[shaderindex].shader.prog);
|
| | 155 | + current_prog = genshaders[shaderindex].shader.prog;
|
| 153 | 156 | }
|
| 154 | 157 | }
|
| 155 | 158 |
|
| — | — | @@ -155,10 +158,7 @@ |
| 156 | 159 | GLuint GetProgram()
|
| 157 | 160 | {
|
| 158 | 161 | if(isbuiltin) return current_shader & 0xFFFFFFFF;
|
| 159 | | - else
|
| 160 | | - {
|
| 161 | | - return 0;
|
| 162 | | - }
|
| | 162 | + else return current_prog;
|
| 163 | 163 | }
|
| 164 | 164 |
|
| 165 | 165 |
|
| — | — | @@ -196,13 +196,13 @@ |
| 197 | 197 | vec4 ambient;\n\
|
| 198 | 198 | vec4 specular;\n\
|
| 199 | 199 | vec4 emissive;\n\
|
| 200 | | -int power;\n\
|
| | 200 | +float power;\n\
|
| 201 | 201 | };\n\
|
| 202 | 202 | uniform Material material;\n";
|
| 203 | 203 | static const char lightstruct[] = "struct Light\n\
|
| 204 | 204 | {\n\
|
| 205 | 205 | vec4 diffuse;\n\
|
| 206 | | -vec4 specilar;\n\
|
| | 206 | +vec4 specular;\n\
|
| 207 | 207 | vec4 ambient;\n\
|
| 208 | 208 | vec3 position;\n\
|
| 209 | 209 | vec3 direction;\n\
|
| — | — | @@ -219,6 +219,7 @@ |
| 220 | 220 | static const char var_colors[] = "vec4 diffuse;\n\
|
| 221 | 221 | vec4 specular;\n\
|
| 222 | 222 | vec4 ambient;\n";
|
| | 223 | +static const char var_color[] = "vec4 color;\n";
|
| 223 | 224 | static const char var_xyzw[] = "vec4 xyzw;\n";
|
| 224 | 225 | // Operations
|
| 225 | 226 | static const char op_transform[] = "xyzw = vec4(xyz[0],xyz[1],xyz[2],1);\n\
|
| — | — | @@ -228,7 +229,10 @@ |
| 229 | 230 | static const char op_dirlight[] = "DirLight(lightX);\n";
|
| 230 | 231 | static const char op_spotlight[] = "SpotLight(lightX);\n";
|
| 231 | 232 | static const char op_colorout[] = "vec4 color = (material.diffuse * diffuse) + (material.ambient * ambient) + \n\
|
| 232 | | -(material.specular * specular) + material.emissive;\n";
|
| | 233 | +(material.specular * specular) + material.emissive;\n\
|
| | 234 | +gl_FrontColor = color;\n";
|
| | 235 | +static const char op_colorfragout[] = "gl_FragColor = color;";
|
| | 236 | +static const char op_fragpassthru[] = "color = gl_Color;";
|
| 233 | 237 |
|
| 234 | 238 | // Functions
|
| 235 | 239 | static const char func_dirlight[] = "void DirLight(in Light light)\n\
|
| — | — | @@ -243,7 +247,7 @@ |
| 244 | 248 | {\n\
|
| 245 | 249 | vec3 eye = (-view[3].xyz / view[3].w);\n\
|
| 246 | 250 | vec3 P = vec3((world*view)*xyzw);\n\
|
| 247 | | -vec3 L = normalize(light.position.xyz - P);\n\
|
| | 251 | +vec3 L = normalize(light.direction.xyz - P);\n\
|
| 248 | 252 | vec3 V = normalize(eye - P);\n\
|
| 249 | 253 | NdotHV = max(dot(N,L+V),0.0);\n\
|
| 250 | 254 | specular += pow(NdotHV,float(material.power));\n\
|
| — | — | @@ -270,7 +274,6 @@ |
| 271 | 275 | vsrc->append(vertexshader);
|
| 272 | 276 | vsrc->append(idheader);
|
| 273 | 277 | vsrc->append(idstring);
|
| 274 | | - //Variables
|
| 275 | 278 | // Attributes
|
| 276 | 279 | if((id>>34)&1) vsrc->append(attr_xyzw);
|
| 277 | 280 | else vsrc->append(attr_xyz);
|
| — | — | @@ -355,5 +358,82 @@ |
| 356 | 359 | #ifdef _DEBUG
|
| 357 | 360 | OutputDebugStringA("Vertex shader:\n");
|
| 358 | 361 | OutputDebugStringA(vsrc->c_str());
|
| | 362 | + OutputDebugStringA("\nCompiling vertex shader:\n");
|
| 359 | 363 | #endif
|
| | 364 | + genshaders[index].shader.vs = glCreateShader(GL_VERTEX_SHADER);
|
| | 365 | + const char *src = vsrc->c_str();
|
| | 366 | + GLint srclen = strlen(src);
|
| | 367 | + glShaderSource(genshaders[index].shader.vs,1,&src,&srclen);
|
| | 368 | + glCompileShader(genshaders[index].shader.vs);
|
| | 369 | + GLint loglen,result;
|
| | 370 | + char *infolog = NULL;
|
| | 371 | + glGetShaderiv(genshaders[index].shader.vs,GL_COMPILE_STATUS,&result);
|
| | 372 | +#ifdef _DEBUG
|
| | 373 | + if(!result)
|
| | 374 | + {
|
| | 375 | + glGetShaderiv(genshaders[index].shader.vs,GL_INFO_LOG_LENGTH,&loglen);
|
| | 376 | + infolog = (char*)malloc(loglen);
|
| | 377 | + glGetShaderInfoLog(genshaders[index].shader.vs,loglen,&result,infolog);
|
| | 378 | + OutputDebugStringA("Compilation failed. Error messages:\n");
|
| | 379 | + OutputDebugStringA(infolog);
|
| | 380 | + free(infolog);
|
| | 381 | + }
|
| | 382 | +#endif
|
| | 383 | + // Create fragment shader
|
| | 384 | + string *fsrc = genshaders[index].shader.fsrc;
|
| | 385 | + fsrc->append(header);
|
| | 386 | + fsrc->append(fragshader);
|
| | 387 | + _snprintf(idstring,21,"%0.16I64X\n",id);
|
| | 388 | + idstring[21] = 0;
|
| | 389 | + fsrc->append(idheader);
|
| | 390 | + fsrc->append(idstring);
|
| | 391 | + // Attributs
|
| | 392 | + // Uniforms
|
| | 393 | + // Variables
|
| | 394 | + fsrc->append(var_color);
|
| | 395 | + // Functions
|
| | 396 | + // Main
|
| | 397 | + fsrc->append(mainstart);
|
| | 398 | + fsrc->append(op_fragpassthru);
|
| | 399 | + fsrc->append(op_colorfragout);
|
| | 400 | + fsrc->append(mainend);
|
| | 401 | +#ifdef _DEBUG
|
| | 402 | + OutputDebugStringA("Fragment shader:\n");
|
| | 403 | + OutputDebugStringA(fsrc->c_str());
|
| | 404 | + OutputDebugStringA("\nCompiling fragment shader:\n");
|
| | 405 | +#endif
|
| | 406 | + genshaders[index].shader.fs = glCreateShader(GL_FRAGMENT_SHADER);
|
| | 407 | + src = fsrc->c_str();
|
| | 408 | + srclen = strlen(src);
|
| | 409 | + glShaderSource(genshaders[index].shader.fs,1,&src,&srclen);
|
| | 410 | + glCompileShader(genshaders[index].shader.fs);
|
| | 411 | + glGetShaderiv(genshaders[index].shader.fs,GL_COMPILE_STATUS,&result);
|
| | 412 | +#ifdef _DEBUG
|
| | 413 | + if(!result)
|
| | 414 | + {
|
| | 415 | + glGetShaderiv(genshaders[index].shader.fs,GL_INFO_LOG_LENGTH,&loglen);
|
| | 416 | + infolog = (char*)malloc(loglen);
|
| | 417 | + glGetShaderInfoLog(genshaders[index].shader.fs,loglen,&result,infolog);
|
| | 418 | + OutputDebugStringA("Compilation failed. Error messages:\n");
|
| | 419 | + OutputDebugStringA(infolog);
|
| | 420 | + free(infolog);
|
| | 421 | + }
|
| | 422 | + OutputDebugStringA("\nLinking program:\n");
|
| | 423 | +#endif
|
| | 424 | + genshaders[index].shader.prog = glCreateProgram();
|
| | 425 | + glAttachShader(genshaders[index].shader.prog,genshaders[index].shader.vs);
|
| | 426 | + glAttachShader(genshaders[index].shader.prog,genshaders[index].shader.fs);
|
| | 427 | + glLinkProgram(genshaders[index].shader.prog);
|
| | 428 | + glGetProgramiv(genshaders[index].shader.prog,GL_LINK_STATUS,&result);
|
| | 429 | +#ifdef _DEBUG
|
| | 430 | + if(!result)
|
| | 431 | + {
|
| | 432 | + glGetProgramiv(genshaders[index].shader.prog,GL_INFO_LOG_LENGTH,&loglen);
|
| | 433 | + infolog = (char*)malloc(loglen);
|
| | 434 | + glGetProgramInfoLog(genshaders[index].shader.prog,loglen,&result,infolog);
|
| | 435 | + OutputDebugStringA("Program link failed. Error messages:\n");
|
| | 436 | + OutputDebugStringA(infolog);
|
| | 437 | + free(infolog);
|
| | 438 | + }
|
| | 439 | +#endif
|
| 360 | 440 | }
|