DXGL r881 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r880‎ | r881 | r882 >
Date:20:09, 8 December 2018
Author:admin
Status:new
Tags:
Comment:
Partially implement RGBA8332 surface uploads.
Disable OpenGL DSA on buffer objects as it appears to cause OpenGL errors as implemented.
Change default DXGL Test bit depth to 32.
Modified paths:
  • /ddraw/BufferObject.cpp (modified) (history)
  • /ddraw/glTexture.cpp (modified) (history)
  • /ddraw/struct.h (modified) (history)
  • /dxglcfg/dxgltest.cpp (modified) (history)
  • /dxglcfg/surfacegen.cpp (modified) (history)

Diff [purge]

Index: ddraw/BufferObject.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2015 William Feely
 3+// Copyright (C) 2015-2018 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -7,7 +7,7 @@
88 // version 2.1 of the License, or (at your option) any later version.
99
1010 // This library is distributed in the hope that it will be useful,
11 -// but WITHOUT ANY W ARRANTY; without even the implied warranty of
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
1212 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1313 // Lesser General Public License for more details.
1414
@@ -33,6 +33,7 @@
3434 buffer->refcount = 1;
3535 buffer->ext = ext;
3636 buffer->util = util;
 37+ buffer->size = 0;
3738 glUtil_AddRef(util);
3839 ext->glGenBuffers(1, &buffer->buffer);
3940 *out = buffer;
@@ -56,7 +57,7 @@
5758
5859 void BufferObject_SetData(BufferObject *This, GLenum target, GLsizeiptr size, GLvoid *data, GLenum usage)
5960 {
60 - if (This->ext->GLEXT_ARB_direct_state_access)
 61+ /*if (This->ext->GLEXT_ARB_direct_state_access)
6162 {
6263 This->ext->glNamedBufferData(This->buffer, size, data, usage);
6364 }
@@ -65,11 +66,11 @@
6667 This->ext->glNamedBufferDataEXT(This->buffer, size, data, usage);
6768 }
6869 else
69 - {
 70+ {*/
7071 glUtil_BindBuffer(This->util, This, target);
7172 This->ext->glBufferData(target, size, data, usage);
7273 glUtil_UndoBindBuffer(This->util, target);
73 - }
 74+ /*}*/
7475 }
7576
7677 void BufferObject_Bind(BufferObject *This, GLenum target)
@@ -84,7 +85,7 @@
8586 void *BufferObject_Map(BufferObject *This, GLenum target, GLenum access)
8687 {
8788 void *ptr;
88 - if (This->ext->GLEXT_ARB_direct_state_access)
 89+ /*if (This->ext->GLEXT_ARB_direct_state_access)
8990 {
9091 ptr = This->ext->glMapNamedBuffer(This->buffer, access);
9192 }
@@ -93,17 +94,17 @@
9495 ptr = This->ext->glMapNamedBufferEXT(This->buffer, access);
9596 }
9697 else
97 - {
 98+ {*/
9899 glUtil_BindBuffer(This->util, This, target);
99100 ptr = This->ext->glMapBuffer(target, access);
100101 glUtil_UndoBindBuffer(This->util, target);
101 - }
 102+ /*}*/
102103 return ptr;
103104 }
104105 GLboolean BufferObject_Unmap(BufferObject *This, GLenum target)
105106 {
106107 GLboolean ret;
107 - if (This->ext->GLEXT_ARB_direct_state_access)
 108+ /*if (This->ext->GLEXT_ARB_direct_state_access)
108109 {
109110 ret = This->ext->glUnmapNamedBuffer(This->buffer);
110111 }
@@ -112,11 +113,11 @@
113114 ret = This->ext->glUnmapNamedBufferEXT(This->buffer);
114115 }
115116 else
116 - {
 117+ {*/
117118 glUtil_BindBuffer(This->util, This, target);
118119 ret = This->ext->glUnmapBuffer(target);
119120 glUtil_UndoBindBuffer(This->util, target);
120 - }
 121+ /*}*/
