DXGL r395 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r394‎ | r395 | r396 >
Date:15:04, 20 July 2013
Author:admin
Status:new
Tags:
Comment:
Implement IDirectDrawClipper::SetClipList, does not yet render clippers.
Modified paths:
  • /ddraw/glClassFactory.cpp (modified) (history)
  • /ddraw/glDirectDrawClipper.cpp (modified) (history)
  • /ddraw/glDirectDrawClipper.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/glutil.h (modified) (history)

Diff [purge]

Index: ddraw/glClassFactory.cpp
@@ -18,6 +18,8 @@
1919 #include "common.h"
2020 #include "glClassFactory.h"
2121 #include "glDirectDraw.h"
 22+#include "texture.h"
 23+#include "glutil.h"
2224 #include "glDirectDrawClipper.h"
2325
2426 LONG locks;
Index: ddraw/glDirectDrawClipper.cpp
@@ -16,6 +16,8 @@
1717 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919 #include "common.h"
 20+#include "texture.h"
 21+#include "glutil.h"
2022 #include "glDirectDraw.h"
2123 #include "glDirectDrawClipper.h"
2224
@@ -38,6 +40,9 @@
3941 glDirectDrawClipper::~glDirectDrawClipper()
4042 {
4143 TRACE_ENTER(1,14,this);
 44+ if (cliplist) free(cliplist);
 45+ if (vertices) free(vertices);
 46+ if (indices) free(indices);
4247 if(glDD7) glDD7->DeleteClipper(this);
4348 TRACE_EXIT(-1,0);
4449 }
@@ -111,6 +116,11 @@
112117 if(glDD7) hasparent = true;
113118 else hasparent = false;
114119 hWnd = NULL;
 120+ cliplist = NULL;
 121+ vertices = NULL;
 122+ indices = NULL;
 123+ hascliplist = false;
 124+ maxsize = clipsize = 0;
115125 refcount = 1;
116126 initialized = true;
117127 TRACE_EXIT(23,DD_OK);
@@ -128,9 +138,82 @@
129139 {
130140 TRACE_ENTER(3,14,this,14,lpClipList,9,dwFlags);
131141 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
132 - FIXME("IDirectDrawClipper::SetClipList: stub");
133 - TRACE_EXIT(23,DDERR_GENERIC);
134 - ERR(DDERR_GENERIC);
 142+ if(hWnd) TRACE_RET(HRESULT,23,DDERR_CLIPPERISUSINGHWND);
 143+ bool memfail;
 144+ if(lpClipList)
 145+ {
 146+ if(lpClipList->rdh.dwSize != sizeof(RGNDATAHEADER)) TRACE_RET(HRESULT,23,DDERR_INVALIDCLIPLIST);
 147+ if(lpClipList->rdh.iType != RDH_RECTANGLES) TRACE_RET(HRESULT,23,DDERR_INVALIDCLIPLIST);
 148+ if(lpClipList->rdh.nRgnSize != lpClipList->rdh.nCount * sizeof(RECT))
 149+ TRACE_RET(HRESULT,23,DDERR_INVALIDCLIPLIST);
 150+ if(!cliplist)
 151+ {
 152+ memfail = false;
 153+ maxsize = lpClipList->rdh.nCount;
 154+ cliplist = (RECT*)malloc(maxsize*sizeof(RECT));
 155+ if(!cliplist) memfail = true;
 156+ if(!memfail) vertices = (BltVertex*)malloc(maxsize*4*sizeof(BltVertex));
 157+ if(!vertices) memfail = true;
 158+ if(!memfail) indices = (WORD*)malloc(maxsize*6*sizeof(WORD));
 159+ if(!indices) memfail = true;
 160+ if(memfail)
 161+ {
 162+ if(vertices)
 163+ {
 164+ free(vertices);
 165+ vertices = NULL;
 166+ }
 167+ if(cliplist)
 168+ {
 169+ free(cliplist);
 170+ cliplist = NULL;
 171+ }
 172+ maxsize = 0;
 173+ TRACE_RET(HRESULT,23,DDERR_OUTOFMEMORY);
 174+ }
 175+ }
 176+ if(lpClipList->rdh.nCount > maxsize)
 177+ {
 178+ memfail = false;
 179+ RECT *newcliplist = NULL;
 180+ BltVertex *newvertices = NULL;
 181+ WORD *newindices = NULL;
 182+ newcliplist = (RECT*)realloc(cliplist,lpClipList->rdh.nCount*sizeof(RECT));
 183+ if(!newcliplist) memfail = true;
 184+ else cliplist = newcliplist;
 185+ if(!memfail) newvertices = (BltVertex*)realloc(vertices,lpClipList->rdh.nCount*4*sizeof(BltVertex));
 186+ if(!newvertices) memfail = true;
 187+ else vertices = newvertices;
 188+ if(!memfail) newindices = (WORD*)realloc(indices,lpClipList->rdh.nCount*6*sizeof(WORD));
 189+ if(!newindices) memfail = true;
 190+ else indices = newindices;
 191+ if(memfail) TRACE_RET(HRESULT,23,DDERR_OUTOFMEMORY);
 192+ maxsize = lpClipList->rdh.nCount;
 193+ }
 194+ clipsize = lpClipList->rdh.nCount;
 195+ memcpy(cliplist,lpClipList->Buffer,lpClipList->rdh.nCount*sizeof(RECT));
 196+ for(int i = 0; i < lpClipList->rdh.nCount; i++)
 197+ {
 198+ vertices[(i*4)+1].y = vertices[(i*4)+3].y = cliplist[i].left;
 199+ vertices[i*4].x = vertices[(i*4)+2].x = cliplist[i].right;
 200+ vertices[i*4].y = vertices[(i*4)+1].y = cliplist[i].top;
 201+ vertices[(i*4)+2].y = vertices[(i*4)+3].y = cliplist[i].bottom;
 202+ // 0 1 2 2 1 3
 203+ indices[i*6] = i*4;
 204+ indices[(i*6)+1] = indices[(i*6)+4] = (i*4)+1;
 205+ indices[(i*6)+2] = indices[(i*6)+3] = (i*4)+2;
 206+ indices[(i*6)+5] = (i*4)+3;
 207+ }
 208+ for(int i = 0; i < (4*lpClipList->rdh.nCount); i++)
 209+ {
 210+ vertices[i].r = 255;
 211+ vertices[i].g = vertices[i].b = vertices[i].a = 0;
 212+ vertices[i].s = vertices[i].t = 0.0f;
 213+ }
 214+ }
 215+ else clipsize = 0;
 216+ TRACE_EXIT(23,DD_OK);
 217+ return DD_OK;
135218 }
136219 HRESULT WINAPI glDirectDrawClipper::SetHWnd(DWORD dwFlags, HWND hWnd)
137220 {
Index: ddraw/glDirectDrawClipper.h
@@ -43,5 +43,11 @@
4444 bool hasparent;
4545 bool initialized;
4646 HWND hWnd;
 47+ RECT *cliplist;
 48+ BltVertex *vertices;
 49+ WORD *indices;
 50+ int clipsize;
 51+ int maxsize;
 52+ bool hascliplist;
4753 };
4854 #endif //_GLDIRECTDRAWCLIPPER_H
\ No newline at end of file
Index: ddraw/glDirectDrawSurface.cpp
@@ -368,6 +368,7 @@
369369 if(bitmapinfo) free(bitmapinfo);
370370 if(palette) palette->Release();
371371 if(backbuffer) backbuffer->Release();
 372+ if(clipper) clipper->Release();
