Index: ddraw/glDirectDrawSurface.cpp |
— | — | @@ -26,6 +26,9 @@ |
27 | 27 | #include "glDirectDrawClipper.h"
|
28 | 28 | #include "glutil.h"
|
29 | 29 |
|
| 30 | +BltVertex bltvertices[4];
|
| 31 | +const GLushort bltindices[4] = {0,1,2,3};
|
| 32 | +
|
30 | 33 | int swapinterval = 0;
|
31 | 34 | inline void SetSwap(int swap)
|
32 | 35 | {
|
— | — | @@ -128,6 +131,8 @@ |
129 | 132 | ZeroMemory(colorkey,4*sizeof(CKEY));
|
130 | 133 | bitmapinfo = (BITMAPINFO *)malloc(sizeof(BITMAPINFO)+(255*sizeof(RGBQUAD)));
|
131 | 134 | palette = NULL;
|
| 135 | + paltex = NULL;
|
| 136 | + texture = NULL;
|
132 | 137 | clipper = NULL;
|
133 | 138 | hdc = NULL;
|
134 | 139 | dds1 = NULL;
|
— | — | @@ -451,6 +456,7 @@ |
452 | 457 | if(dds3) dds3->Release();
|
453 | 458 | if(dds4) dds4->Release();
|
454 | 459 | if(paltex)glDeleteTextures(1,&paltex);
|
| 460 | + if(texture)glDeleteTextures(1,&texture);
|
455 | 461 | if(bitmapinfo) free(bitmapinfo);
|
456 | 462 | if(palette) palette->Release();
|
457 | 463 | if(backbuffer) backbuffer->Release();
|
— | — | @@ -611,15 +617,14 @@ |
612 | 618 | srcrect.bottom = ddsdSrc.dwHeight;
|
613 | 619 | }
|
614 | 620 | else srcrect = *lpSrcRect;
|
615 | | - GLfloat coords[8];
|
616 | | - coords[0] = (GLfloat)destrect.left * ((GLfloat)fakex/(GLfloat)ddsd.dwWidth);
|
617 | | - coords[1] = (GLfloat)destrect.right * ((GLfloat)fakex/(GLfloat)ddsd.dwWidth);
|
618 | | - coords[2] = (GLfloat)fakey-((GLfloat)destrect.top * ((GLfloat)fakey/(GLfloat)ddsd.dwHeight));
|
619 | | - coords[3] = (GLfloat)fakey-((GLfloat)destrect.bottom * ((GLfloat)fakey/(GLfloat)ddsd.dwHeight));
|
620 | | - coords[4] = (GLfloat)srcrect.left / (GLfloat)ddsdSrc.dwWidth;
|
621 | | - coords[5] = (GLfloat)srcrect.right / (GLfloat)ddsdSrc.dwWidth;
|
622 | | - coords[6] = (GLfloat)srcrect.top / (GLfloat)ddsdSrc.dwHeight;
|
623 | | - coords[7] = (GLfloat)srcrect.bottom / (GLfloat)ddsdSrc.dwHeight;
|
| 621 | + bltvertices[1].x = bltvertices[3].x = (GLfloat)destrect.left * ((GLfloat)fakex/(GLfloat)ddsd.dwWidth);
|
| 622 | + bltvertices[0].x = bltvertices[2].x = (GLfloat)destrect.right * ((GLfloat)fakex/(GLfloat)ddsd.dwWidth);
|
| 623 | + bltvertices[0].y = bltvertices[1].y = (GLfloat)fakey-((GLfloat)destrect.top * ((GLfloat)fakey/(GLfloat)ddsd.dwHeight));
|
| 624 | + bltvertices[2].y = bltvertices[3].y = (GLfloat)fakey-((GLfloat)destrect.bottom * ((GLfloat)fakey/(GLfloat)ddsd.dwHeight));
|
| 625 | + bltvertices[1].s = bltvertices[3].s = (GLfloat)srcrect.left / (GLfloat)ddsdSrc.dwWidth;
|
| 626 | + bltvertices[0].s = bltvertices[2].s = (GLfloat)srcrect.right / (GLfloat)ddsdSrc.dwWidth;
|
| 627 | + bltvertices[0].t = bltvertices[1].t = (GLfloat)srcrect.top / (GLfloat)ddsdSrc.dwHeight;
|
| 628 | + bltvertices[2].t = bltvertices[3].t = (GLfloat)srcrect.bottom / (GLfloat)ddsdSrc.dwHeight;
|
624 | 629 | glClear(GL_DEPTH_BUFFER_BIT);
|
625 | 630 | if(dwFlags & DDBLT_COLORFILL)
|
626 | 631 | {
|
— | — | @@ -629,23 +634,35 @@ |
630 | 635 | switch(ddInterface->GetBPP())
|
631 | 636 | {
|
632 | 637 | case 8:
|
633 | | - glColor3ub((GLubyte)lpDDBltFx->dwFillColor,(GLubyte)lpDDBltFx->dwFillColor,
|
634 | | - (GLubyte)lpDDBltFx->dwFillColor);
|
| 638 | + bltvertices[0].r = bltvertices[0].g = bltvertices[0].b =
|
| 639 | + bltvertices[1].r = bltvertices[1].g = bltvertices[1].b =
|
| 640 | + bltvertices[2].r = bltvertices[2].g = bltvertices[2].b =
|
| 641 | + bltvertices[3].r = bltvertices[3].g = bltvertices[3].b = (GLubyte)lpDDBltFx->dwFillColor;
|
635 | 642 | break;
|
636 | 643 | case 15:
|
637 | | - glColor3ub(_5to8bit((lpDDBltFx->dwFillColor>>10) & 31),
|
638 | | - _5to8bit((lpDDBltFx->dwFillColor>>5) & 31),
|
639 | | - _5to8bit(lpDDBltFx->dwFillColor & 31));
|
| 644 | + bltvertices[0].r = bltvertices[1].r = bltvertices[2].r = bltvertices[3].r =
|
| 645 | + _5to8bit((lpDDBltFx->dwFillColor>>10) & 31);
|
| 646 | + bltvertices[0].g = bltvertices[1].g = bltvertices[2].g = bltvertices[3].g =
|
| 647 | + _5to8bit((lpDDBltFx->dwFillColor>>5) & 31);
|
| 648 | + bltvertices[0].b = bltvertices[1].b = bltvertices[2].b = bltvertices[3].b =
|
| 649 | + _5to8bit(lpDDBltFx->dwFillColor & 31);
|
640 | 650 | break;
|
641 | 651 | case 16:
|
642 | | - glColor3ub(_5to8bit((lpDDBltFx->dwFillColor>>11) & 31),
|
643 | | - _6to8bit((lpDDBltFx->dwFillColor>>5) & 63),
|
644 | | - _5to8bit(lpDDBltFx->dwFillColor & 31));
|
| 652 | + bltvertices[0].r = bltvertices[1].r = bltvertices[2].r = bltvertices[3].r =
|
| 653 | + _5to8bit((lpDDBltFx->dwFillColor>>11) & 31);
|
| 654 | + bltvertices[0].g = bltvertices[1].g = bltvertices[2].g = bltvertices[3].g =
|
| 655 | + _6to8bit((lpDDBltFx->dwFillColor>>5) & 63);
|
| 656 | + bltvertices[0].b = bltvertices[1].b = bltvertices[2].b = bltvertices[3].b =
|
| 657 | + _5to8bit(lpDDBltFx->dwFillColor & 31);
|
645 | 658 | break;
|
646 | 659 | case 24:
|
647 | 660 | case 32:
|
648 | | - glColor3ub(((lpDDBltFx->dwFillColor>>16) & 255),
|
649 | | - ((lpDDBltFx->dwFillColor>>8) & 255),(lpDDBltFx->dwFillColor & 255));
|
| 661 | + bltvertices[0].r = bltvertices[1].r = bltvertices[2].r = bltvertices[3].r =
|
| 662 | + ((lpDDBltFx->dwFillColor>>16) & 255);
|
| 663 | + bltvertices[0].g = bltvertices[1].g = bltvertices[2].g = bltvertices[3].g =
|
| 664 | + ((lpDDBltFx->dwFillColor>>8) & 255);
|
| 665 | + bltvertices[0].b = bltvertices[1].b = bltvertices[2].b = bltvertices[3].b =
|
| 666 | + (lpDDBltFx->dwFillColor & 255);
|
650 | 667 | default:
|
651 | 668 | break;
|
652 | 669 | }
|
— | — | @@ -653,7 +670,6 @@ |
654 | 671 | else
|
655 | 672 | {
|
656 | 673 | glEnable(GL_TEXTURE_2D);
|
657 | | - glColor3f(1.0,1.0,1.0);
|
658 | 674 | }
|
659 | 675 | if(lpDDSrcSurface) glBindTexture(GL_TEXTURE_2D,((glDirectDrawSurface7*)lpDDSrcSurface)->GetTexture());
|
660 | 676 | if((dwFlags & DDBLT_KEYSRC) && (src && src->colorkey[0].enabled) && !(dwFlags & DDBLT_COLORFILL))
|
— | — | @@ -696,17 +712,14 @@ |
697 | 713 | GLint viewloc = glGetUniformLocation(GetProgram()&0xffffffff,"view");
|
698 | 714 | glUniform4f(viewloc,0,(GLfloat)fakex,0,(GLfloat)fakey);
|
699 | 715 | this->dirty |= 2;
|
700 | | - glBegin(GL_QUADS);
|
701 | | - glTexCoord2f(coords[4], coords[6]);
|
702 | | - glVertex2f(coords[0], coords[2]);
|
703 | | - glTexCoord2f(coords[5], coords[6]);
|
704 | | - glVertex2f( coords[1], coords[2]);
|
705 | | - glTexCoord2f(coords[5], coords[7]);
|
706 | | - glVertex2f( coords[1], coords[3]);
|
707 | | - glTexCoord2f(coords[4], coords[7]);
|
708 | | - glVertex2f(coords[0], coords[3]);
|
709 | | - glEnd();
|
710 | | - glColor3f(1.0,1.0,1.0);
|
| 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);
|
| 723 | + glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
|
711 | 724 | glDisable(GL_TEXTURE_2D);
|
712 | 725 | SetFBO(0,0,false);
|
713 | 726 | if(((ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
|
— | — | @@ -1117,10 +1130,10 @@ |
1118 | 1131 | {
|
1119 | 1132 | ddInterface->GetSizes(sizes);
|
1120 | 1133 | glViewport(0,0,sizes[4],sizes[5]);
|
1121 | | - view[0] = (signed)-(sizes[4]-sizes[0])/2;
|
1122 | | - view[1] = (signed)(sizes[4]-sizes[0])/2+sizes[0];
|
1123 | | - view[2] = (signed)(sizes[5]-sizes[1])/2+sizes[1];
|
1124 | | - view[3] = (signed)-(sizes[5]-sizes[1])/2;
|
| 1134 | + view[0] = (GLfloat)-(sizes[4]-sizes[0])/2;
|
| 1135 | + view[1] = (GLfloat)(sizes[4]-sizes[0])/2+sizes[0];
|
| 1136 | + view[2] = (GLfloat)(sizes[5]-sizes[1])/2+sizes[1];
|
| 1137 | + view[3] = (GLfloat)-(sizes[5]-sizes[1])/2;
|
1125 | 1138 | }
|
1126 | 1139 | else
|
1127 | 1140 | {
|
— | — | @@ -1134,18 +1147,18 @@ |
1135 | 1148 | ClientToScreen(hwnd,(LPPOINT)&r2.left);
|
1136 | 1149 | ClientToScreen(hwnd,(LPPOINT)&r2.right);
|
1137 | 1150 | glViewport(0,0,r.right,r.bottom);
|
1138 | | - view[0] = (signed)r2.left;
|
1139 | | - view[1] = (signed)r2.right;
|
1140 | | - view[2] = (signed)(fakey-r2.top);
|
1141 | | - view[3] = (signed)(fakey-r2.bottom);
|
| 1151 | + view[0] = (GLfloat)r2.left;
|
| 1152 | + view[1] = (GLfloat)r2.right;
|
| 1153 | + view[2] = (GLfloat)fakey-(GLfloat)r2.top;
|
| 1154 | + view[3] = (GLfloat)fakey-(GLfloat)r2.bottom;
|
1142 | 1155 | }
|
1143 | 1156 | }
|
1144 | 1157 | else
|
1145 | 1158 | {
|
1146 | 1159 | view[0] = 0;
|
1147 | | - view[1] = fakex;
|
| 1160 | + view[1] = (GLfloat)fakex;
|
1148 | 1161 | view[2] = 0;
|
1149 | | - view[3] = fakey;
|
| 1162 | + view[3] = (GLfloat)fakey;
|
1150 | 1163 | }
|
1151 | 1164 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
1152 | 1165 | if(ddInterface->GetBPP() == 8)
|
— | — | @@ -1168,38 +1181,32 @@ |
1169 | 1182 | SetShader(PROG_TEXTURE,true);
|
1170 | 1183 | glEnable(GL_TEXTURE_2D);
|
1171 | 1184 | glBindTexture(GL_TEXTURE_2D,texture);
|
1172 | | - int prog = GetProgram();
|
| 1185 | + GLuint prog = GetProgram() & 0xFFFFFFFF;
|
1173 | 1186 | GLint texloc = glGetUniformLocation(prog,"Texture");
|
1174 | 1187 | }
|
1175 | | - int prog = GetProgram();
|
| 1188 | + GLuint prog = GetProgram();
|
1176 | 1189 | GLint viewloc = glGetUniformLocation(prog,"view");
|
1177 | 1190 | glUniform4f(viewloc,view[0],view[1],view[2],view[3]);
|
1178 | 1191 | if(ddInterface->GetFullscreen())
|
1179 | 1192 | {
|
1180 | | - glBegin(GL_QUADS);
|
1181 | | - glTexCoord2f(0., 1.);
|
1182 | | - glVertex2f(0., 0.);
|
1183 | | - glTexCoord2f(1., 1.);
|
1184 | | - glVertex2f( (float)sizes[0], 0.);
|
1185 | | - glTexCoord2f(1., 0.);
|
1186 | | - glVertex2f( (float)sizes[0], (float)sizes[1]);
|
1187 | | - glTexCoord2f(0., 0.);
|
1188 | | - glVertex2f(0., (float)sizes[1]);
|
1189 | | - glEnd();
|
| 1193 | + bltvertices[0].x = bltvertices[2].x = (float)sizes[0];
|
| 1194 | + bltvertices[0].y = bltvertices[1].y = bltvertices[1].x = bltvertices[3].x = 0.;
|
| 1195 | + bltvertices[2].y = bltvertices[3].y = (float)sizes[1];
|
1190 | 1196 | }
|
1191 | 1197 | else
|
1192 | 1198 | {
|
1193 | | - glBegin(GL_QUADS);
|
1194 | | - glTexCoord2f(0., 1.);
|
1195 | | - glVertex2f(0., 0.);
|
1196 | | - glTexCoord2f(1., 1.);
|
1197 | | - glVertex2f( (float)fakex, 0.);
|
1198 | | - glTexCoord2f(1., 0.);
|
1199 | | - glVertex2f( (float)fakex, (float)fakey);
|
1200 | | - glTexCoord2f(0., 0.);
|
1201 | | - glVertex2f(0., (float)fakey);
|
1202 | | - glEnd();
|
| 1199 | + bltvertices[0].x = bltvertices[2].x = (float)fakex;
|
| 1200 | + bltvertices[0].y = bltvertices[1].y = bltvertices[1].x = bltvertices[3].x = 0.;
|
| 1201 | + bltvertices[2].y = bltvertices[3].y = (float)fakey;
|
1203 | 1202 | }
|
| 1203 | + bltvertices[0].s = bltvertices[0].t = bltvertices[1].t = bltvertices[2].s = 1.;
|
| 1204 | + 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);
|
| 1210 | + glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
|
1204 | 1211 | glDisable(GL_TEXTURE_2D);
|
1205 | 1212 | glFlush();
|
1206 | 1213 | SwapBuffers(ddInterface->hDC);
|
Index: ddraw/glDirectDrawSurface.h |
— | — | @@ -28,6 +28,16 @@ |
29 | 29 | DDCOLORKEY key;
|
30 | 30 | } CKEY;
|
31 | 31 |
|
| 32 | +struct BltVertex
|
| 33 | +{
|
| 34 | + GLfloat x,y;
|
| 35 | + GLubyte r,g,b,a;
|
| 36 | + GLfloat s,t;
|
| 37 | + GLfloat padding[3];
|
| 38 | +};
|
| 39 | +
|
| 40 | +extern BltVertex bltvertices[4];
|
| 41 | +
|
32 | 42 | class glDirectDrawClipper;
|
33 | 43 | class glDirectDrawPalette;
|
34 | 44 | class glDirectDrawSurface1;
|
Index: ddraw/glExtensions.cpp |
— | — | @@ -54,7 +54,10 @@ |
55 | 55 | void (APIENTRY *glUniform4f) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) = NULL;
|
56 | 56 | void (APIENTRY *glUniformMatrix4fv) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) = NULL;
|
57 | 57 |
|
| 58 | +void (APIENTRY *glDrawRangeElements) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
|
| 59 | +
|
58 | 60 | void (APIENTRY *glActiveTexture)(GLenum texture) = NULL;
|
| 61 | +void (APIENTRY *glClientActiveTexture) (GLenum texture) = NULL;
|
59 | 62 |
|
60 | 63 | BOOL (APIENTRY *wglSwapIntervalEXT)(int interval) = NULL;
|
61 | 64 | int (APIENTRY *wglGetSwapIntervalEXT)() = NULL;
|
— | — | @@ -71,8 +74,13 @@ |
72 | 75 | {
|
73 | 76 | const GLubyte *glversion = glGetString(GL_VERSION);
|
74 | 77 | sscanf((char*)glversion,"%d.%d",&glver_major,&glver_minor);
|
| 78 | + if((glver_major >= 2) || ((glver_major >= 1) && (glver_minor >= 2)))
|
| 79 | + glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC)wglGetProcAddress("glDrawRangeElements");
|
75 | 80 | if((glver_major >= 2) || ((glver_major >= 1) && (glver_minor >= 3)))
|
| 81 | + {
|
76 | 82 | glActiveTexture = (PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture");
|
| 83 | + glClientActiveTexture = (PFNGLCLIENTACTIVETEXTUREPROC)wglGetProcAddress("glClientActiveTexture");
|
| 84 | + }
|
77 | 85 | if(glver_major >= 2)
|
78 | 86 | {
|
79 | 87 | glCreateShader = (PFNGLCREATESHADERPROC)wglGetProcAddress("glCreateShader");
|
Index: ddraw/glExtensions.h |
— | — | @@ -37,6 +37,7 @@ |
38 | 38 | #undef GLAPI
|
39 | 39 | #define GLAPI extern
|
40 | 40 | #endif
|
| 41 | +
|
41 | 42 | GLAPI GLuint (APIENTRY *glCreateShader) (GLenum type);
|
42 | 43 | GLAPI void (APIENTRY *glShaderSource) (GLuint shader, GLsizei count, const GLchar** string, const GLint* length);
|
43 | 44 | GLAPI void (APIENTRY *glCompileShader) (GLuint shader);
|
— | — | @@ -73,7 +74,10 @@ |
74 | 75 | GLAPI void (APIENTRY *glUniform4f) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
|
75 | 76 | GLAPI void (APIENTRY *glUniformMatrix4fv) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
|
76 | 77 |
|
| 78 | +GLAPI void (APIENTRY *glDrawRangeElements) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
|
| 79 | +
|
77 | 80 | GLAPI void (APIENTRY *glActiveTexture)(GLenum texture);
|
| 81 | +GLAPI void (APIENTRY *glClientActiveTexture) (GLenum texture);
|
78 | 82 |
|
79 | 83 | GLAPI BOOL (APIENTRY *wglSwapIntervalEXT)(int interval);
|
80 | 84 | GLAPI int (APIENTRY *wglGetSwapIntervalEXT)();
|
Index: ddraw/shadergen.cpp |
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | static __int64 current_shader = 0;
|
25 | 25 | static int shadercount = 0;
|
26 | 26 | static bool initialized = false;
|
| 27 | +static bool isbuiltin = true;
|
27 | 28 |
|
28 | 29 | void SetShader(__int64 id, bool builtin)
|
29 | 30 | {
|
— | — | @@ -33,7 +34,11 @@ |
34 | 35 | }
|
35 | 36 | }
|
36 | 37 |
|
37 | | -__int64 GetProgram()
|
| 38 | +GLuint GetProgram()
|
38 | 39 | {
|
39 | | - return current_shader;
|
| 40 | + if(isbuiltin) return current_shader & 0xFFFFFFFF;
|
| 41 | + else
|
| 42 | + {
|
| 43 | + return 0;
|
| 44 | + }
|
40 | 45 | }
|
Index: ddraw/shadergen.h |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 |
|
22 | 22 |
|
23 | 23 | void SetShader(__int64 id, bool builtin);
|
24 | | -__int64 GetProgram();
|
| 24 | +GLuint GetProgram();
|
25 | 25 |
|
26 | 26 |
|
27 | 27 | #endif |
\ No newline at end of file |
Index: ddraw/shaders.cpp |
— | — | @@ -123,7 +123,6 @@ |
124 | 124 | {
|
125 | 125 | const GLchar *src;
|
126 | 126 | GLint srclen;
|
127 | | - GLenum error;
|
128 | 127 | for(int i = 0; i < NumberOfShaders; i++)
|
129 | 128 | {
|
130 | 129 | shaders[i].prog = glCreateProgram();
|