Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -520,11 +520,6 @@ |
521 | 521 | {
|
522 | 522 | if(!lpMaterial) return DDERR_INVALIDPARAMS;
|
523 | 523 | memcpy(&material,lpMaterial,sizeof(D3DMATERIAL7));
|
524 | | - glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,(GLfloat*)&material.ambient);
|
525 | | - glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,(GLfloat*)&material.diffuse);
|
526 | | - glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,(GLfloat*)&material.specular);
|
527 | | - glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,(GLfloat*)&material.emissive);
|
528 | | - glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,material.power);
|
529 | 524 | return D3D_OK;
|
530 | 525 | }
|
531 | 526 |
|
Index: ddraw/glDirect3DDevice.h |
— | — | @@ -106,6 +106,7 @@ |
107 | 107 | GLfloat *normals;
|
108 | 108 | GLubyte *diffuse;
|
109 | 109 | GLubyte *specular;
|
| 110 | + GLubyte *ambient;
|
110 | 111 | GLfloat *texcoords[8];
|
111 | 112 | };
|
112 | 113 |
|
Index: ddraw/glDirectDraw.cpp |
— | — | @@ -851,6 +851,9 @@ |
852 | 852 | if(initialized) return DDERR_ALREADYINITIALIZED;
|
853 | 853 | hDC = NULL;
|
854 | 854 | hRC = NULL;
|
| 855 | + PBO = 0;
|
| 856 | + hasHWnd = false;
|
| 857 | + dib.enabled = false;
|
855 | 858 | glD3D7 = NULL;
|
856 | 859 | hRenderWnd = NULL;
|
857 | 860 | primary = NULL;
|
— | — | @@ -1266,6 +1269,11 @@ |
1267 | 1270 | {
|
1268 | 1271 | DeleteShaders();
|
1269 | 1272 | DeleteFBO();
|
| 1273 | + if(PBO)
|
| 1274 | + {
|
| 1275 | + glDeleteBuffers(1,&PBO);
|
| 1276 | + PBO = 0;
|
| 1277 | + }
|
1270 | 1278 | wglMakeCurrent(NULL,NULL);
|
1271 | 1279 | wglDeleteContext(hRC);
|
1272 | 1280 | };
|
— | — | @@ -1322,16 +1330,34 @@ |
1323 | 1331 | SetWindowPos(hWnd,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
|
1324 | 1332 | RECT rectRender;
|
1325 | 1333 | GetClientRect(hWnd,&rectRender);
|
1326 | | - hRenderWnd = CreateWindowA("DXGLRenderWindow","Renderer",WS_CHILD|WS_VISIBLE,0,0,rectRender.right - rectRender.left,
|
1327 | | - rectRender.bottom - rectRender.top,hWnd,NULL,NULL,this);
|
| 1334 | + if(hWnd)
|
| 1335 | + {
|
| 1336 | + hRenderWnd = CreateWindowA("DXGLRenderWindow","Renderer",WS_CHILD|WS_VISIBLE,0,0,rectRender.right - rectRender.left,
|
| 1337 | + rectRender.bottom - rectRender.top,hWnd,NULL,NULL,this);
|
| 1338 | + hasHWnd = true;
|
| 1339 | + }
|
| 1340 | + else
|
| 1341 | + {
|
| 1342 | + width = GetSystemMetrics(SM_CXSCREEN);
|
| 1343 | + height = GetSystemMetrics(SM_CYSCREEN);
|
| 1344 | + hRenderWnd = CreateWindowExA(WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOPMOST,"DXGLRenderWindow","Renderer",
|
| 1345 | + WS_POPUP,0,0,width,height,0,0,NULL,this);
|
| 1346 | + hasHWnd = false;
|
| 1347 | + }
|
1328 | 1348 | SetWindowPos(hRenderWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW);
|
1329 | 1349 | PIXELFORMATDESCRIPTOR pfd;
|
1330 | 1350 | ZeroMemory(&pfd,sizeof(PIXELFORMATDESCRIPTOR));
|
1331 | 1351 | pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
1332 | 1352 | pfd.nVersion = 1;
|
1333 | | - pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
| 1353 | + if(hasHWnd) pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
| 1354 | + else pfd.dwFlags = pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
|
1334 | 1355 | pfd.iPixelType = PFD_TYPE_RGBA;
|
1335 | | - pfd.cColorBits = bpp;
|
| 1356 | + if(hasHWnd) pfd.cColorBits = bpp;
|
| 1357 | + else
|
| 1358 | + {
|
| 1359 | + pfd.cColorBits = 24;
|
| 1360 | + pfd.cAlphaBits = 8;
|
| 1361 | + }
|
1336 | 1362 | pfd.iLayerType = PFD_MAIN_PLANE;
|
1337 | 1363 | hDC = GetDC(hRenderWnd);
|
1338 | 1364 | if(!hDC)
|
— | — | @@ -1385,6 +1411,27 @@ |
1386 | 1412 | glClear(GL_COLOR_BUFFER_BIT);
|
1387 | 1413 | glFlush();
|
1388 | 1414 | SwapBuffers(hDC);
|
| 1415 | + if(!hasHWnd)
|
| 1416 | + {
|
| 1417 | + dib.enabled = true;
|
| 1418 | + dib.width = width;
|
| 1419 | + dib.height = height;
|
| 1420 | + dib.pitch = (((width<<3)+31)&~31) >>3;
|
| 1421 | + dib.pixels = NULL;
|
| 1422 | + dib.hdc = CreateCompatibleDC(NULL);
|
| 1423 | + ZeroMemory(&dib.info,sizeof(BITMAPINFO));
|
| 1424 | + dib.info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
| 1425 | + dib.info.bmiHeader.biBitCount = 32;
|
| 1426 | + dib.info.bmiHeader.biWidth = width;
|
| 1427 | + dib.info.bmiHeader.biHeight = height;
|
| 1428 | + dib.info.bmiHeader.biCompression = BI_RGB;
|
| 1429 | + dib.info.bmiHeader.biPlanes = 1;
|
| 1430 | + dib.hbitmap = CreateDIBSection(dib.hdc,&dib.info,DIB_RGB_COLORS,(void**)&dib.pixels,NULL,0);
|
| 1431 | + glGenBuffers(1,&PBO);
|
| 1432 | + glBindBuffer(GL_PIXEL_PACK_BUFFER,PBO);
|
| 1433 | + glBufferData(GL_PIXEL_PACK_BUFFER,width*height*4,NULL,GL_STREAM_READ);
|
| 1434 | + glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
|
| 1435 | + }
|
1389 | 1436 | return TRUE;
|
1390 | 1437 | }
|
1391 | 1438 | void glDirectDraw7::GetSizes(LONG *sizes) // allocate 6 dwords
|
Index: ddraw/glDirectDraw.h |
— | — | @@ -36,6 +36,17 @@ |
37 | 37 | int MultiTextureExt;
|
38 | 38 | int PalettedTextures;
|
39 | 39 | } GLCAPS;
|
| 40 | +typedef struct
|
| 41 | +{
|
| 42 | + bool enabled;
|
| 43 | + int width;
|
| 44 | + int height;
|
| 45 | + int pitch;
|
| 46 | + HDC hdc;
|
| 47 | + HBITMAP hbitmap;
|
| 48 | + BITMAPINFO info;
|
| 49 | + BYTE *pixels;
|
| 50 | +} DIB;
|
40 | 51 |
|
41 | 52 | class glDirectDraw7 : public IDirectDraw7
|
42 | 53 | {
|
— | — | @@ -95,6 +106,10 @@ |
96 | 107 | bool GetFullscreen(){return fullscreen;};
|
97 | 108 | void GetHandles(HWND *hwnd, HWND *hrender);
|
98 | 109 | glDirectDrawSurface7 *primary;
|
| 110 | + bool hasHWnd;
|
| 111 | + DIB dib;
|
| 112 | + GLuint PBO;
|
| 113 | + HWND hRenderWnd;
|
99 | 114 | private:
|
100 | 115 | void DeleteGL();
|
101 | 116 | BOOL InitGL(int width, int height, int bpp, bool fullscreen, HWND hWnd);
|
— | — | @@ -101,7 +116,6 @@ |
102 | 117 | HRESULT error;
|
103 | 118 | ULONG refcount;
|
104 | 119 | HWND hWnd;
|
105 | | - HWND hRenderWnd;
|
106 | 120 | bool fullscreen;
|
107 | 121 | bool fpupreserve;
|
108 | 122 | bool fpusetup;
|
Index: ddraw/glDirectDrawSurface.cpp |
— | — | @@ -993,8 +993,8 @@ |
994 | 994 | }
|
995 | 995 | HRESULT WINAPI glDirectDrawSurface7::IsLost()
|
996 | 996 | {
|
997 | | - FIXME("glDirectDrawSurface7::IsLost: stub\n");
|
998 | | - ERR(DDERR_GENERIC);
|
| 997 | + if(hrc == ddInterface->hRC) return DD_OK;
|
| 998 | + else return DDERR_SURFACELOST;
|
999 | 999 | }
|
1000 | 1000 |
|
1001 | 1001 | HRESULT WINAPI glDirectDrawSurface7::Lock(LPRECT lpDestRect, LPDDSURFACEDESC2 lpDDSurfaceDesc, DWORD dwFlags, HANDLE hEvent)
|
— | — | @@ -1219,7 +1219,37 @@ |
1220 | 1220 | glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
|
1221 | 1221 | glDisable(GL_TEXTURE_2D);
|
1222 | 1222 | glFlush();
|
1223 | | - SwapBuffers(ddInterface->hDC);
|
| 1223 | + if(ddInterface->hasHWnd) SwapBuffers(ddInterface->hDC);
|
| 1224 | + else
|
| 1225 | + {
|
| 1226 | + glReadBuffer(GL_FRONT);
|
| 1227 | + glBindBuffer(GL_PIXEL_PACK_BUFFER,ddInterface->PBO);
|
| 1228 | + GLint packalign;
|
| 1229 | + glGetIntegerv(GL_PACK_ALIGNMENT,&packalign);
|
| 1230 | + glPixelStorei(GL_PACK_ALIGNMENT,1);
|
| 1231 | + glReadPixels(0,0,sizes[4],sizes[5],GL_BGRA,GL_UNSIGNED_BYTE,0);
|
| 1232 | + GLubyte *pixels = (GLubyte*)glMapBuffer(GL_PIXEL_PACK_BUFFER,GL_READ_ONLY);
|
| 1233 | + for(int i = 0; i < sizes[5];i++)
|
| 1234 | + {
|
| 1235 | + memcpy(&ddInterface->dib.pixels[ddInterface->dib.pitch*i],
|
| 1236 | + &pixels[((sizes[5]-1)-i)*(sizes[4]*4)],sizes[4]*4);
|
| 1237 | + }
|
| 1238 | + glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
| 1239 | + glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
|
| 1240 | + glPixelStorei(GL_PACK_ALIGNMENT,packalign);
|
| 1241 | + HDC hRenderDC = (HDC)::GetDC(ddInterface->hRenderWnd);
|
| 1242 | + HGDIOBJ hPrevObj = 0;
|
| 1243 | + POINT dest = {0,0};
|
| 1244 | + POINT src = {0,0};
|
| 1245 | + SIZE wnd = {ddInterface->dib.width,ddInterface->dib.height};
|
| 1246 | + BLENDFUNCTION func = {AC_SRC_OVER,0,255,AC_SRC_ALPHA};
|
| 1247 | + hPrevObj = SelectObject(ddInterface->dib.hdc,ddInterface->dib.hbitmap);
|
| 1248 | + ClientToScreen(ddInterface->hRenderWnd,&dest);
|
| 1249 | + UpdateLayeredWindow(ddInterface->hRenderWnd,hRenderDC,&dest,&wnd,
|
| 1250 | + ddInterface->dib.hdc,&src,0,&func,ULW_ALPHA);
|
| 1251 | + SelectObject(ddInterface->dib.hdc,hPrevObj);
|
| 1252 | + ::ReleaseDC(ddInterface->hRenderWnd,hRenderDC);
|
| 1253 | + }
|
1224 | 1254 | }
|
1225 | 1255 | // ddraw 2+ api
|
1226 | 1256 | HRESULT WINAPI glDirectDrawSurface7::GetDDInterface(LPVOID FAR *lplpDD)
|
Index: ddraw/glExtensions.cpp |
— | — | @@ -66,6 +66,13 @@ |
67 | 67 | void (APIENTRY *glActiveTexture)(GLenum texture) = NULL;
|
68 | 68 | void (APIENTRY *glClientActiveTexture) (GLenum texture) = NULL;
|
69 | 69 |
|
| 70 | +void (APIENTRY *glGenBuffers)(GLsizei n, GLuint* buffers) = NULL;
|
| 71 | +void (APIENTRY *glDeleteBuffers)(GLsizei n, const GLuint* buffers) = NULL;
|
| 72 | +void (APIENTRY *glBindBuffer)(GLenum target, GLuint buffer) = NULL;
|
| 73 | +void (APIENTRY *glBufferData)(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage) = NULL;
|
| 74 | +void* (APIENTRY *glMapBuffer)(GLenum target, GLenum access) = NULL;
|
| 75 | +GLboolean (APIENTRY *glUnmapBuffer)(GLenum target) = NULL;
|
| 76 | +
|
70 | 77 | BOOL (APIENTRY *wglSwapIntervalEXT)(int interval) = NULL;
|
71 | 78 | int (APIENTRY *wglGetSwapIntervalEXT)() = NULL;
|
72 | 79 |
|
— | — | @@ -88,6 +95,15 @@ |
89 | 96 | glActiveTexture = (PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture");
|
90 | 97 | glClientActiveTexture = (PFNGLCLIENTACTIVETEXTUREPROC)wglGetProcAddress("glClientActiveTexture");
|
91 | 98 | }
|
| 99 | + if((glver_major >= 2) || ((glver_major >= 1) && (glver_minor >= 5)))
|
| 100 | + {
|
| 101 | + glGenBuffers = (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffers");
|
| 102 | + glDeleteBuffers = (PFNGLDELETEBUFFERSPROC)wglGetProcAddress("glDeleteBuffers");
|
| 103 | + glBindBuffer = (PFNGLBINDBUFFERPROC)wglGetProcAddress("glBindBuffer");
|
| 104 | + glBufferData = (PFNGLBUFFERDATAPROC)wglGetProcAddress("glBufferData");
|
| 105 | + glMapBuffer = (PFNGLMAPBUFFERPROC)wglGetProcAddress("glMapBuffer");
|
| 106 | + glUnmapBuffer = (PFNGLUNMAPBUFFERPROC)wglGetProcAddress("glUnmapBuffer");
|
| 107 | + }
|
92 | 108 | if(glver_major >= 2)
|
93 | 109 | {
|
94 | 110 | glCreateShader = (PFNGLCREATESHADERPROC)wglGetProcAddress("glCreateShader");
|
Index: ddraw/glExtensions.h |
— | — | @@ -86,6 +86,13 @@ |
87 | 87 | GLAPI void (APIENTRY *glActiveTexture)(GLenum texture);
|
88 | 88 | GLAPI void (APIENTRY *glClientActiveTexture) (GLenum texture);
|
89 | 89 |
|
| 90 | +GLAPI void (APIENTRY *glGenBuffers)(GLsizei n, GLuint* buffers);
|
| 91 | +GLAPI void (APIENTRY *glDeleteBuffers)(GLsizei n, const GLuint* buffers);
|
| 92 | +GLAPI void (APIENTRY *glBindBuffer)(GLenum target, GLuint buffer);
|
| 93 | +GLAPI void (APIENTRY *glBufferData)(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
|
| 94 | +GLAPI void* (APIENTRY *glMapBuffer)(GLenum target, GLenum access);
|
| 95 | +GLAPI GLboolean (APIENTRY *glUnmapBuffer)(GLenum target);
|
| 96 | +
|
90 | 97 | GLAPI BOOL (APIENTRY *wglSwapIntervalEXT)(int interval);
|
91 | 98 | GLAPI int (APIENTRY *wglGetSwapIntervalEXT)();
|
92 | 99 |
|
Index: ddraw/shadergen.cpp |
— | — | @@ -18,27 +18,108 @@ |
19 | 19 | #include "common.h"
|
20 | 20 | #include "shadergen.h"
|
21 | 21 | #include "shaders.h"
|
| 22 | +#include <string>
|
| 23 | +using namespace std;
|
22 | 24 |
|
| 25 | +typedef struct
|
| 26 | +{
|
| 27 | + GLint vs;
|
| 28 | + GLint fs;
|
| 29 | + string *vsrc;
|
| 30 | + string *fsrc;
|
| 31 | + GLint prog;
|
| 32 | +} _GENSHADER;
|
| 33 | +
|
23 | 34 | struct GenShader
|
24 | 35 | {
|
25 | | - SHADER shader;
|
| 36 | + _GENSHADER shader;
|
26 | 37 | __int64 id;
|
27 | 38 | };
|
28 | 39 | GenShader genshaders[256];
|
29 | 40 | static __int64 current_shader = 0;
|
30 | 41 | static int shadercount = 0;
|
| 42 | +static int genindex = 0;
|
31 | 43 | static bool initialized = false;
|
32 | 44 | static bool isbuiltin = true;
|
33 | 45 |
|
| 46 | +/* Bits in Shader ID:
|
| 47 | +Bits 0-1 - Shading mode: 00=flat 01=gouraud 11=phong 10=flat per-pixel
|
| 48 | +Bit 2 - Alpha test enable
|
| 49 | +Bits 3-5 - Alpha test function:
|
| 50 | +000=never 001=less 010=equal 011=lessequal
|
| 51 | +100=greater 101=notequal 110=lessequal 111=always
|
| 52 | +Bits 6-7 - Table fog:
|
| 53 | +00 = none 01=exp 10=exp2 11=linear
|
| 54 | +Bits 8-9 - Vertex fog: same as table
|
| 55 | +Bit 10 - Range based fog
|
| 56 | +Bit 11 - Specular highlights
|
| 57 | +Bit 12 - Stippled alpha
|
| 58 | +Bit 13 - Color key transparency
|
| 59 | +Bit 14 - Enable Z bias
|
| 60 | +Bits 15-17 - Number of lights
|
| 61 | +Bit 18 - Camera relative specular highlights
|
| 62 | +Bit 19 - Alpha blended color key
|
| 63 | +Bits 20-21 - Diffuse material source
|
| 64 | +Bits 22-23 - Specular material source
|
| 65 | +Bits 24-25 - Ambient material source
|
| 66 | +Bits 26-27 - Emissive material source
|
| 67 | +Bits 28-30 - Number of textures
|
| 68 | +Bit 31 - RGB or RGBA color
|
| 69 | +Bits 32-33 - Vertex format
|
| 70 | +Bits 34-49 - Texture coordinate format
|
| 71 | +Bit 50 - Enable normals
|
| 72 | +Bits 51-58 - Light types
|
| 73 | +*/
|
| 74 | +void ZeroShaderArray()
|
| 75 | +{
|
| 76 | + ZeroMemory(genshaders,256*sizeof(GenShader));
|
| 77 | + current_shader = 0;
|
| 78 | + isbuiltin = true;
|
| 79 | +}
|
| 80 | +
|
34 | 81 | void SetShader(__int64 id, bool builtin)
|
35 | 82 | {
|
| 83 | + int shaderindex = -1;
|
36 | 84 | if(builtin)
|
37 | 85 | {
|
| 86 | + if(isbuiltin && (shaders[id].prog == current_shader)) return;
|
38 | 87 | glUseProgram(shaders[id].prog);
|
39 | 88 | current_shader = shaders[id].prog;
|
| 89 | + isbuiltin=true;
|
40 | 90 | }
|
41 | 91 | else
|
42 | 92 | {
|
| 93 | + if(!isbuiltin && (id == current_shader)) return;
|
| 94 | + current_shader = id;
|
| 95 | + isbuiltin=false;
|
| 96 | + for(int i = 0; i < shadercount; i++)
|
| 97 | + {
|
| 98 | + if(genshaders[i].id == id)
|
| 99 | + {
|
| 100 | + shaderindex = i;
|
| 101 | + break;
|
| 102 | + }
|
| 103 | + }
|
| 104 | + if(shaderindex == -1)
|
| 105 | + {
|
| 106 | + shadercount++;
|
| 107 | + if(shadercount > 256) shadercount = 256;
|
| 108 | + if(genshaders[genindex].shader.prog)
|
| 109 | + {
|
| 110 | + glUseProgram(0);
|
| 111 | + glDeleteProgram(genshaders[shaderindex].shader.prog);
|
| 112 | + glDeleteShader(genshaders[shaderindex].shader.vs);
|
| 113 | + glDeleteShader(genshaders[shaderindex].shader.fs);
|
| 114 | + delete genshaders[shaderindex].shader.vsrc;
|
| 115 | + delete genshaders[shaderindex].shader.fsrc;
|
| 116 | + ZeroMemory(&genshaders[shaderindex],sizeof(GenShader));
|
| 117 | + }
|
| 118 | + CreateShader(genindex,id);
|
| 119 | + shaderindex = genindex;
|
| 120 | + genindex++;
|
| 121 | + if(genindex == 256) genindex = 0;
|
| 122 | + }
|
| 123 | + glUseProgram(shaderindex);
|
43 | 124 | }
|
44 | 125 | }
|
45 | 126 |
|
— | — | @@ -51,6 +132,7 @@ |
52 | 133 | }
|
53 | 134 | }
|
54 | 135 |
|
| 136 | +
|
55 | 137 | #define REVISION 1
|
56 | 138 | static const char header[] =
|
57 | 139 | "//REV" STR(REVISION) "\n\
|
— | — | @@ -61,18 +143,89 @@ |
62 | 144 | static const char linefeed[] = "\n";
|
63 | 145 | static const char mainstart[] = "void main()\n{\n";
|
64 | 146 | 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";
|
| 147 | +// Attributes
|
67 | 148 | static const char attr_xyz[] = "attribute vec3 xyz;\n";
|
68 | 149 | static const char conv_xyz[] = "vec4 xyzw = vec4(xyz[0],xyz[1],xyz[2],1);\n";
|
69 | 150 | 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";
|
| 151 | +static const char attr_nxyz[] = "attribute vec3 nxyz;\n";
|
| 152 | +static const char attr_blend[] = "attribute float blendX;\n";
|
| 153 | +static const char attr_rgb[] = "attribute vec3 rgbX;\n";
|
| 154 | +static const char conv_rgb[] = "vec4 rgbaX = vec4(rgbX[0],rgbX[1],rgbX[2],1);\n";
|
| 155 | +static const char attr_rgba[] = "attribute vec4 rgbaX;\n";
|
| 156 | +static const char attr_s[] = "attribute float sX;\n";
|
74 | 157 | static const char conv_s[] = "vec4 strqX = vec4(sX,0,0,1);\n";
|
75 | | -static const char attr_st[] = "attrib vec2 stX;\n";
|
| 158 | +static const char attr_st[] = "attribute vec2 stX;\n";
|
76 | 159 | 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";
|
| 160 | +static const char attr_str[] = "attribute vec3 strX;\n";
|
78 | 161 | 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 |
| 162 | +static const char attr_strq[] = "attribute vec4 strqX;\n";
|
| 163 | +// Uniforms
|
| 164 | +static const char unif_mats[] = "uniform mat4 world;\n\
|
| 165 | +uniform mat4 view;\n\
|
| 166 | +uniform mat4 projection;\n";
|
| 167 | +static const char modelview[] = "mat4 modelview = world * view;\n";
|
| 168 | +static const char unif_material[] = "struct Material\n\
|
| 169 | +{\n\
|
| 170 | +vec4 diffuse;\n\
|
| 171 | +vec4 ambient;\n\
|
| 172 | +vec4 specular;\n\
|
| 173 | +vec4 emussive;\n\
|
| 174 | +int power;\n\
|
| 175 | +};\n\
|
| 176 | +uniform Material material;\n";
|
| 177 | +static const char lightstruct[] = "struct Light\n\
|
| 178 | +{\n\
|
| 179 | +vec4 diffuse;\n\
|
| 180 | +vec4 specilar;\n\
|
| 181 | +vec4 ambient;\n\
|
| 182 | +vec3 position;\n\
|
| 183 | +vec3 direction;\n\
|
| 184 | +float range;\n\
|
| 185 | +float falloff;\n\
|
| 186 | +float constant;\n\
|
| 187 | +float linear;\n\
|
| 188 | +float quad;\n\
|
| 189 | +float theta;\n\
|
| 190 | +float phi;\n\
|
| 191 | +};\n";
|
| 192 | +static const char unif_light[] = "uniform Light lightX;\n";
|
| 193 | +// Operations
|
| 194 | +static const char normalize[] = "vec3 N = normalize(vec3(modelview*vec4(nxyz,0.0)));\n";
|
| 195 | +
|
| 196 | +void CreateShader(int index, __int64 id)
|
| 197 | +{
|
| 198 | + string tmp;
|
| 199 | + int i;
|
| 200 | + char idstring[22];
|
| 201 | + _snprintf(idstring,21,"%0.16I64X\n",id);
|
| 202 | + idstring[21] = 0;
|
| 203 | + genshaders[index].shader.vsrc = new string;
|
| 204 | + genshaders[index].shader.fsrc = new string;
|
| 205 | + // Create vertex shader
|
| 206 | + //Header
|
| 207 | + string *vsrc = genshaders[index].shader.vsrc;
|
| 208 | + vsrc->append(header);
|
| 209 | + vsrc->append(vertexshader);
|
| 210 | + vsrc->append(idheader);
|
| 211 | + vsrc->append(idstring);
|
| 212 | + //Variables
|
| 213 | + vsrc->append(unif_mats);
|
| 214 | + vsrc->append(unif_material);
|
| 215 | + if((id>>15)&8) // Lighting
|
| 216 | + {
|
| 217 | + vsrc->append(lightstruct);
|
| 218 | + for(i = 0; i < ((id>>15)&8); i++)
|
| 219 | + {
|
| 220 | + tmp = unif_light;
|
| 221 | + tmp.replace(19,1,_itoa(i,idstring,10));
|
| 222 | + vsrc->append(tmp);
|
| 223 | + }
|
| 224 | + }
|
| 225 | +
|
| 226 | + //Main
|
| 227 | + vsrc->append(mainstart);
|
| 228 | +
|
| 229 | +
|
| 230 | + vsrc->append(mainend);
|
| 231 | +
|
| 232 | +}
|
Index: ddraw/shadergen.h |
— | — | @@ -21,6 +21,7 @@ |
22 | 22 |
|
23 | 23 | void SetShader(__int64 id, bool builtin);
|
24 | 24 | GLuint GetProgram();
|
| 25 | +void ZeroShaderArray();
|
| 26 | +void CreateShader(int index, __int64 id);
|
25 | 27 |
|
26 | | -
|
27 | 28 | #endif |
\ No newline at end of file |
Index: ddraw/shaders.cpp |
— | — | @@ -17,6 +17,7 @@ |
18 | 18 |
|
19 | 19 | #include "common.h"
|
20 | 20 | #include "shaders.h"
|
| 21 | +#include "shadergen.h"
|
21 | 22 |
|
22 | 23 | const char frag_Color[] = "\
|
23 | 24 | #version 110\n\
|
— | — | @@ -127,6 +128,7 @@ |
128 | 129 |
|
129 | 130 | void CompileShaders()
|
130 | 131 | {
|
| 132 | + ZeroShaderArray();
|
131 | 133 | const GLchar *src;
|
132 | 134 | GLint srclen;
|
133 | 135 | for(int i = 0; i < NumberOfShaders; i++)
|