| Index: ddraw/glDirect3DDevice.cpp |
| — | — | @@ -210,14 +210,16 @@ |
| 211 | 211 | diffuse = specular = NULL;
|
| 212 | 212 | ZeroMemory(texcoords,8*sizeof(GLfloat*));
|
| 213 | 213 | memcpy(renderstate,renderstate_default,153*sizeof(DWORD));
|
| 214 | | - __gluMakeIdentityf((GLfloat*)&matrices[0]);
|
| 215 | | - for(int i = 1; i < 24; i++)
|
| 216 | | - memcpy(&matrices[i],&matrices[0],sizeof(D3DMATRIX));
|
| | 214 | + __gluMakeIdentityf(matWorld);
|
| | 215 | + __gluMakeIdentityf(matView);
|
| | 216 | + __gluMakeIdentityf(matProjection);
|
| | 217 | + __gluMakeIdentityf(matNormal);
|
| 217 | 218 | texstages[0] = texstagedefault0;
|
| 218 | 219 | texstages[1] = texstages[2] = texstages[3] = texstages[4] =
|
| 219 | 220 | texstages[5] = texstages[6] = texstages[7] = texstagedefault1;
|
| 220 | 221 | refcount = 1;
|
| 221 | 222 | inscene = false;
|
| | 223 | + normal_dirty = false;
|
| 222 | 224 | this->glD3D7 = glD3D7;
|
| 223 | 225 | glD3D7->AddRef();
|
| 224 | 226 | this->glDDS7 = glDDS7;
|
| — | — | @@ -233,8 +235,6 @@ |
| 234 | 236 | d3ddesc.dwMaxTextureWidth = d3ddesc.dwMaxTextureHeight =
|
| 235 | 237 | d3ddesc.dwMaxTextureRepeat = d3ddesc.dwMaxTextureAspectRatio = glD3D7->glDD7->renderer->gl_caps.TextureMax;
|
| 236 | 238 | glD3D7->glDD7->renderer->InitD3D(zbuffer);
|
| 237 | | - glD3D7->glDD7->renderer->SetRenderState(0,153,renderstate);
|
| 238 | | - glD3D7->glDD7->renderer->SetMatrix(0,24,matrices);
|
| 239 | 239 | }
|
| 240 | 240 | glDirect3DDevice7::~glDirect3DDevice7()
|
| 241 | 241 | {
|
| — | — | @@ -513,8 +513,8 @@ |
| 514 | 514 | if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
|
| 515 | 515 | HRESULT err = fvftoglvertex(dwVertexTypeDesc,(LPDWORD)lpvVertices);
|
| 516 | 516 | if(err != D3D_OK) return err;
|
| 517 | | - return glD3D7->glDD7->renderer->DrawPrimitives(this,setdrawmode(d3dptPrimitiveType),
|
| 518 | | - vertdata,true,texformats,dwVertexCount,lpwIndices,dwIndexCount,dwFlags);
|
| | 517 | + return glD3D7->glDD7->renderer->DrawPrimitives(this,setdrawmode(d3dptPrimitiveType),vertdata,texformats,
|
| | 518 | + dwVertexCount,lpwIndices,dwIndexCount,dwFlags);
|
| 519 | 519 | }
|
| 520 | 520 | HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
| 521 | 521 | LPD3DDRAWPRIMITIVESTRIDEDDATA lpvVerticexArray, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
|
| — | — | @@ -772,9 +772,20 @@ |
| 773 | 773 | HRESULT WINAPI glDirect3DDevice7::GetTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
|
| 774 | 774 | {
|
| 775 | 775 | if(!this) return DDERR_INVALIDPARAMS;
|
| 776 | | - if(dtstTransformStateType > D3DTRANSFORMSTATE_TEXTURE7) return DDERR_INVALIDPARAMS;
|
| 777 | | - memcpy(lpD3DMatrix,&matrices[dtstTransformStateType],sizeof(D3DMATRIX));
|
| 778 | | - return D3D_OK;
|
| | 776 | + switch(dtstTransformStateType)
|
| | 777 | + {
|
| | 778 | + case D3DTRANSFORMSTATE_WORLD:
|
| | 779 | + memcpy(lpD3DMatrix,&matWorld,sizeof(D3DMATRIX));
|
| | 780 | + return D3D_OK;
|
| | 781 | + case D3DTRANSFORMSTATE_VIEW:
|
| | 782 | + memcpy(lpD3DMatrix,&matView,sizeof(D3DMATRIX));
|
| | 783 | + return D3D_OK;
|
| | 784 | + case D3DTRANSFORMSTATE_PROJECTION:
|
| | 785 | + memcpy(lpD3DMatrix,&matProjection,sizeof(D3DMATRIX));
|
| | 786 | + return D3D_OK;
|
| | 787 | + default:
|
| | 788 | + ERR(DDERR_INVALIDPARAMS);
|
| | 789 | + }
|
| 779 | 790 | }
|
| 780 | 791 | HRESULT WINAPI glDirect3DDevice7::GetViewport(LPD3DVIEWPORT7 lpViewport)
|
| 781 | 792 | {
|
| — | — | @@ -1127,10 +1138,22 @@ |
| 1128 | 1139 | HRESULT WINAPI glDirect3DDevice7::SetTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
|
| 1129 | 1140 | {
|
| 1130 | 1141 | if(!this) return DDERR_INVALIDPARAMS;
|
| 1131 | | - if(dtstTransformStateType > D3DTRANSFORMSTATE_TEXTURE7) return DDERR_INVALIDPARAMS;
|
| 1132 | | - memcpy(&matrices[dtstTransformStateType],lpD3DMatrix,sizeof(D3DMATRIX));
|
| 1133 | | - glD3D7->glDD7->renderer->SetMatrix(dtstTransformStateType,1,lpD3DMatrix);
|
| 1134 | | - return D3D_OK;
|
| | 1142 | + switch(dtstTransformStateType)
|
| | 1143 | + {
|
| | 1144 | + case D3DTRANSFORMSTATE_WORLD:
|
| | 1145 | + memcpy(&matWorld,lpD3DMatrix,sizeof(D3DMATRIX));
|
| | 1146 | + normal_dirty = true;
|
| | 1147 | + return D3D_OK;
|
| | 1148 | + case D3DTRANSFORMSTATE_VIEW:
|
| | 1149 | + memcpy(&matView,lpD3DMatrix,sizeof(D3DMATRIX));
|
| | 1150 | + normal_dirty = true;
|
| | 1151 | + return D3D_OK;
|
| | 1152 | + case D3DTRANSFORMSTATE_PROJECTION:
|
| | 1153 | + memcpy(&matProjection,lpD3DMatrix,sizeof(D3DMATRIX));
|
| | 1154 | + return D3D_OK;
|
| | 1155 | + default:
|
| | 1156 | + ERR(DDERR_INVALIDPARAMS);
|
| | 1157 | + }
|
| 1135 | 1158 | }
|
| 1136 | 1159 | HRESULT WINAPI glDirect3DDevice7::SetViewport(LPD3DVIEWPORT7 lpViewport)
|
| 1137 | 1160 | {
|
| — | — | @@ -1164,3 +1187,26 @@ |
| 1165 | 1188 | return D3D_OK;
|
| 1166 | 1189 | }
|
| 1167 | 1190 |
|
| | 1191 | +void glDirect3DDevice7::UpdateNormalMatrix()
|
| | 1192 | +{
|
| | 1193 | + GLfloat worldview[16];
|
| | 1194 | + GLfloat tmp[16];
|
| | 1195 | +
|
| | 1196 | + ZeroMemory(&worldview,sizeof(D3DMATRIX));
|
| | 1197 | + ZeroMemory(&tmp,sizeof(D3DMATRIX));
|
| | 1198 | + __gluMultMatricesf(matWorld,matView,worldview); // Get worldview
|
| | 1199 | + if(__gluInvertMatrixf(worldview,tmp)) // Invert
|
| | 1200 | + {
|
| | 1201 | + memcpy(matNormal,tmp,3*sizeof(GLfloat));
|
| | 1202 | + memcpy(matNormal+3,tmp+4,3*sizeof(GLfloat));
|
| | 1203 | + memcpy(matNormal+6,tmp+8,3*sizeof(GLfloat));
|
| | 1204 | + }
|
| | 1205 | + else
|
| | 1206 | + {
|
| | 1207 | + memcpy(matNormal,worldview,3*sizeof(GLfloat));
|
| | 1208 | + memcpy(matNormal+3,worldview+4,3*sizeof(GLfloat));
|
| | 1209 | + memcpy(matNormal+6,worldview+8,3*sizeof(GLfloat));
|
| | 1210 | + }
|
| | 1211 | +
|
| | 1212 | + normal_dirty = false;
|
| | 1213 | +} |
| \ No newline at end of file |
| Index: ddraw/glDirect3DDevice.h |
| — | — | @@ -122,7 +122,12 @@ |
| 123 | 123 | HRESULT WINAPI ValidateDevice(LPDWORD lpdwPasses);
|
| 124 | 124 | void SetArraySize(DWORD size, DWORD vertex, DWORD texcoord);
|
| 125 | 125 | __int64 SelectShader(GLVERTEX *VertexType);
|
| 126 | | - D3DMATRIX matrices[24];
|
| | 126 | + void UpdateNormalMatrix();
|
| | 127 | + GLfloat matWorld[16];
|
| | 128 | + GLfloat matView[16];
|
| | 129 | + GLfloat matProjection[16];
|
| | 130 | + GLfloat matNormal[9];
|
| | 131 | + bool normal_dirty;
|
| 127 | 132 | D3DMATERIAL7 material;
|
| 128 | 133 | D3DVIEWPORT7 viewport;
|
| 129 | 134 | glDirect3DLight **lights;
|
| — | — | @@ -148,7 +153,7 @@ |
| 149 | 154 | GLubyte *ambient;
|
| 150 | 155 | GLfloat *texcoords[8];
|
| 151 | 156 | GLVERTEX vertdata[18];
|
| 152 | | - DWORD texformats[8];
|
| | 157 | + int texformats[8];
|
| 153 | 158 | };
|
| 154 | 159 |
|
| 155 | 160 | #endif //__GLDIRECT3DDEVICE_H |
| \ No newline at end of file |
| Index: ddraw/glDirectDraw.cpp |
| — | — | @@ -1380,7 +1380,7 @@ |
| 1381 | 1381 |
|
| 1382 | 1382 | void glDirectDraw7::DeleteGL()
|
| 1383 | 1383 | {
|
| 1384 | | - if(renderer) delete renderer;
|
| | 1384 | + delete renderer;
|
| 1385 | 1385 | renderer = NULL;
|
| 1386 | 1386 | }
|
| 1387 | 1387 |
|
| Index: ddraw/glRenderer.cpp |
| — | — | @@ -15,11 +15,6 @@ |
| 16 | 16 | // License along with this library; if not, write to the Free Software
|
| 17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | 18 |
|
| 19 | | -/**
|
| 20 | | - * @file glRenderer.cpp
|
| 21 | | - * @brief Contains the functions that control the DXGL rendering pipeline.
|
| 22 | | - */
|
| 23 | | -
|
| 24 | 19 | #include "common.h"
|
| 25 | 20 | #include "glDirectDraw.h"
|
| 26 | 21 | #include "glDirectDrawSurface.h"
|
| — | — | @@ -31,7 +26,6 @@ |
| 32 | 27 | #include "ddraw.h"
|
| 33 | 28 | #include "scalers.h"
|
| 34 | 29 | #include <string>
|
| 35 | | -#include <cstdarg>
|
| 36 | 30 | using namespace std;
|
| 37 | 31 | #include "shadergen.h"
|
| 38 | 32 | #include "matrix.h"
|
| — | — | @@ -43,37 +37,8 @@ |
| 44 | 38 | int backy = 0;
|
| 45 | 39 | BltVertex bltvertices[4];
|
| 46 | 40 | const GLushort bltindices[4] = {0,1,2,3};
|
| 47 | | -const RECT nullrect = {0,0,0,0};
|
| 48 | 41 |
|
| 49 | 42 | /**
|
| 50 | | - * Waits for an object to be signaled, while processing window messages received
|
| 51 | | - * by the calling thread.
|
| 52 | | - * @param object
|
| 53 | | - * Win32 handle to the object to wait for
|
| 54 | | - */
|
| 55 | | -void WaitForMessageAndObject(HANDLE object)
|
| 56 | | -{
|
| 57 | | - bool loop = true;
|
| 58 | | - DWORD wake;
|
| 59 | | - MSG msg;
|
| 60 | | - DWORD error;
|
| 61 | | - while(loop)
|
| 62 | | - {
|
| 63 | | - wake = MsgWaitForMultipleObjects(1,&object,FALSE,INFINITE,QS_ALLEVENTS);
|
| 64 | | - if(wake == (WAIT_OBJECT_0+1))
|
| 65 | | - {
|
| 66 | | - while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
|
| 67 | | - {
|
| 68 | | - TranslateMessage(&msg);
|
| 69 | | - DispatchMessage(&msg);
|
| 70 | | - }
|
| 71 | | - }
|
| 72 | | - else loop = false;
|
| 73 | | - error = GetLastError();
|
| 74 | | - }
|
| 75 | | -}
|
| 76 | | -
|
| 77 | | -/**
|
| 78 | 43 | * Expands a 5-bit value to 8 bits.
|
| 79 | 44 | * @param number
|
| 80 | 45 | * 5-bit value to convert to 8 bits.
|
| — | — | @@ -116,122 +81,6 @@ |
| 117 | 82 | }
|
| 118 | 83 |
|
| 119 | 84 | /**
|
| 120 | | - * Adds a command to the renderer queue.\n
|
| 121 | | - * If the command requires more space than the queue buffer, the buffer will be
|
| 122 | | - * expanded. If there is no free space for the command, execution will pause
|
| 123 | | - * until the queue has been sufficiently emptied.
|
| 124 | | - * @param opcode
|
| 125 | | - * Code that describes the command to be added to the queue.
|
| 126 | | - * @param mode
|
| 127 | | - * Method to use for synchronization:
|
| 128 | | - * - 0: Do not fail the call
|
| 129 | | - * - 1: Fail if queue is full
|
| 130 | | - * - 2: Fail if queue is not empty
|
| 131 | | - * @param size
|
| 132 | | - * Size of the command in DWORDs
|
| 133 | | - * @param paramcount
|
| 134 | | - * Number of parameters to add to the queue command.
|
| 135 | | - * @param ...
|
| 136 | | - * Parameters for the command, when required. This is given in pairs of two
|
| 137 | | - * arguments:
|
| 138 | | - * - size: The size of the parameter, in bytes. Note that parameters are DWORD
|
| 139 | | - * aligned. The size cannot exceed the size of the command, minus data already
|
| 140 | | - * written to the queue.
|
| 141 | | - * - pointer: A pointer to the data to be added to the command.\n
|
| 142 | | - * If no parameters are used for the opcode, then supply 0 and NULL for the ...
|
| 143 | | - * parameter.
|
| 144 | | - * @return
|
| 145 | | - * Zero if the call succeeds, nonzero otherwise.
|
| 146 | | - */
|
| 147 | | -int glRenderer::AddQueue(DWORD opcode, int mode, DWORD size, int paramcount, ...)
|
| 148 | | -{
|
| 149 | | - EnterCriticalSection(&queuecs);
|
| 150 | | - if((mode == 2) && queuelength)
|
| 151 | | - {
|
| 152 | | - LeaveCriticalSection(&queuecs);
|
| 153 | | - return 1;
|
| 154 | | - }
|
| 155 | | - va_list params;
|
| 156 | | - // Check queue size
|
| 157 | | - va_start(params,paramcount);
|
| 158 | | - int argsize;
|
| 159 | | - void *argptr;
|
| 160 | | - if(size > queuesize)
|
| 161 | | - {
|
| 162 | | - queue = (LPDWORD)realloc(queue,(queuesize+size)*sizeof(DWORD));
|
| 163 | | - queuesize += size;
|
| 164 | | - }
|
| 165 | | - if(queuesize - queue_write < size)
|
| 166 | | - {
|
| 167 | | - if(queue_read < size)
|
| 168 | | - {
|
| 169 | | - if(mode == 1)
|
| 170 | | - {
|
| 171 | | - LeaveCriticalSection(&queuecs);
|
| 172 | | - return 1;
|
| 173 | | - }
|
| 174 | | - if(queue_write < queuesize)
|
| 175 | | - {
|
| 176 | | - queue[queue_write] = OP_RESETQUEUE;
|
| 177 | | - queuelength++;
|
| 178 | | - }
|
| 179 | | - LeaveCriticalSection(&queuecs);
|
| 180 | | - Sync(size);
|
| 181 | | - EnterCriticalSection(&queuecs);
|
| 182 | | - }
|
| 183 | | - }
|
| 184 | | - if(queue_write < queue_read)
|
| 185 | | - {
|
| 186 | | - if(queue_read - queue_write < size)
|
| 187 | | - {
|
| 188 | | - LeaveCriticalSection(&queuecs);
|
| 189 | | - Sync(size);
|
| 190 | | - EnterCriticalSection(&queuecs);
|
| 191 | | - }
|
| 192 | | - }
|
| 193 | | - queue[queue_write++] = opcode;
|
| 194 | | - queue[queue_write++] = size;
|
| 195 | | - size -= 2;
|
| 196 | | - for(int i = 0; i < paramcount; i++)
|
| 197 | | - {
|
| 198 | | - argsize = va_arg(params,int);
|
| 199 | | - argptr = va_arg(params,void*);
|
| 200 | | - if(!argsize) continue;
|
| 201 | | - if((NextMultipleOf4(argsize)/4) > size) break;
|
| 202 | | - queue[queue_write++] = argsize;
|
| 203 | | - if(argptr) memcpy(queue+queue_write,argptr,argsize);
|
| 204 | | - queue_write += (NextMultipleOf4(argsize)/4);
|
| 205 | | - size -= (NextMultipleOf4(argsize)/4);
|
| 206 | | - }
|
| 207 | | - va_end(params);
|
| 208 | | - queuelength++;
|
| 209 | | - if(!running) SetEvent(start);
|
| 210 | | - LeaveCriticalSection(&queuecs);
|
| 211 | | - return 0;
|
| 212 | | -}
|
| 213 | | -
|
| 214 | | -/**
|
| 215 | | - * Waits until the specified amount of queue space is free
|
| 216 | | - * @param size
|
| 217 | | - * If nonzero, the number of DWORDs that must be available within the queue.
|
| 218 | | - * If zero, waits until the queue is empty.
|
| 219 | | - */
|
| 220 | | -void glRenderer::Sync(int size)
|
| 221 | | -{
|
| 222 | | - EnterCriticalSection(&queuecs);
|
| 223 | | - if(!queuelength && !running)
|
| 224 | | - {
|
| 225 | | - LeaveCriticalSection(&queuecs);
|
| 226 | | - return;
|
| 227 | | - }
|
| 228 | | - ResetEvent(sync);
|
| 229 | | - syncsize = size;
|
| 230 | | - if(!running) SetEvent(start);
|
| 231 | | - LeaveCriticalSection(&queuecs);
|
| 232 | | - WaitForMessageAndObject(sync);
|
| 233 | | -}
|
| 234 | | -
|
| 235 | | -/**
|
| 236 | 85 | * Internal function for uploading surface content to an OpenGL texture
|
| 237 | 86 | * @param buffer
|
| 238 | 87 | * Contains the contents of the surface
|
| — | — | @@ -286,9 +135,9 @@ |
| 287 | 136 | }
|
| 288 | 137 | glTexImage2D(GL_TEXTURE_2D,0,texformat3,bigx,bigy,0,texformat,texformat2,bigbuffer);
|
| 289 | 138 | }
|
| | 139 | + return 0;
|
| 290 | 140 | }
|
| 291 | 141 |
|
| 292 | | -
|
| 293 | 142 | /**
|
| 294 | 143 | * Internal function for downloading surface content from an OpenGL texture
|
| 295 | 144 | * @param buffer
|
| — | — | @@ -342,6 +191,7 @@ |
| 343 | 192 | break;
|
| 344 | 193 | }
|
| 345 | 194 | }
|
| | 195 | + return 0;
|
| 346 | 196 | }
|
| 347 | 197 |
|
| 348 | 198 | /**
|
| — | — | @@ -358,18 +208,16 @@ |
| 359 | 209 | */
|
| 360 | 210 | glRenderer::glRenderer(int width, int height, int bpp, bool fullscreen, HWND hwnd, glDirectDraw7 *glDD7)
|
| 361 | 211 | {
|
| | 212 | + MSG Msg;
|
| | 213 | + wndbusy = false;
|
| 362 | 214 | hDC = NULL;
|
| 363 | 215 | hRC = NULL;
|
| 364 | 216 | PBO = 0;
|
| 365 | 217 | hasHWnd = false;
|
| 366 | 218 | dib.enabled = false;
|
| 367 | | - normal_dirty = false;
|
| 368 | | - running = false;
|
| 369 | 219 | hWnd = hwnd;
|
| 370 | 220 | hRenderWnd = NULL;
|
| 371 | | - busy = CreateEvent(NULL,FALSE,FALSE,NULL);
|
| 372 | | - InitializeCriticalSection(&commandcs);
|
| 373 | | - InitializeCriticalSection(&queuecs);
|
| | 221 | + InitializeCriticalSection(&cs);
|
| 374 | 222 | if(fullscreen)
|
| 375 | 223 | {
|
| 376 | 224 | SetWindowLongPtrA(hWnd,GWL_EXSTYLE,WS_EX_APPWINDOW);
|
| — | — | @@ -380,7 +228,6 @@ |
| 381 | 229 | {
|
| 382 | 230 | // TODO: Adjust window rect
|
| 383 | 231 | }
|
| 384 | | - EnterCriticalSection(&commandcs);
|
| 385 | 232 | SetWindowPos(hWnd,HWND_TOP,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
|
| 386 | 233 | inputs[0] = (void*)width;
|
| 387 | 234 | inputs[1] = (void*)height;
|
| — | — | @@ -389,9 +236,17 @@ |
| 390 | 237 | inputs[4] = (void*)hWnd;
|
| 391 | 238 | inputs[5] = glDD7;
|
| 392 | 239 | inputs[6] = this;
|
| | 240 | + wndbusy = true;
|
| 393 | 241 | hThread = CreateThread(NULL,0,ThreadEntry,inputs,0,NULL);
|
| 394 | | - WaitForMessageAndObject(busy);
|
| 395 | | - LeaveCriticalSection(&commandcs);
|
| | 242 | + while(wndbusy)
|
| | 243 | + {
|
| | 244 | + while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| | 245 | + {
|
| | 246 | + TranslateMessage(&Msg);
|
| | 247 | + DispatchMessage(&Msg);
|
| | 248 | + }
|
| | 249 | + Sleep(0);
|
| | 250 | + }
|
| 396 | 251 | }
|
| 397 | 252 |
|
| 398 | 253 | /**
|
| — | — | @@ -399,14 +254,21 @@ |
| 400 | 255 | */
|
| 401 | 256 | glRenderer::~glRenderer()
|
| 402 | 257 | {
|
| 403 | | - EnterCriticalSection(&commandcs);
|
| 404 | | - AddQueue(OP_DELETE,0,2,0,NULL);
|
| 405 | | - Sync(0);
|
| 406 | | - LeaveCriticalSection(&commandcs);
|
| 407 | | - DeleteCriticalSection(&commandcs);
|
| 408 | | - CloseHandle(busy);
|
| 409 | | - CloseHandle(sync);
|
| 410 | | - CloseHandle(start);
|
| | 258 | + MSG Msg;
|
| | 259 | + EnterCriticalSection(&cs);
|
| | 260 | + wndbusy = true;
|
| | 261 | + SendMessage(hRenderWnd,GLEVENT_DELETE,0,0);
|
| | 262 | + while(wndbusy)
|
| | 263 | + {
|
| | 264 | + while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| | 265 | + {
|
| | 266 | + TranslateMessage(&Msg);
|
| | 267 | + DispatchMessage(&Msg);
|
| | 268 | + }
|
| | 269 | + Sleep(0);
|
| | 270 | + }
|
| | 271 | + LeaveCriticalSection(&cs);
|
| | 272 | + DeleteCriticalSection(&cs);
|
| 411 | 273 | }
|
| 412 | 274 |
|
| 413 | 275 | /**
|
| — | — | @@ -440,15 +302,21 @@ |
| 441 | 303 | */
|
| 442 | 304 | GLuint glRenderer::MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3)
|
| 443 | 305 | {
|
| 444 | | - EnterCriticalSection(&commandcs);
|
| 445 | | - AddQueue(OP_CREATE,0,20,9,4,&min,4,&mag,4,&wraps,4,&wrapt,4,&width,
|
| 446 | | - 4,&height,4,&texformat1,4,&texformat2,4,&texformat3);
|
| 447 | | - Sync(0);
|
| 448 | | - LeaveCriticalSection(&commandcs);
|
| 449 | | - return (GLuint)output;
|
| | 306 | + EnterCriticalSection(&cs);
|
| | 307 | + inputs[0] = (void*)min;
|
| | 308 | + inputs[1] = (void*)mag;
|
| | 309 | + inputs[2] = (void*)wraps;
|
| | 310 | + inputs[3] = (void*)wrapt;
|
| | 311 | + inputs[4] = (void*)width;
|
| | 312 | + inputs[5] = (void*)height;
|
| | 313 | + inputs[6] = (void*)texformat1;
|
| | 314 | + inputs[7] = (void*)texformat2;
|
| | 315 | + inputs[8] = (void*)texformat3;
|
| | 316 | + SendMessage(hRenderWnd,GLEVENT_CREATE,0,0);
|
| | 317 | + LeaveCriticalSection(&cs);
|
| | 318 | + return (GLuint)outputs[0];
|
| 450 | 319 | }
|
| 451 | 320 |
|
| 452 | | -
|
| 453 | 321 | /**
|
| 454 | 322 | * Uploads the content of a surface to an OpenGL texture.
|
| 455 | 323 | * @param buffer
|
| — | — | @@ -475,14 +343,37 @@ |
| 476 | 344 | * @param texformat3
|
| 477 | 345 | * OpenGL internalformat parameter for glTexImage2D
|
| 478 | 346 | */
|
| 479 | | -void glRenderer::UploadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y,
|
| | 347 | +int glRenderer::UploadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y,
|
| 480 | 348 | int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2, int texformat3)
|
| 481 | 349 | {
|
| 482 | | - EnterCriticalSection(&commandcs);
|
| 483 | | - AddQueue(OP_UPLOAD,0,28,13,4,&buffer,4,&bigbuffer,4,&texture,4,&x,4,&y,4,&bigx,
|
| 484 | | - 4,&bigy,4,&pitch,4,&bigpitch,4,&bpp,4,&texformat,4,&texformat2,4,&texformat3);
|
| 485 | | - Sync(0);
|
| 486 | | - LeaveCriticalSection(&commandcs);
|
| | 350 | + EnterCriticalSection(&cs);
|
| | 351 | + MSG Msg;
|
| | 352 | + inputs[0] = buffer;
|
| | 353 | + inputs[1] = bigbuffer;
|
| | 354 | + inputs[2] = (void*)texture;
|
| | 355 | + inputs[3] = (void*)x;
|
| | 356 | + inputs[4] = (void*)y;
|
| | 357 | + inputs[5] = (void*)bigx;
|
| | 358 | + inputs[6] = (void*)bigy;
|
| | 359 | + inputs[7] = (void*)pitch;
|
| | 360 | + inputs[8] = (void*)bigpitch;
|
| | 361 | + inputs[9] = (void*)bpp;
|
| | 362 | + inputs[10] = (void*)texformat;
|
| | 363 | + inputs[11] = (void*)texformat2;
|
| | 364 | + inputs[12] = (void*)texformat3;
|
| | 365 | + wndbusy = true;
|
| | 366 | + SendMessage(hRenderWnd,GLEVENT_UPLOAD,0,0);
|
| | 367 | + while(wndbusy)
|
| | 368 | + {
|
| | 369 | + while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| | 370 | + {
|
| | 371 | + TranslateMessage(&Msg);
|
| | 372 | + DispatchMessage(&Msg);
|
| | 373 | + }
|
| | 374 | + Sleep(0);
|
| | 375 | + }
|
| | 376 | + LeaveCriticalSection(&cs);
|
| | 377 | + return (int)outputs[0];
|
| 487 | 378 | }
|
| 488 | 379 |
|
| 489 | 380 | /**
|
| — | — | @@ -509,14 +400,36 @@ |
| 510 | 401 | * @param texformat2
|
| 511 | 402 | * OpenGL type parameter for glGetTexImage
|
| 512 | 403 | */
|
| 513 | | -void glRenderer::DownloadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y,
|
| | 404 | +int glRenderer::DownloadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y,
|
| 514 | 405 | int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2)
|
| 515 | 406 | {
|
| 516 | | - EnterCriticalSection(&commandcs);
|
| 517 | | - AddQueue(OP_DOWNLOAD,0,26,12,4,&buffer,4,&bigbuffer,4,&texture,4,&x,4,&y,4,&bigx,
|
| 518 | | - 4,&bigy,4,&pitch,4,&bigpitch,4,&bpp,4,&texformat,4,&texformat2);
|
| 519 | | - Sync(0);
|
| 520 | | - LeaveCriticalSection(&commandcs);
|
| | 407 | + EnterCriticalSection(&cs);
|
| | 408 | + MSG Msg;
|
| | 409 | + inputs[0] = buffer;
|
| | 410 | + inputs[1] = bigbuffer;
|
| | 411 | + inputs[2] = (void*)texture;
|
| | 412 | + inputs[3] = (void*)x;
|
| | 413 | + inputs[4] = (void*)y;
|
| | 414 | + inputs[5] = (void*)bigx;
|
| | 415 | + inputs[6] = (void*)bigy;
|
| | 416 | + inputs[7] = (void*)pitch;
|
| | 417 | + inputs[8] = (void*)bigpitch;
|
| | 418 | + inputs[9] = (void*)bpp;
|
| | 419 | + inputs[10] = (void*)texformat;
|
| | 420 | + inputs[11] = (void*)texformat2;
|
| | 421 | + wndbusy = true;
|
| | 422 | + SendMessage(hRenderWnd,GLEVENT_DOWNLOAD,0,0);
|
| | 423 | + while(wndbusy)
|
| | 424 | + {
|
| | 425 | + while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| | 426 | + {
|
| | 427 | + TranslateMessage(&Msg);
|
| | 428 | + DispatchMessage(&Msg);
|
| | 429 | + }
|
| | 430 | + Sleep(0);
|
| | 431 | + }
|
| | 432 | + LeaveCriticalSection(&cs);
|
| | 433 | + return (int)outputs[0];
|
| 521 | 434 | }
|
| 522 | 435 |
|
| 523 | 436 | /**
|
| — | — | @@ -526,9 +439,10 @@ |
| 527 | 440 | */
|
| 528 | 441 | void glRenderer::DeleteTexture(GLuint texture)
|
| 529 | 442 | {
|
| 530 | | - EnterCriticalSection(&commandcs);
|
| 531 | | - AddQueue(OP_DELETETEX,0,4,1,4,&texture);
|
| 532 | | - LeaveCriticalSection(&commandcs);
|
| | 443 | + EnterCriticalSection(&cs);
|
| | 444 | + inputs[0] = (void*)texture;
|
| | 445 | + SendMessage(hRenderWnd,GLEVENT_DELETETEX,0,0);
|
| | 446 | + LeaveCriticalSection(&cs);
|
| 533 | 447 | }
|
| 534 | 448 |
|
| 535 | 449 | /**
|
| — | — | @@ -544,7 +458,7 @@ |
| 545 | 459 | * entire surface will be used.
|
| 546 | 460 | * @param dwFlags
|
| 547 | 461 | * Flags to determine the behavior of the blitter. Certain flags control the
|
| 548 | | - * synchronization of the operation:
|
| | 462 | + * synchronization of the operation: (not yet implemented)
|
| 549 | 463 | * - DDBLT_ASYNC: Adds the command to the queue. If the queue is full, returns
|
| 550 | 464 | * DDERR_WASSTILLDRAWING.
|
| 551 | 465 | * - DDBLT_DONOTWAIT: Fails and returns DDERR_WASSTILLDRAWING if the queue is full.
|
| — | — | @@ -557,26 +471,27 @@ |
| 558 | 472 | HRESULT glRenderer::Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
| 559 | 473 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
|
| 560 | 474 | {
|
| 561 | | - DWORD nullfx = 0xFFFFFFFF;
|
| 562 | | - RECT emptyrect = nullrect;
|
| 563 | | - EnterCriticalSection(&commandcs);
|
| 564 | | - int syncmode = 0;
|
| 565 | | - if(dwFlags & DDBLT_ASYNC) syncmode = 1;
|
| 566 | | - if(dwFlags & DDBLT_DONOTWAIT) syncmode = 2;
|
| 567 | | - if(!lpSrcRect) lpSrcRect = &emptyrect;
|
| 568 | | - if(!lpDestRect) lpDestRect = &emptyrect;
|
| 569 | | - int fxsize = 4;
|
| 570 | | - if(lpDDBltFx) fxsize = sizeof(DDBLTFX);
|
| 571 | | - else lpDDBltFx = (LPDDBLTFX)&nullfx;
|
| 572 | | - if(AddQueue(OP_BLT,syncmode,5+(sizeof(RECT)/2)+(fxsize/4),6,sizeof(RECT),lpDestRect,4,&src,
|
| 573 | | - 4,&dest,sizeof(RECT),lpSrcRect,4,&dwFlags,fxsize,lpDDBltFx))
|
| | 475 | + MSG Msg;
|
| | 476 | + EnterCriticalSection(&cs);
|
| | 477 | + inputs[0] = lpDestRect;
|
| | 478 | + inputs[1] = src;
|
| | 479 | + inputs[2] = dest;
|
| | 480 | + inputs[3] = lpSrcRect;
|
| | 481 | + inputs[4] = (void*)dwFlags;
|
| | 482 | + inputs[5] = lpDDBltFx;
|
| | 483 | + wndbusy = true;
|
| | 484 | + SendMessage(hRenderWnd,GLEVENT_BLT,0,0);
|
| | 485 | + while(wndbusy)
|
| 574 | 486 | {
|
| 575 | | - LeaveCriticalSection(&commandcs);
|
| 576 | | - return DDERR_WASSTILLDRAWING;
|
| | 487 | + while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| | 488 | + {
|
| | 489 | + TranslateMessage(&Msg);
|
| | 490 | + DispatchMessage(&Msg);
|
| | 491 | + }
|
| | 492 | + Sleep(0);
|
| 577 | 493 | }
|
| 578 | | - if(dwFlags & DDBLT_WAIT) Sync(0);
|
| 579 | | - LeaveCriticalSection(&commandcs);
|
| 580 | | - return DD_OK;
|
| | 494 | + LeaveCriticalSection(&cs);
|
| | 495 | + return (HRESULT)outputs[0];
|
| 581 | 496 | }
|
| 582 | 497 |
|
| 583 | 498 | /**
|
| — | — | @@ -592,10 +507,24 @@ |
| 593 | 508 | */
|
| 594 | 509 | void glRenderer::DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src)
|
| 595 | 510 | {
|
| 596 | | - EnterCriticalSection(&commandcs);
|
| 597 | | - AddQueue(OP_DRAWSCREEN,0,10,4,4,&texture,4,&paltex,4,&dest,4,&src);
|
| 598 | | - Sync(0);
|
| 599 | | - LeaveCriticalSection(&commandcs);
|
| | 511 | + MSG Msg;
|
| | 512 | + EnterCriticalSection(&cs);
|
| | 513 | + inputs[0] = (void*)texture;
|
| | 514 | + inputs[1] = (void*)paltex;
|
| | 515 | + inputs[2] = dest;
|
| | 516 | + inputs[3] = src;
|
| | 517 | + wndbusy = true;
|
| | 518 | + SendMessage(hRenderWnd,GLEVENT_DRAWSCREEN,0,0);
|
| | 519 | + while(wndbusy)
|
| | 520 | + {
|
| | 521 | + while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| | 522 | + {
|
| | 523 | + TranslateMessage(&Msg);
|
| | 524 | + DispatchMessage(&Msg);
|
| | 525 | + }
|
| | 526 | + Sleep(0);
|
| | 527 | + }
|
| | 528 | + LeaveCriticalSection(&cs);
|
| 600 | 529 | }
|
| 601 | 530 |
|
| 602 | 531 | /**
|
| — | — | @@ -605,9 +534,21 @@ |
| 606 | 535 | */
|
| 607 | 536 | void glRenderer::InitD3D(int zbuffer)
|
| 608 | 537 | {
|
| 609 | | - EnterCriticalSection(&commandcs);
|
| 610 | | - AddQueue(OP_INITD3D,0,4,1,4,zbuffer);
|
| 611 | | - LeaveCriticalSection(&commandcs);
|
| | 538 | + MSG Msg;
|
| | 539 | + EnterCriticalSection(&cs);
|
| | 540 | + wndbusy = true;
|
| | 541 | + inputs[0] = (void*)zbuffer;
|
| | 542 | + SendMessage(hRenderWnd,GLEVENT_INITD3D,0,0);
|
| | 543 | + while(wndbusy)
|
| | 544 | + {
|
| | 545 | + while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| | 546 | + {
|
| | 547 | + TranslateMessage(&Msg);
|
| | 548 | + DispatchMessage(&Msg);
|
| | 549 | + }
|
| | 550 | + Sleep(0);
|
| | 551 | + }
|
| | 552 | + LeaveCriticalSection(&cs);
|
| 612 | 553 | }
|
| 613 | 554 |
|
| 614 | 555 | /**
|
| — | — | @@ -631,23 +572,49 @@ |
| 632 | 573 | */
|
| 633 | 574 | HRESULT glRenderer::Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
|
| 634 | 575 | {
|
| 635 | | - EnterCriticalSection(&commandcs);
|
| 636 | | - int rectsize = dwCount * sizeof(D3DRECT);
|
| 637 | | - AddQueue(OP_CLEAR,0,15+(rectsize/4),7,4,&target,4,&dwCount,rectsize,lpRects,
|
| 638 | | - 4,dwFlags,4,dwColor,4,dvZ,4,dwStencil);
|
| 639 | | - LeaveCriticalSection(&commandcs);
|
| 640 | | - return D3D_OK;
|
| | 576 | + MSG Msg;
|
| | 577 | + EnterCriticalSection(&cs);
|
| | 578 | + wndbusy = true;
|
| | 579 | + inputs[0] = target;
|
| | 580 | + inputs[1] = (void*)dwCount;
|
| | 581 | + inputs[2] = lpRects;
|
| | 582 | + inputs[3] = (void*)dwFlags;
|
| | 583 | + inputs[4] = (void*)dwColor;
|
| | 584 | + memcpy(&inputs[5],&dvZ,4);
|
| | 585 | + inputs[6] = (void*)dwStencil;
|
| | 586 | + SendMessage(hRenderWnd,GLEVENT_CLEAR,0,0);
|
| | 587 | + while(wndbusy)
|
| | 588 | + {
|
| | 589 | + while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| | 590 | + {
|
| | 591 | + TranslateMessage(&Msg);
|
| | 592 | + DispatchMessage(&Msg);
|
| | 593 | + }
|
| | 594 | + Sleep(0);
|
| | 595 | + }
|
| | 596 | + LeaveCriticalSection(&cs);
|
| | 597 | + return (HRESULT)outputs[0];
|
| 641 | 598 | }
|
| 642 | 599 |
|
| 643 | 600 | /**
|
| 644 | | - * Issues a glFlush command and empties the queue.
|
| | 601 | + * Flushes queued OpenGL commands to the GPU.
|
| 645 | 602 | */
|
| 646 | 603 | void glRenderer::Flush()
|
| 647 | 604 | {
|
| 648 | | - EnterCriticalSection(&commandcs);
|
| 649 | | - AddQueue(OP_CLEAR,0,2,0,0,NULL);
|
| 650 | | - Sync(0);
|
| 651 | | - LeaveCriticalSection(&commandcs);
|
| | 605 | + MSG Msg;
|
| | 606 | + EnterCriticalSection(&cs);
|
| | 607 | + wndbusy = true;
|
| | 608 | + SendMessage(hRenderWnd,GLEVENT_FLUSH,0,0);
|
| | 609 | + while(wndbusy)
|
| | 610 | + {
|
| | 611 | + while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| | 612 | + {
|
| | 613 | + TranslateMessage(&Msg);
|
| | 614 | + DispatchMessage(&Msg);
|
| | 615 | + }
|
| | 616 | + Sleep(0);
|
| | 617 | + }
|
| | 618 | + LeaveCriticalSection(&cs);
|
| 652 | 619 | }
|
| 653 | 620 |
|
| 654 | 621 | /**
|
| — | — | @@ -670,89 +637,40 @@ |
| 671 | 638 | * @param indexcount
|
| 672 | 639 | * Number of vertex indices. May be 0 for non-indexed mode.
|
| 673 | 640 | * @param flags
|
| 674 | | - * Set to D3DDP_WAIT to wait until the queue has processed the call.
|
| | 641 | + * Set to D3DDP_WAIT to wait until the queue has processed the call. (not yet
|
| | 642 | + * implemented)
|
| 675 | 643 | * @return
|
| 676 | 644 | * D3D_OK if the call succeeds, or D3DERR_INVALIDVERTEXTYPE if the vertex format
|
| 677 | 645 | * has no position coordinates.
|
| 678 | 646 | */
|
| 679 | | -HRESULT glRenderer::DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, bool packed,
|
| 680 | | - DWORD *texformats, DWORD count, LPWORD indices, DWORD indexcount, DWORD flags)
|
| | 647 | +HRESULT glRenderer::DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
| | 648 | + DWORD indexcount, DWORD flags)
|
| 681 | 649 | {
|
| 682 | | - if(!vertices[0].data) return D3DERR_INVALIDVERTEXTYPE;
|
| 683 | | - GLVERTEX vertdata[18];
|
| 684 | | - EnterCriticalSection(&commandcs);
|
| 685 | | - __int64 shader = device->SelectShader(vertices);
|
| 686 | | - int vertsize = 0;
|
| 687 | | - if(packed)
|
| | 650 | + MSG Msg;
|
| | 651 | + EnterCriticalSection(&cs);
|
| | 652 | + wndbusy = true;
|
| | 653 | + inputs[0] = device;
|
| | 654 | + inputs[1] = (void*)mode;
|
| | 655 | + inputs[2] = vertices;
|
| | 656 | + inputs[3] = texformats;
|
| | 657 | + inputs[4] = (void*)count;
|
| | 658 | + inputs[5] = indices;
|
| | 659 | + inputs[6] = (void*)indexcount;
|
| | 660 | + inputs[7] = (void*)flags;
|
| | 661 | + SendMessage(hRenderWnd,GLEVENT_DRAWPRIMITIVES,0,0);
|
| | 662 | + while(wndbusy)
|
| 688 | 663 | {
|
| 689 | | - vertsize = vertices[0].stride * count;
|
| 690 | | - AddQueue(OP_DRAWPRIMITIVES,0,NextMultipleOf4(40+(18*sizeof(GLVERTEX))+(8*sizeof(DWORD))+(indexcount*sizeof(WORD))+vertsize)/4,
|
| 691 | | - 10,4,&device,4,&mode,18*sizeof(GLVERTEX),vertices,1,&packed,8*sizeof(DWORD),texformats,4,&count,indexcount*sizeof(WORD),
|
| 692 | | - &indices,4,&indexcount,4,&flags,8,&shader,vertsize,vertices[0].data);
|
| 693 | | - }
|
| 694 | | - else
|
| 695 | | - {
|
| 696 | | - for(int i = 0; i < 18; i++)
|
| | 664 | + while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| 697 | 665 | {
|
| 698 | | - vertdata[i].stride = vertices[i].stride;
|
| 699 | | - if(vertices[i].data)
|
| 700 | | - {
|
| 701 | | - vertdata[i].data = (void*)vertsize;
|
| 702 | | - vertsize += (vertices[i].stride * count);
|
| 703 | | - }
|
| 704 | | - else vertdata[i].data = (void*)-1;
|
| | 666 | + TranslateMessage(&Msg);
|
| | 667 | + DispatchMessage(&Msg);
|
| 705 | 668 | }
|
| 706 | | - FIXME("glRenderer::DrawPrimitives: Add Strided Vertex format");
|
| 707 | | - AddQueue(OP_DRAWPRIMITIVES,0,NextMultipleOf4(32+(18*sizeof(GLVERTEX))+(8*sizeof(DWORD))+(indexcount*sizeof(WORD))+vertsize)/4,
|
| 708 | | - 10,4,&device,4,&mode,18*sizeof(GLVERTEX),vertdata,1,packed,8*sizeof(DWORD),texformats,4,count,indexcount*sizeof(WORD),
|
| 709 | | - indices,4,indexcount,4,flags,vertsize,vertdata[0].data);
|
| | 669 | + Sleep(0);
|
| 710 | 670 | }
|
| 711 | | - if(flags & D3DDP_WAIT) Sync(0);
|
| 712 | | - LeaveCriticalSection(&commandcs);
|
| 713 | | - return D3D_OK;
|
| | 671 | + return (HRESULT)outputs[0];
|
| 714 | 672 | }
|
| 715 | 673 |
|
| 716 | 674 | /**
|
| 717 | | - * Sets one or more render states in the glRenderer class
|
| 718 | | - * @param index
|
| 719 | | - * Index of the render state(s) to set
|
| 720 | | - * @param count
|
| 721 | | - * Number of states to set at once
|
| 722 | | - * @param data
|
| 723 | | - * Pointer to state data to copy
|
| 724 | | - * @remark
|
| 725 | | - * If the render thread is not currently running, this function will immediately
|
| 726 | | - * copy the data to the renderer. Otherwise, it will add a command to the queue.
|
| 727 | | - */
|
| 728 | | -void glRenderer::SetRenderState(DWORD index, DWORD count, DWORD *data)
|
| 729 | | -{
|
| 730 | | - EnterCriticalSection(&commandcs);
|
| 731 | | - if(!running) memcpy(&renderstate[index],data,count*sizeof(DWORD));
|
| 732 | | - else AddQueue(OP_SETRENDERSTATE,0,4+count,2,4,&index,count*4,data);
|
| 733 | | - LeaveCriticalSection(&commandcs);
|
| 734 | | -}
|
| 735 | | -
|
| 736 | | -/**
|
| 737 | | - * Sets one or more Direct3D matrices in the glRenderer class
|
| 738 | | - * @param index
|
| 739 | | - * Index of the matrix or matrices to set
|
| 740 | | - * @param count
|
| 741 | | - * Number of matrices to set at once
|
| 742 | | - * @param data
|
| 743 | | - * Pointer to matrices to copy
|
| 744 | | - * @remark
|
| 745 | | - * If the render thread is not currently running, this function will immediately
|
| 746 | | - * copy the data to the renderer. Otherwise, it will add a command to the queue.
|
| 747 | | - */
|
| 748 | | -void glRenderer::SetMatrix(DWORD index, DWORD count, D3DMATRIX *data)
|
| 749 | | -{
|
| 750 | | - EnterCriticalSection(&commandcs);
|
| 751 | | - if(!running) memcpy(&renderstate[index],data,count*sizeof(D3DMATRIX));
|
| 752 | | - else AddQueue(OP_SETMATRIX,0,4+((count*sizeof(D3DMATRIX))/4),2,4,&index,count*4,data);
|
| 753 | | - LeaveCriticalSection(&commandcs);
|
| 754 | | -}
|
| 755 | | -
|
| 756 | | -/**
|
| 757 | 675 | * Main loop for glRenderer class
|
| 758 | 676 | * @return
|
| 759 | 677 | * Returns 0 to signal successful thread termination
|
| — | — | @@ -759,102 +677,15 @@ |
| 760 | 678 | */
|
| 761 | 679 | DWORD glRenderer::_Entry()
|
| 762 | 680 | {
|
| 763 | | - DWORD size;
|
| 764 | 681 | MSG Msg;
|
| | 682 | + EnterCriticalSection(&cs);
|
| 765 | 683 | _InitGL((int)inputs[0],(int)inputs[1],(int)inputs[2],(int)inputs[3],(HWND)inputs[4],(glDirectDraw7*)inputs[5]);
|
| 766 | | - dead = false;
|
| 767 | | - queue = (LPDWORD)malloc(1048576);
|
| 768 | | - queuesize = 1048576/sizeof(DWORD);
|
| 769 | | - queuelength = queue_read = queue_write = syncsize = 0;
|
| 770 | | - SetEvent(busy);
|
| 771 | | - start = CreateEvent(NULL,TRUE,FALSE,NULL);
|
| 772 | | - ResetEvent(start);
|
| 773 | | - sync = CreateEvent(NULL,TRUE,FALSE,NULL);
|
| 774 | | - queueloop:
|
| 775 | | - MsgWaitForMultipleObjects(1,&start,FALSE,INFINITE,QS_ALLEVENTS);
|
| 776 | | - if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))
|
| | 684 | + LeaveCriticalSection(&cs);
|
| | 685 | + while(GetMessage(&Msg, NULL, 0, 0) > 0)
|
| 777 | 686 | {
|
| 778 | 687 | TranslateMessage(&Msg);
|
| 779 | 688 | DispatchMessage(&Msg);
|
| 780 | 689 | }
|
| 781 | | - if(queuelength)
|
| 782 | | - {
|
| 783 | | - running = true;
|
| 784 | | - switch(queue[queue_read])
|
| 785 | | - {
|
| 786 | | - case OP_NULL:
|
| 787 | | - default:
|
| 788 | | - break;
|
| 789 | | - case OP_DELETE:
|
| 790 | | - DestroyWindow(hRenderWnd);
|
| 791 | | - break;
|
| 792 | | - case OP_CREATE:
|
| 793 | | - if(queue[queue_read+1] != 20) break;
|
| 794 | | - output = (void*)_MakeTexture(queue[queue_read+3],queue[queue_read+5],queue[queue_read+7],queue[queue_read+9],
|
| 795 | | - queue[queue_read+11],queue[queue_read+13],queue[queue_read+15],queue[queue_read+17],queue[queue_read+19]);
|
| 796 | | - break;
|
| 797 | | - case OP_UPLOAD:
|
| 798 | | - if(queue[queue_read+1] != 28) break;
|
| 799 | | - _UploadTexture((char*)queue[queue_read+3],(char*)queue[queue_read+5],queue[queue_read+7],queue[queue_read+9],
|
| 800 | | - queue[queue_read+11],queue[queue_read+13],queue[queue_read+15],queue[queue_read+17],queue[queue_read+19],
|
| 801 | | - queue[queue_read+21],queue[queue_read+23],queue[queue_read+25],queue[queue_read+27]);
|
| 802 | | - break;
|
| 803 | | - case OP_DOWNLOAD:
|
| 804 | | - if(queue[queue_read+1] != 26) break;
|
| 805 | | - _DownloadTexture((char*)queue[queue_read+3],(char*)queue[queue_read+5],queue[queue_read+7],queue[queue_read+9],
|
| 806 | | - queue[queue_read+11],queue[queue_read+13],queue[queue_read+15],queue[queue_read+17],queue[queue_read+19],
|
| 807 | | - queue[queue_read+21],queue[queue_read+23],queue[queue_read+25]);
|
| 808 | | - break;
|
| 809 | | - case OP_DELETETEX:
|
| 810 | | - if(queue[queue_read+1] != 4) break;
|
| 811 | | - _DeleteTexture(queue[queue_read+3]);
|
| 812 | | - break;
|
| 813 | | - case OP_BLT:
|
| 814 | | - if(queue[queue_read+1] < 5) break;
|
| 815 | | - _Blt((LPRECT)&queue[queue_read+3],(glDirectDrawSurface7*)queue[queue_read+4+(sizeof(RECT)/4)],
|
| 816 | | - (glDirectDrawSurface7*)queue[queue_read+6+(sizeof(RECT)/4)],(LPRECT)&queue[queue_read+8+(sizeof(RECT)/4)],
|
| 817 | | - queue[queue_read+9+(sizeof(RECT)/2)],(LPDDBLTFX)&queue[queue_read+11+(sizeof(RECT)/2)]);
|
| 818 | | - break;
|
| 819 | | - case OP_DRAWSCREEN:
|
| 820 | | - if(queue[queue_read+1] != 10) break;
|
| 821 | | - _DrawScreen(queue[queue_read+3],queue[queue_read+5],(glDirectDrawSurface7*)queue[queue_read+7],
|
| 822 | | - (glDirectDrawSurface7*)queue[queue_read+9]);
|
| 823 | | - break;
|
| 824 | | - case OP_INITD3D:
|
| 825 | | - if(queue[queue_read+1] != 4) break;
|
| 826 | | - _InitD3D(queue[queue_read+3]);
|
| 827 | | - break;
|
| 828 | | - case OP_CLEAR:
|
| 829 | | - if(queue[queue_read+1] < 15) break;
|
| 830 | | - size = queue[queue_read+1] - 15;
|
| 831 | | - if(!size) _Clear((glDirectDrawSurface7*)queue[queue_read+3],queue[queue_read+5],NULL,
|
| 832 | | - queue[queue_read+8],queue[queue_read+10],queue[queue_read+12],queue[queue_read+14]);
|
| 833 | | - else _Clear((glDirectDrawSurface7*)queue[queue_read+3],queue[queue_read+5],(LPD3DRECT)&queue[queue_read+7],
|
| 834 | | - queue[queue_read+8+size],queue[queue_read+10+size],queue[queue_read+12+size],
|
| 835 | | - queue[queue_read+14+size]);
|
| 836 | | - break;
|
| 837 | | - case OP_FLUSH:
|
| 838 | | - _Flush();
|
| 839 | | - break;
|
| 840 | | - }
|
| 841 | | - EnterCriticalSection(&queuecs);
|
| 842 | | - queuelength--;
|
| 843 | | - queue_read+=queue[queue_read+1];
|
| 844 | | - if((queue_read >= syncsize) && syncsize != 0) SetEvent(sync);
|
| 845 | | - }
|
| 846 | | - else EnterCriticalSection(&queuecs);
|
| 847 | | - if(!queuelength)
|
| 848 | | - {
|
| 849 | | - ResetEvent(start);
|
| 850 | | - queue_read = 0;
|
| 851 | | - queue_write = 0;
|
| 852 | | - running = false;
|
| 853 | | - SetEvent(sync);
|
| 854 | | - }
|
| 855 | | - LeaveCriticalSection(&queuecs);
|
| 856 | | - if(!dead) goto queueloop;
|
| 857 | | - free(queue);
|
| 858 | | - queue = NULL;
|
| 859 | 690 | return 0;
|
| 860 | 691 | }
|
| 861 | 692 |
|
| — | — | @@ -909,13 +740,8 @@ |
| 910 | 741 | {
|
| 911 | 742 | width = GetSystemMetrics(SM_CXSCREEN);
|
| 912 | 743 | height = GetSystemMetrics(SM_CYSCREEN);
|
| 913 | | -#ifdef _DEBUG
|
| 914 | | - hRenderWnd = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_LAYERED|WS_EX_TRANSPARENT,
|
| 915 | | - "DXGLRenderWindow","Renderer",WS_POPUP,0,0,width,height,0,0,NULL,this);
|
| 916 | | -#else
|
| 917 | 744 | hRenderWnd = CreateWindowExA(WS_EX_TOOLWINDOW|WS_EX_LAYERED|WS_EX_TRANSPARENT|WS_EX_TOPMOST,
|
| 918 | 745 | "DXGLRenderWindow","Renderer",WS_POPUP,0,0,width,height,0,0,NULL,this);
|
| 919 | | -#endif
|
| 920 | 746 | hasHWnd = false;
|
| 921 | 747 | SetWindowPos(hRenderWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW|SWP_NOACTIVATE);
|
| 922 | 748 | }
|
| — | — | @@ -971,6 +797,7 @@ |
| 972 | 798 | gllock = false;
|
| 973 | 799 | return FALSE;
|
| 974 | 800 | }
|
| | 801 | + wndbusy = false;
|
| 975 | 802 | gllock = false;
|
| 976 | 803 | InitGLExt();
|
| 977 | 804 | SetSwap(1);
|
| — | — | @@ -1017,7 +844,7 @@ |
| 1018 | 845 | return TRUE;
|
| 1019 | 846 | }
|
| 1020 | 847 |
|
| 1021 | | -void glRenderer::_Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
| | 848 | +HRESULT glRenderer::_Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
| 1022 | 849 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
|
| 1023 | 850 | {
|
| 1024 | 851 | LONG sizes[6];
|
| — | — | @@ -1032,6 +859,7 @@ |
| 1033 | 860 | if(memcmp(&r2,&r,sizeof(RECT)))
|
| 1034 | 861 | SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
|
| 1035 | 862 | }
|
| | 863 | + wndbusy = false;
|
| 1036 | 864 | ddInterface->GetSizes(sizes);
|
| 1037 | 865 | int error;
|
| 1038 | 866 | error = SetFBO(dest->texture,0,false);
|
| — | — | @@ -1172,7 +1000,7 @@ |
| 1173 | 1001 | (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
|
| 1174 | 1002 | ((ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
|
| 1175 | 1003 | !(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)))_DrawScreen(dest->texture,dest->paltex,dest,dest);
|
| 1176 | | - SetEvent(busy);
|
| | 1004 | + return DD_OK;
|
| 1177 | 1005 | }
|
| 1178 | 1006 |
|
| 1179 | 1007 | GLuint glRenderer::_MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3)
|
| — | — | @@ -1242,6 +1070,7 @@ |
| 1243 | 1071 | if(memcmp(&r2,&r,sizeof(RECT)))
|
| 1244 | 1072 | SetWindowPos(hRenderWnd,NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
|
| 1245 | 1073 | }
|
| | 1074 | + wndbusy = false;
|
| 1246 | 1075 | RECT *viewrect = &r2;
|
| 1247 | 1076 | SetSwap(swapinterval);
|
| 1248 | 1077 | LONG sizes[6];
|
| — | — | @@ -1391,15 +1220,14 @@ |
| 1392 | 1221 | void glRenderer::_DeleteTexture(GLuint texture)
|
| 1393 | 1222 | {
|
| 1394 | 1223 | glDeleteTextures(1,&texture);
|
| 1395 | | - SetEvent(busy);
|
| 1396 | 1224 | }
|
| 1397 | 1225 |
|
| 1398 | 1226 | void glRenderer::_InitD3D(int zbuffer)
|
| 1399 | 1227 | {
|
| 1400 | | - if(zbuffer) glEnable(GL_DEPTH_TEST);
|
| 1401 | | - SetEvent(busy);
|
| | 1228 | + wndbusy = false;
|
| 1402 | 1229 | glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
|
| 1403 | 1230 | GLfloat ambient[] = {0.0,0.0,0.0,0.0};
|
| | 1231 | + if(zbuffer) glEnable(GL_DEPTH_TEST);
|
| 1404 | 1232 | glDepthFunc(GL_LEQUAL);
|
| 1405 | 1233 | glDisable(GL_DITHER);
|
| 1406 | 1234 | }
|
| — | — | @@ -1408,9 +1236,13 @@ |
| 1409 | 1237 | {
|
| 1410 | 1238 | if(dwCount)
|
| 1411 | 1239 | {
|
| | 1240 | + outputs[0] = (void*)DDERR_INVALIDPARAMS;
|
| 1412 | 1241 | FIXME("glDirect3DDevice7::Clear: Cannot clear rects yet.");
|
| | 1242 | + wndbusy = false;
|
| 1413 | 1243 | return;
|
| 1414 | 1244 | }
|
| | 1245 | + outputs[0] = (void*)D3D_OK;
|
| | 1246 | + wndbusy = false;
|
| 1415 | 1247 | GLfloat color[4];
|
| 1416 | 1248 | dwordto4float(dwColor,color);
|
| 1417 | 1249 | if(target->zbuffer) SetFBO(target->texture,target->GetZBuffer()->texture,target->GetZBuffer()->hasstencil);
|
| — | — | @@ -1434,13 +1266,12 @@ |
| 1435 | 1267 | glClear(clearbits);
|
| 1436 | 1268 | if(target->zbuffer) target->zbuffer->dirty |= 2;
|
| 1437 | 1269 | target->dirty |= 2;
|
| 1438 | | - SetEvent(busy);
|
| 1439 | 1270 | }
|
| 1440 | 1271 |
|
| 1441 | 1272 | void glRenderer::_Flush()
|
| 1442 | 1273 | {
|
| | 1274 | + wndbusy = false;
|
| 1443 | 1275 | glFlush();
|
| 1444 | | - SetEvent(busy);
|
| 1445 | 1276 | }
|
| 1446 | 1277 |
|
| 1447 | 1278 | void glRenderer::_DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
| — | — | @@ -1454,6 +1285,12 @@ |
| 1455 | 1286 | int i;
|
| 1456 | 1287 | if(vertices[1].data) transformed = true;
|
| 1457 | 1288 | else transformed = false;
|
| | 1289 | + if(!vertices[0].data)
|
| | 1290 | + {
|
| | 1291 | + outputs[0] = (void*)DDERR_INVALIDPARAMS;
|
| | 1292 | + wndbusy = false;
|
| | 1293 | + return;
|
| | 1294 | + }
|
| 1458 | 1295 | __int64 shader = device->SelectShader(vertices);
|
| 1459 | 1296 | SetShader(shader,device->texstages,texformats,0);
|
| 1460 | 1297 | _GENSHADER prog = genshaders[current_genshader].shader;
|
| — | — | @@ -1536,11 +1373,11 @@ |
| 1537 | 1374 |
|
| 1538 | 1375 | }
|
| 1539 | 1376 | }
|
| 1540 | | - if(normal_dirty) _UpdateNormalMatrix();
|
| 1541 | | - if(prog.uniforms[0] != -1) glUniformMatrix4fv(prog.uniforms[0],1,false,(GLfloat*)&matrices[1]);
|
| 1542 | | - if(prog.uniforms[1] != -1) glUniformMatrix4fv(prog.uniforms[1],1,false,(GLfloat*)&matrices[2]);
|
| 1543 | | - if(prog.uniforms[2] != -1) glUniformMatrix4fv(prog.uniforms[2],1,false,(GLfloat*)&matrices[3]);
|
| 1544 | | - if(prog.uniforms[3] != -1) glUniformMatrix3fv(prog.uniforms[3],1,true,(GLfloat*)&matrices[7]);
|
| | 1377 | + if(device->normal_dirty) device->UpdateNormalMatrix();
|
| | 1378 | + if(prog.uniforms[0] != -1) glUniformMatrix4fv(prog.uniforms[0],1,false,device->matWorld);
|
| | 1379 | + if(prog.uniforms[1] != -1) glUniformMatrix4fv(prog.uniforms[1],1,false,device->matView);
|
| | 1380 | + if(prog.uniforms[2] != -1) glUniformMatrix4fv(prog.uniforms[2],1,false,device->matProjection);
|
| | 1381 | + if(prog.uniforms[3] != -1) glUniformMatrix3fv(prog.uniforms[3],1,true,device->matNormal);
|
| 1545 | 1382 |
|
| 1546 | 1383 | if(prog.uniforms[15] != -1) glUniform4fv(prog.uniforms[15],1,(GLfloat*)&device->material.ambient);
|
| 1547 | 1384 | if(prog.uniforms[16] != -1) glUniform4fv(prog.uniforms[16],1,(GLfloat*)&device->material.diffuse);
|
| — | — | @@ -1584,7 +1421,7 @@ |
| 1585 | 1422 | lightindex++;
|
| 1586 | 1423 | }
|
| 1587 | 1424 |
|
| 1588 | | - DWORD ambient = renderstate[D3DRENDERSTATE_AMBIENT];
|
| | 1425 | + DWORD ambient = device->renderstate[D3DRENDERSTATE_AMBIENT];
|
| 1589 | 1426 | if(prog.uniforms[136] != -1)
|
| 1590 | 1427 | glUniform4f(prog.uniforms[136],RGBA_GETRED(ambient),RGBA_GETGREEN(ambient),
|
| 1591 | 1428 | RGBA_GETBLUE(ambient),RGBA_GETALPHA(ambient));
|
| — | — | @@ -1621,32 +1458,11 @@ |
| 1622 | 1459 | if(device->glDDS7->zbuffer) device->glDDS7->zbuffer->dirty |= 2;
|
| 1623 | 1460 | device->glDDS7->dirty |= 2;
|
| 1624 | 1461 | if(flags & D3DDP_WAIT) glFlush();
|
| 1625 | | - SetEvent(busy);
|
| | 1462 | + outputs[0] = (void*)D3D_OK;
|
| | 1463 | + wndbusy = false;
|
| 1626 | 1464 | return;
|
| 1627 | 1465 | }
|
| 1628 | | -void glRenderer::_UpdateNormalMatrix()
|
| 1629 | | -{
|
| 1630 | | - GLfloat worldview[16];
|
| 1631 | | - GLfloat tmp[16];
|
| 1632 | 1466 |
|
| 1633 | | - ZeroMemory(&worldview,sizeof(D3DMATRIX));
|
| 1634 | | - ZeroMemory(&tmp,sizeof(D3DMATRIX));
|
| 1635 | | - __gluMultMatricesf((GLfloat*)&matrices[1],(GLfloat*)&matrices[2],worldview); // Get worldview
|
| 1636 | | - if(__gluInvertMatrixf(worldview,tmp)) // Invert
|
| 1637 | | - {
|
| 1638 | | - memcpy((GLfloat*)&matrices[7],tmp,3*sizeof(GLfloat));
|
| 1639 | | - memcpy((GLfloat*)&matrices[7]+3,tmp+4,3*sizeof(GLfloat));
|
| 1640 | | - memcpy((GLfloat*)&matrices[7]+6,tmp+8,3*sizeof(GLfloat));
|
| 1641 | | - }
|
| 1642 | | - else
|
| 1643 | | - {
|
| 1644 | | - memcpy((GLfloat*)&matrices[7],worldview,3*sizeof(GLfloat));
|
| 1645 | | - memcpy((GLfloat*)&matrices[7]+3,worldview+4,3*sizeof(GLfloat));
|
| 1646 | | - memcpy((GLfloat*)&matrices[7]+6,worldview+8,3*sizeof(GLfloat));
|
| 1647 | | - }
|
| 1648 | | -
|
| 1649 | | - normal_dirty = false;
|
| 1650 | | -}
|
| 1651 | 1467 | LRESULT glRenderer::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
| 1652 | 1468 | {
|
| 1653 | 1469 | int oldx,oldy;
|
| — | — | @@ -1691,15 +1507,14 @@ |
| 1692 | 1508 | };
|
| 1693 | 1509 | if(hDC) ReleaseDC(hRenderWnd,hDC);
|
| 1694 | 1510 | hDC = NULL;
|
| | 1511 | + wndbusy = false;
|
| 1695 | 1512 | PostQuitMessage(0);
|
| 1696 | | - dead = true;
|
| 1697 | 1513 | return 0;
|
| 1698 | 1514 | case WM_SETCURSOR:
|
| 1699 | 1515 | hParent = GetParent(hwnd);
|
| 1700 | 1516 | cursor = (HCURSOR)GetClassLong(hParent,GCL_HCURSOR);
|
| 1701 | 1517 | SetCursor(cursor);
|
| 1702 | | - PostMessage(hParent,msg,wParam,lParam);
|
| 1703 | | - return 0;
|
| | 1518 | + return SendMessage(hParent,msg,wParam,lParam);
|
| 1704 | 1519 | case WM_MOUSEMOVE:
|
| 1705 | 1520 | case WM_LBUTTONDOWN:
|
| 1706 | 1521 | case WM_LBUTTONUP:
|
| — | — | @@ -1734,10 +1549,53 @@ |
| 1735 | 1550 | if(oldx >= sizes[2]) oldx = sizes[2]-1;
|
| 1736 | 1551 | if(oldy >= sizes[3]) oldy = sizes[3]-1;
|
| 1737 | 1552 | newpos = oldx + (oldy << 16);
|
| 1738 | | - PostMessage(hParent,msg,wParam,newpos);
|
| | 1553 | + return SendMessage(hParent,msg,wParam,newpos);
|
| 1739 | 1554 | }
|
| 1740 | | - else PostMessage(hParent,msg,wParam,lParam);
|
| | 1555 | + else return SendMessage(hParent,msg,wParam,lParam);
|
| | 1556 | + case GLEVENT_DELETE:
|
| | 1557 | + DestroyWindow(hRenderWnd);
|
| 1741 | 1558 | return 0;
|
| | 1559 | + case GLEVENT_CREATE:
|
| | 1560 | + outputs[0] = (void*)_MakeTexture((GLint)inputs[0],(GLint)inputs[1],(GLint)inputs[2],(GLint)inputs[3],
|
| | 1561 | + (DWORD)inputs[4],(DWORD)inputs[5],(GLint)inputs[6],(GLint)inputs[7],(GLint)inputs[8]);
|
| | 1562 | + return 0;
|
| | 1563 | + case GLEVENT_UPLOAD:
|
| | 1564 | + outputs[0] = (void*)_UploadTexture((char*)inputs[0],(char*)inputs[1],(GLuint)inputs[2],(int)inputs[3],
|
| | 1565 | + (int)inputs[4],(int)inputs[5],(int)inputs[6],(int)inputs[7],(int)inputs[8],(int)inputs[9],
|
| | 1566 | + (int)inputs[10],(int)inputs[11],(int)inputs[12]);
|
| | 1567 | + wndbusy = false;
|
| | 1568 | + return 0;
|
| | 1569 | + case GLEVENT_DOWNLOAD:
|
| | 1570 | + outputs[0] = (void*)_DownloadTexture((char*)inputs[0],(char*)inputs[1],(GLuint)inputs[2],(int)inputs[3],
|
| | 1571 | + (int)inputs[4],(int)inputs[5],(int)inputs[6],(int)inputs[7],(int)inputs[8],(int)inputs[9],
|
| | 1572 | + (int)inputs[10],(int)inputs[11]);
|
| | 1573 | + wndbusy = false;
|
| | 1574 | + return 0;
|
| | 1575 | + case GLEVENT_DELETETEX:
|
| | 1576 | + _DeleteTexture((GLuint)inputs[0]);
|
| | 1577 | + return 0;
|
| | 1578 | + case GLEVENT_BLT:
|
| | 1579 | + outputs[0] = (void*)_Blt((LPRECT)inputs[0],(glDirectDrawSurface7*)inputs[1],(glDirectDrawSurface7*)inputs[2],
|
| | 1580 | + (LPRECT)inputs[3],(DWORD)inputs[4],(LPDDBLTFX)inputs[5]);
|
| | 1581 | + return 0;
|
| | 1582 | + case GLEVENT_DRAWSCREEN:
|
| | 1583 | + _DrawScreen((GLuint)inputs[0],(GLuint)inputs[1],(glDirectDrawSurface7*)inputs[2],(glDirectDrawSurface7*)inputs[3]);
|
| | 1584 | + return 0;
|
| | 1585 | + case GLEVENT_INITD3D:
|
| | 1586 | + _InitD3D((int)inputs[0]);
|
| | 1587 | + return 0;
|
| | 1588 | + case GLEVENT_CLEAR:
|
| | 1589 | + memcpy(&tmpfloats[0],&inputs[5],4);
|
| | 1590 | + _Clear((glDirectDrawSurface7*)inputs[0],(DWORD)inputs[1],(LPD3DRECT)inputs[2],(DWORD)inputs[3],(DWORD)inputs[4],
|
| | 1591 | + tmpfloats[0],(DWORD)inputs[6]);
|
| | 1592 | + return 0;
|
| | 1593 | + case GLEVENT_FLUSH:
|
| | 1594 | + _Flush();
|
| | 1595 | + return 0;
|
| | 1596 | + case GLEVENT_DRAWPRIMITIVES:
|
| | 1597 | + _DrawPrimitives((glDirect3DDevice7*)inputs[0],(GLenum)inputs[1],(GLVERTEX*)inputs[2],(int*)inputs[3],(DWORD)inputs[4],
|
| | 1598 | + (LPWORD)inputs[5],(DWORD)inputs[6],(DWORD)inputs[7]);
|
| | 1599 | + return 0;
|
| 1742 | 1600 | default:
|
| 1743 | 1601 | return DefWindowProc(hwnd,msg,wParam,lParam);
|
| 1744 | 1602 | }
|
| Index: ddraw/glRenderer.h |
| — | — | @@ -52,24 +52,20 @@ |
| 53 | 53 |
|
| 54 | 54 | extern BltVertex bltvertices[4];
|
| 55 | 55 |
|
| 56 | | -#define OP_NULL 0
|
| 57 | | -#define OP_DELETE 1
|
| 58 | | -#define OP_CREATE 2
|
| 59 | | -#define OP_UPLOAD 3
|
| 60 | | -#define OP_DOWNLOAD 4
|
| 61 | | -#define OP_DELETETEX 5
|
| 62 | | -#define OP_BLT 6
|
| 63 | | -#define OP_DRAWSCREEN 7
|
| 64 | | -#define OP_INITD3D 8
|
| 65 | | -#define OP_CLEAR 9
|
| 66 | | -#define OP_FLUSH 10
|
| 67 | | -#define OP_DRAWPRIMITIVES 11
|
| 68 | | -#define OP_SETRENDERSTATE 12
|
| 69 | | -#define OP_SETMATRIX 13
|
| | 56 | +#define GLEVENT_NULL WM_USER
|
| | 57 | +#define GLEVENT_DELETE WM_USER+1
|
| | 58 | +#define GLEVENT_CREATE WM_USER+2
|
| | 59 | +#define GLEVENT_UPLOAD WM_USER+3
|
| | 60 | +#define GLEVENT_DOWNLOAD WM_USER+4
|
| | 61 | +#define GLEVENT_DELETETEX WM_USER+5
|
| | 62 | +#define GLEVENT_BLT WM_USER+6
|
| | 63 | +#define GLEVENT_DRAWSCREEN WM_USER+7
|
| | 64 | +#define GLEVENT_INITD3D WM_USER+8
|
| | 65 | +#define GLEVENT_CLEAR WM_USER+9
|
| | 66 | +#define GLEVENT_FLUSH WM_USER+10
|
| | 67 | +#define GLEVENT_DRAWPRIMITIVES WM_USER+11
|
| 70 | 68 |
|
| 71 | | -#define OP_RESETQUEUE 0xFFFFFFFF
|
| 72 | 69 |
|
| 73 | | -
|
| 74 | 70 | extern int swapinterval;
|
| 75 | 71 | extern inline void SetSwap(int swap);
|
| 76 | 72 |
|
| — | — | @@ -83,8 +79,8 @@ |
| 84 | 80 | glRenderer(int width, int height, int bpp, bool fullscreen, HWND hwnd, glDirectDraw7 *glDD7);
|
| 85 | 81 | ~glRenderer();
|
| 86 | 82 | static DWORD WINAPI ThreadEntry(void *entry);
|
| 87 | | - void UploadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2, int texformat3);
|
| 88 | | - void DownloadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2);
|
| | 83 | + int UploadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2, int texformat3);
|
| | 84 | + int DownloadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2);
|
| 89 | 85 | HRESULT Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
| 90 | 86 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
|
| 91 | 87 | GLuint MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3);
|
| — | — | @@ -92,12 +88,8 @@ |
| 93 | 89 | void DeleteTexture(GLuint texture);
|
| 94 | 90 | void InitD3D(int zbuffer);
|
| 95 | 91 | void Flush();
|
| 96 | | - void SetRenderState(DWORD index, DWORD count, DWORD *data);
|
| 97 | | - void SetMatrix(DWORD index, DWORD count, D3DMATRIX *data);
|
| 98 | | - void Sync(int size);
|
| 99 | | - int AddQueue(DWORD opcode, int mode, DWORD size, int paramcount, ...);
|
| 100 | 92 | HRESULT Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
|
| 101 | | - HRESULT DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, bool packed, DWORD *texformats, DWORD count, LPWORD indices,
|
| | 93 | + HRESULT DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
| 102 | 94 | DWORD indexcount, DWORD flags);
|
| 103 | 95 | HGLRC hRC;
|
| 104 | 96 | LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
| — | — | @@ -106,9 +98,9 @@ |
| 107 | 99 | // In-thread APIs
|
| 108 | 100 | DWORD _Entry();
|
| 109 | 101 | BOOL _InitGL(int width, int height, int bpp, int fullscreen, HWND hWnd, glDirectDraw7 *glDD7);
|
| 110 | | - void _UploadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2, int texformat3);
|
| 111 | | - void _DownloadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2);
|
| 112 | | - void _Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
| | 102 | + int _UploadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2, int texformat3);
|
| | 103 | + int _DownloadTexture(char *buffer, char *bigbuffer, GLuint texture, int x, int y, int bigx, int bigy, int pitch, int bigpitch, int bpp, int texformat, int texformat2);
|
| | 104 | + HRESULT _Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
| 113 | 105 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx);
|
| 114 | 106 | GLuint _MakeTexture(GLint min, GLint mag, GLint wraps, GLint wrapt, DWORD width, DWORD height, GLint texformat1, GLint texformat2, GLint texformat3);
|
| 115 | 107 | void _DrawScreen(GLuint texture, GLuint paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src);
|
| — | — | @@ -116,16 +108,14 @@ |
| 117 | 109 | void _DrawBackbuffer(GLuint *texture, int x, int y);
|
| 118 | 110 | void _InitD3D(int zbuffer);
|
| 119 | 111 | void _Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
|
| 120 | | - void _DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texcormats, DWORD count, LPWORD indices,
|
| | 112 | + void glRenderer::_DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texcormats, DWORD count, LPWORD indices,
|
| 121 | 113 | DWORD indexcount, DWORD flags);
|
| 122 | | - void _SetRenderState(DWORD index, DWORD count, DWORD *data);
|
| 123 | | - void _SetMatrix(DWORD index, DWORD count, D3DMATRIX *data);
|
| 124 | | - void _UpdateNormalMatrix();
|
| 125 | 114 | glDirectDraw7 *ddInterface;
|
| 126 | 115 | void _Flush();
|
| 127 | | - void* inputs[7];
|
| 128 | | - void* output;
|
| | 116 | + void* inputs[32];
|
| | 117 | + void* outputs[32];
|
| 129 | 118 | HANDLE hThread;
|
| | 119 | + bool wndbusy;
|
| 130 | 120 | HDC hDC;
|
| 131 | 121 | HWND hWnd;
|
| 132 | 122 | HWND hRenderWnd;
|
| — | — | @@ -132,22 +122,7 @@ |
| 133 | 123 | bool hasHWnd;
|
| 134 | 124 | DIB dib;
|
| 135 | 125 | GLuint PBO;
|
| 136 | | - HANDLE busy;
|
| 137 | | - HANDLE start;
|
| 138 | | - HANDLE sync;
|
| 139 | | - bool running;
|
| 140 | | - CRITICAL_SECTION commandcs;
|
| 141 | | - CRITICAL_SECTION queuecs;
|
| 142 | | - LPDWORD queue;
|
| 143 | | - int queuesize;
|
| 144 | | - int queuelength;
|
| 145 | | - int queue_read;
|
| 146 | | - int queue_write;
|
| 147 | | - int syncsize;
|
| 148 | | - bool dead;
|
| 149 | | - DWORD renderstate[153];
|
| 150 | | - D3DMATRIX matrices[24];
|
| 151 | | - bool normal_dirty;
|
| | 126 | + CRITICAL_SECTION cs;
|
| 152 | 127 | };
|
| 153 | 128 |
|
| 154 | 129 | #endif //_GLRENDERER_H |
| \ No newline at end of file |