372373 if(buffer) free(buffer);
373374 if(bigbuffer) free(bigbuffer);
374375 if(zbuffer) zbuffer->Release();
Index: ddraw/glRenderer.cpp
@@ -34,9 +34,6 @@
3535 #include "shadergen.h"
3636 #include "matrix.h"
3737
38 -TEXTURE *backbuffer = NULL;
39 -int backx = 0;
40 -int backy = 0;
4138 BltVertex bltvertices[4];
4239 const GLushort bltindices[4] = {0,1,2,3};
4340
@@ -195,6 +192,8 @@
196193 */
197194 glRenderer::glRenderer(int width, int height, int bpp, bool fullscreen, unsigned int frequency, HWND hwnd, glDirectDraw7 *glDD7)
198195 {
 196+ backbuffer = NULL;
 197+ stenciltex = NULL;
199198 hDC = NULL;
200199 hRC = NULL;
201200 PBO = 0;
Index: ddraw/glRenderer.h
@@ -51,14 +51,6 @@
5252 int stride;
5353 } GLVERTEX;
5454
55 -typedef struct
56 -{
57 - GLfloat x,y;
58 - GLubyte r,g,b,a;
59 - GLfloat s,t;
60 - GLfloat padding[3];
61 -} BltVertex;
62 -
6355 extern BltVertex bltvertices[4];
6456
6557 #define OP_NULL 0
@@ -145,6 +137,12 @@
146138 HANDLE start;
147139 unsigned int frequency;
148140 DXGLTimer timer;
 141+ TEXTURE *backbuffer;
 142+ int backx;
 143+ int backy;
 144+ TEXTURE *stenciltex;
 145+ int stencilx;
 146+ int stencily;
149147 };
150148
151149 #endif //_GLRENDERER_H
\ No newline at end of file
Index: ddraw/glutil.h
@@ -28,6 +28,14 @@
2929 GLenum status;
3030 } FBO;
3131
 32+typedef struct
 33+{
 34+ GLfloat x, y;
 35+ GLubyte r, g, b, a;
 36+ GLfloat s, t;
 37+ GLfloat padding[3];
 38+} BltVertex;
 39+
3240 extern FBO *currentfbo;
3341 class glDirectDrawSurface7;
3442