121122 return ret;
122123 }
123124
Index: ddraw/glTexture.cpp
@@ -137,6 +137,8 @@
138138 ZeroMemory(newtexture, sizeof(glTexture));
139139 memcpy(&newtexture->levels[0].ddsd, ddsd, sizeof(DDSURFACEDESC2));
140140 newtexture->useconv = FALSE;
 141+ newtexture->pboPack = NULL;
 142+ newtexture->pboUnpack = NULL;
141143 if (bigwidth)
142144 {
143145 newtexture->bigwidth = bigwidth;
@@ -425,9 +427,13 @@
426428 int bpp = This->levels[level].ddsd.ddpfPixelFormat.dwRGBBitCount;
427429 int x = This->levels[level].ddsd.dwWidth;
428430 int y = This->levels[level].ddsd.dwHeight;
 431+ int i;
429432 int bigpitch = NextMultipleOf4((bpp / 8)*This->bigwidth);
430433 int pitch = This->levels[level].ddsd.lPitch;
431434 int bigx, bigy;
 435+ int inpitch, outpitch;
 436+ GLenum error;
 437+ char *readbuffer;
432438 if (level)
433439 {
434440 bigx = This->levels[level].ddsd.dwWidth;
@@ -438,46 +444,83 @@
439445 bigx = This->bigwidth;
440446 bigy = This->bigheight;
441447 }
442 - if ((bigx == x && bigy == y) || !This->levels[level].bigbuffer)
 448+ if (This->useconv)
443449 {
 450+ if ((bigx == x && bigy == y) || !This->levels[level].bigbuffer)
 451+ {
 452+ if (!This->pboPack)
 453+ BufferObject_Create(&This->pboPack, This->renderer->ext, This->renderer->util);
 454+ }
 455+ else return; // Non-primary surfaces should not have scaling
 456+ inpitch = NextMultipleOf4(This->levels[level].ddsd.dwWidth * This->internalsize);
 457+ outpitch = NextMultipleOf4(This->levels[level].ddsd.dwHeight
 458+ * (NextMultipleOf8(This->levels[level].ddsd.ddpfPixelFormat.dwRGBBitCount)/8));
 459+ if (This->pboPack->size < inpitch * This->levels[level].ddsd.dwHeight)
 460+ BufferObject_SetData(This->pboPack, GL_PIXEL_PACK_BUFFER,
 461+ inpitch * This->levels[level].ddsd.dwHeight, NULL, GL_DYNAMIC_READ);
 462+ BufferObject_Bind(This->pboPack, GL_PIXEL_PACK_BUFFER);
444463 if (This->renderer->ext->GLEXT_EXT_direct_state_access)
445 - This->renderer->ext->glGetTextureImageEXT(This->id, GL_TEXTURE_2D, level, This->format, This->type, This->levels[level].buffer);
 464+ This->renderer->ext->glGetTextureImageEXT(This->id, GL_TEXTURE_2D, level, This->format, This->type, 0);
446465 else
447466 {
448467 glUtil_SetActiveTexture(This->renderer->util, 0);
449468 glUtil_SetTexture(This->renderer->util, 0, This);
450 - glGetTexImage(GL_TEXTURE_2D, level, This->format, This->type, This->levels[level].buffer);
 469+ glGetTexImage(GL_TEXTURE_2D, level, This->format, This->type, 0);
451470 }
 471+ BufferObject_Unbind(This->pboPack, GL_PIXEL_PACK_BUFFER);
 472+ readbuffer = (char*)BufferObject_Map(This->pboPack, GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
 473+ error = glGetError();
 474+ if (error == GL_NO_ERROR)
 475+ {
 476+ for (i = 0; i < This->levels[level].ddsd.dwHeight; i++)
 477+ colorconvproc[This->convfunctiondownload](This->levels[level].ddsd.dwWidth,
 478+ This->levels[level].buffer + (i*outpitch), readbuffer + (i + inpitch));
 479+ }
 480+ BufferObject_Unmap(This->pboPack, GL_PIXEL_PACK_BUFFER);
452481 }
453482 else
454483 {
455 - if (This->renderer->ext->GLEXT_EXT_direct_state_access)
456 - This->renderer->ext->glGetTextureImageEXT(This->id, GL_TEXTURE_2D, level, This->format, This->type, This->levels[level].bigbuffer);
457 - else
 484+ if ((bigx == x && bigy == y) || !This->levels[level].bigbuffer)
458485 {
459 - glUtil_SetActiveTexture(This->renderer->util, 0);
460 - glUtil_SetTexture(This->renderer->util, 0, This);
461 - glGetTexImage(GL_TEXTURE_2D, level, This->format, This->type, This->levels[level].bigbuffer);
 486+ if (This->renderer->ext->GLEXT_EXT_direct_state_access)
 487+ This->renderer->ext->glGetTextureImageEXT(This->id, GL_TEXTURE_2D, level, This->format, This->type, This->levels[level].buffer);
 488+ else
 489+ {
 490+ glUtil_SetActiveTexture(This->renderer->util, 0);
 491+ glUtil_SetTexture(This->renderer->util, 0, This);
 492+ glGetTexImage(GL_TEXTURE_2D, level, This->format, This->type, This->levels[level].buffer);
 493+ }
462494 }
463 - switch (bpp)
 495+ else
464496 {
465 - case 8:
466 - ScaleNearest8(This->levels[level].buffer, This->levels[level].bigbuffer,
467 - x, y, bigx, bigy, bigpitch, pitch);
468 - break;
469 - case 15:
470 - case 16:
471 - ScaleNearest16(This->levels[level].buffer, This->levels[level].bigbuffer,
472 - x, y, bigx, bigy, bigpitch / 2, pitch / 2);
473 - break;
474 - case 24:
475 - ScaleNearest24(This->levels[level].buffer, This->levels[level].bigbuffer,
476 - x, y, bigx, bigy, bigpitch, pitch);
477 - break;
478 - case 32:
479 - ScaleNearest32(This->levels[level].buffer, This->levels[level].bigbuffer,
480 - x, y, bigx, bigy, bigpitch / 4, pitch / 4);
481 - break;
 497+ if (This->renderer->ext->GLEXT_EXT_direct_state_access)
 498+ This->renderer->ext->glGetTextureImageEXT(This->id, GL_TEXTURE_2D, level, This->format, This->type, This->levels[level].bigbuffer);
 499+ else
 500+ {
 501+ glUtil_SetActiveTexture(This->renderer->util, 0);
 502+ glUtil_SetTexture(This->renderer->util, 0, This);
 503+ glGetTexImage(GL_TEXTURE_2D, level, This->format, This->type, This->levels[level].bigbuffer);
 504+ }
 505+ switch (bpp)
 506+ {
 507+ case 8:
 508+ ScaleNearest8(This->levels[level].buffer, This->levels[level].bigbuffer,
 509+ x, y, bigx, bigy, bigpitch, pitch);
 510+ break;
 511+ case 15:
 512+ case 16:
 513+ ScaleNearest16(This->levels[level].buffer, This->levels[level].bigbuffer,
 514+ x, y, bigx, bigy, bigpitch / 2, pitch / 2);
 515+ break;
 516+ case 24:
 517+ ScaleNearest24(This->levels[level].buffer, This->levels[level].bigbuffer,
 518+ x, y, bigx, bigy, bigpitch, pitch);
 519+ break;
 520+ case 32:
 521+ ScaleNearest32(This->levels[level].buffer, This->levels[level].bigbuffer,
 522+ x, y, bigx, bigy, bigpitch / 4, pitch / 4);
 523+ break;
 524+ }
482525 }
483526 }
484527 This->levels[level].dirty &= ~2;
@@ -487,6 +530,9 @@
488531 {
489532 GLenum error;
490533 void *data;
 534+ int inpitch, outpitch;
 535+ int i;
 536+ char *writebuffer;
491537 if (dorealloc)
492538 {
493539 This->levels[level].ddsd.dwWidth = width;
@@ -506,15 +552,79 @@
507553 (This->levels[level].ddsd.dwHeight != This->bigheight)))
508554 data = This->levels[level].bigbuffer;
509555 else data = This->levels[level].buffer;
510 - if (checkerror)
 556+ if (This->useconv)
511557 {
512 - do
 558+ if (!This->pboUnpack)
 559+ BufferObject_Create(&This->pboUnpack, This->renderer->ext, This->renderer->util);
 560+ outpitch = NextMultipleOf4(This->levels[level].ddsd.dwWidth * This->internalsize);
 561+ inpitch = NextMultipleOf4(This->levels[level].ddsd.dwHeight
 562+ * (NextMultipleOf8(This->levels[level].ddsd.ddpfPixelFormat.dwRGBBitCount) / 8));
 563+ if (This->pboUnpack->size < outpitch * This->levels[level].ddsd.dwHeight)
 564+ BufferObject_SetData(This->pboUnpack, GL_PIXEL_UNPACK_BUFFER,
 565+ outpitch * This->levels[level].ddsd.dwHeight, NULL, GL_DYNAMIC_DRAW);
 566+ writebuffer = (char*)BufferObject_Map(This->pboUnpack, GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
 567+ for (i = 0; i < This->levels[level].ddsd.dwHeight; i++)
 568+ colorconvproc[This->convfunctionupload](This->levels[level].ddsd.dwWidth,
 569+ writebuffer + (i*outpitch), This->levels[level].buffer + (i + inpitch));
 570+ BufferObject_Unmap(This->pboUnpack, GL_PIXEL_UNPACK_BUFFER);
 571+ BufferObject_Bind(This->pboUnpack, GL_PIXEL_UNPACK_BUFFER);
 572+ if (This->renderer->ext->GLEXT_EXT_direct_state_access)
513573 {
514 - ClearError();
 574+ /*if (dorealloc)This->renderer->ext->glTextureImage2DEXT(This->id, GL_TEXTURE_2D, level, This->internalformats[0],
 575+ width, height, 0, This->format, This->type, data);
 576+ else */This->renderer->ext->glTextureSubImage2DEXT(This->id, GL_TEXTURE_2D, level,
 577+ 0, 0, width, height, This->format, This->type, 0);
 578+ }
 579+ else
 580+ {
 581+ glUtil_SetActiveTexture(util, 0);
 582+ glUtil_SetTexture(util, 0, This);
 583+ /*if (dorealloc)glTexImage2D(GL_TEXTURE_2D, level, This->internalformats[0], width, height, 0, This->format, This->type, data);
 584+ else */glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, This->format, This->type, 0);
 585+ }
 586+ BufferObject_Unbind(This->pboUnpack, GL_PIXEL_UNPACK_BUFFER);
 587+ }
 588+ else
 589+ {
 590+ if (checkerror)
 591+ {
 592+ do
 593+ {
 594+ ClearError();
 595+ if (This->renderer->ext->GLEXT_EXT_direct_state_access)
 596+ {
 597+ if (dorealloc)This->renderer->ext->glTextureImage2DEXT(This->id, GL_TEXTURE_2D, level,
 598+ This->internalformats[0], width, height, 0, This->format, This->type, data);
 599+ else This->renderer->ext->glTextureSubImage2DEXT(This->id, GL_TEXTURE_2D, level,
 600+ 0, 0, width, height, This->format, This->type, data);
 601+ }
 602+ else
 603+ {
 604+ glUtil_SetActiveTexture(util, 0);
 605+ glUtil_SetTexture(util, 0, This);
 606+ if (dorealloc) glTexImage2D(GL_TEXTURE_2D, level, This->internalformats[0], width, height, 0, This->format, This->type, data);
 607+ else glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, This->format, This->type, data);
 608+ }
 609+ error = glGetError();
 610+ if (error != GL_NO_ERROR)
 611+ {
 612+ if (This->internalformats[1] == 0)
 613+ {
 614+ FIXME("Failed to update texture, cannot find internal format");
 615+ break;
 616+ }
 617+ memmove(&This->internalformats[0], &This->internalformats[1], 7 * sizeof(GLint));
 618+ This->internalformats[7] = 0;
 619+ }
 620+ else break;
 621+ } while (1);
 622+ }
 623+ else
 624+ {
515625 if (This->renderer->ext->GLEXT_EXT_direct_state_access)
516626 {
517 - if (dorealloc)This->renderer->ext->glTextureImage2DEXT(This->id, GL_TEXTURE_2D, level,
518 - This->internalformats[0], width, height, 0, This->format, This->type, data);
 627+ if (dorealloc)This->renderer->ext->glTextureImage2DEXT(This->id, GL_TEXTURE_2D, level, This->internalformats[0],
 628+ width, height, 0, This->format, This->type, data);
519629 else This->renderer->ext->glTextureSubImage2DEXT(This->id, GL_TEXTURE_2D, level,
520630 0, 0, width, height, This->format, This->type, data);
521631 }
@@ -522,42 +632,10 @@
523633 {
524634 glUtil_SetActiveTexture(util, 0);
525635 glUtil_SetTexture(util, 0, This);
526 - if (dorealloc) glTexImage2D(GL_TEXTURE_2D, level, This->internalformats[0], width, height, 0, This->format, This->type, data);
 636+ if (dorealloc)glTexImage2D(GL_TEXTURE_2D, level, This->internalformats[0], width, height, 0, This->format, This->type, data);
527637 else glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, This->format, This->type, data);
528638 }
529 - error = glGetError();
530 - if (error != GL_NO_ERROR)
531 - {
532 - if (This->internalformats[1] == 0)
533 - {
534 - FIXME("Failed to update texture, cannot find internal format");
535 - break;
536 - }
537 - memmove(&This->internalformats[0], &This->internalformats[1], 7 * sizeof(GLint));
538 - This->internalformats[7] = 0;
539 - }
540 - else break;
541 - } while (1);
542 - }
543 - else
544 - {
545 - if (This->renderer->ext->GLEXT_EXT_direct_state_access)
546 - {
547 - if (dorealloc)This->renderer->ext->glTextureImage2DEXT(This->id, GL_TEXTURE_2D, level, This->internalformats[0],
548 - width, height, 0, This->format, This->type, data);
549 - else This->renderer->ext->glTextureSubImage2DEXT(This->id, GL_TEXTURE_2D, level,
550 - 0, 0, width, height, This->format, This->type, data);
551639 }
552 - else
553 - {
554 -
555 - }
556 - {
557 - glUtil_SetActiveTexture(util, 0);
558 - glUtil_SetTexture(util, 0, This);
559 - if (dorealloc)glTexImage2D(GL_TEXTURE_2D, level, This->internalformats[0], width, height, 0, This->format, This->type, data);
560 - else glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, width, height, This->format, This->type, data);
561 - }
562640 }
563641 This->levels[level].dirty &= ~1;
564642 }
@@ -820,7 +898,9 @@
821899 This->useconv = TRUE;
822900 This->convfunctionupload = 0;
823901 This->convfunctiondownload = 1;
 902+ This->internalsize = 4; // Store in 8888 texture
824903 This->internalformats[0] = GL_RGBA8;
 904+ This->format = GL_BGRA;
825905 This->type = GL_UNSIGNED_BYTE;
826906 This->colororder = 1;
827907 This->colorsizes[0] = 7;
@@ -1049,7 +1129,7 @@
10501130 {
10511131 if (This->internalformats[1] == 0)
10521132 {
1053 - FIXME("Failed to create texture, cannot find internal format");
 1133+ FIXME("Failed to create texture, cannot find internal format\n");
10541134 break;
10551135 }
10561136 memmove(&This->internalformats[0], &This->internalformats[1], 7 * sizeof(GLint));
@@ -1068,6 +1148,8 @@
10691149 {
10701150 glRenderer__RemoveTextureFromD3D(This->renderer, This);
10711151 glDeleteTextures(1, &This->id);
 1152+ if (This->pboPack) BufferObject_Release(This->pboPack);
 1153+ if (This->pboUnpack) BufferObject_Release(This->pboUnpack);
10721154 free(This);
10731155 }
10741156
Index: ddraw/struct.h
@@ -314,10 +314,13 @@
315315 BOOL useconv;
316316 int convfunctionupload;
317317 int convfunctiondownload;
 318+ int internalsize;
318319 struct glTexture *palette;
319320 struct glTexture *stencil;
320321 struct glTexture *dummycolor;
321322 struct glRenderer *renderer;
 323+ BufferObject *pboPack;
 324+ BufferObject *pboUnpack;
322325 } glTexture;
323326
324327 // Color orders:
Index: dxglcfg/dxgltest.cpp
@@ -254,7 +254,7 @@
255255 error = DirectDrawCreate(NULL, &lpdd, NULL);
256256 if (error == DD_OK)
257257 {
258 - error = lpdd->EnumDisplayModes(DDEDM_REFRESHRATES, NULL, GetDlgItem(hWnd, IDC_VIDMODES), EnumModesCallback8);
 258+ error = lpdd->EnumDisplayModes(DDEDM_REFRESHRATES, NULL, GetDlgItem(hWnd, IDC_VIDMODES), EnumModesCallback32);
259259 IDirectDraw_Release(lpdd);
260260 }
261261 SendDlgItemMessage(hWnd, IDC_VIDMODES, LB_SETCURSEL, modenum, 0);
@@ -278,7 +278,7 @@
279279 error = DirectDrawCreate(NULL,&lpdd,NULL);
280280 if(error == DD_OK)
281281 {
282 - error = lpdd->EnumDisplayModes(DDEDM_REFRESHRATES,NULL,GetDlgItem(hWnd,IDC_VIDMODES),EnumModesCallback8);
 282+ error = lpdd->EnumDisplayModes(DDEDM_REFRESHRATES,NULL,GetDlgItem(hWnd,IDC_VIDMODES),EnumModesCallback32);
283283 IDirectDraw_Release(lpdd);
284284 }
285285 SendDlgItemMessage(hWnd,IDC_VIDMODES,LB_SETCURSEL,modenum,0);
Index: dxglcfg/surfacegen.cpp
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2013 William Feely
 3+// Copyright (C) 2011-2018 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -244,6 +244,17 @@
245245 }
246246 }
247247 }
 248+ else if ((ddsd.ddpfPixelFormat.dwRBitMask | ddsd.ddpfPixelFormat.dwGBitMask |
 249+ ddsd.ddpfPixelFormat.dwBBitMask) == 0xFF)
 250+ {
 251+ for (y = 0; y < ddsd.dwHeight; y++)
 252+ {
 253+ for (x = 0; x < ddsd.dwWidth; x++)
 254+ {
 255+ buffer16[x + ((ddsd.lPitch/2)*y)] = (unsigned short)((x / (ddsd.dwWidth / 16.)) + 16 * floor((y / (ddsd.dwHeight / 16.))));
 256+ }
 257+ }
 258+ }
248259 else
249260 {
250261 for(y = 0; y < ddsd.dwHeight; y++)