DXGL r227 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r226‎ | r227 | r228 >
Date:21:07, 5 August 2012
Author:admin
Status:new
Tags:
Comment:
Enable texture stage operations.
Add missing "break"s
Add DXGL logo texture
Modified paths:
  • /dxgltest/Tests3D.cpp (modified) (history)

Diff [purge]

Index: dxgltest/Tests3D.cpp
@@ -862,8 +862,98 @@
863863 }
864864 }
865865
 866+HRESULT CALLBACK SelectTextureFormatCallback(LPDDPIXELFORMAT lpDDPixFmt, LPVOID lpContext)
 867+{
 868+ if(lpDDPixFmt->dwFlags & (DDPF_LUMINANCE|DDPF_BUMPLUMINANCE|DDPF_BUMPDUDV)) return D3DENUMRET_OK;
 869+ if(lpDDPixFmt->dwFourCC != 0) return D3DENUMRET_OK;
 870+ if(!(lpDDPixFmt->dwFlags & DDPF_ALPHAPIXELS)) return D3DENUMRET_OK;
 871+ if(lpDDPixFmt->dwRGBBitCount < 32) return D3DENUMRET_OK;
 872+ memcpy(lpContext,lpDDPixFmt,sizeof(DDPIXELFORMAT));
 873+ return D3DENUMRET_CANCEL;
 874+}
 875+
 876+void CreateSurfaceFromBitmap(MultiDirectDrawSurface **surface, DDSURFACEDESC2 *ddsd, HDC hdc, int width, int height)
 877+{
 878+ ddinterface->CreateSurface(ddsd,surface,NULL);
 879+ HDC surfacedc;
 880+ if(surface)
 881+ {
 882+ (*surface)->GetDC(&surfacedc);
 883+ BitBlt(surfacedc,0,0,width,height,hdc,0,0,SRCCOPY);
 884+ (*surface)->ReleaseDC(surfacedc);
 885+ }
 886+}
 887+
866888 void SelectTexture(MultiDirectDrawSurface **surface, int type, DWORD colorkey, LPCTSTR file)
867889 {
 890+ DDSURFACEDESC2 ddsd;
 891+ ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
 892+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 893+ BITMAPV4HEADER bi;
 894+ HBITMAP bitmap;
 895+ HDC hdc;
 896+ HDC hmemdc;
 897+ HBITMAP holdbmp;
 898+ HICON icon;
 899+ VOID *bmpbits;
 900+ ZeroMemory(&bi,sizeof(BITMAPV4HEADER));
 901+ bi.bV4Size = sizeof(BITMAPV4HEADER);
 902+ bi.bV4Planes = 1;
 903+ bi.bV4BitCount = 32;
 904+ bi.bV4V4Compression = BI_BITFIELDS;
 905+ bi.bV4RedMask = 0x00FF0000;
 906+ bi.bV4GreenMask = 0x0000FF00;
 907+ bi.bV4BlueMask = 0x000000FF;
 908+ bi.bV4AlphaMask = 0xFF000000;
 909+ d3d7dev->EnumTextureFormats(SelectTextureFormatCallback,&ddsd.ddpfPixelFormat);
 910+ ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
 911+ ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT|DDSD_TEXTURESTAGE;
 912+ if(*surface)
 913+ {
 914+ d3d7dev->SetTexture(texshaderstate.currentstage,NULL);
 915+ (*surface)->Release();
 916+ *surface = NULL;
 917+ }
 918+ switch(type)
 919+ {
 920+ case 0:
 921+ default:
 922+ break;
 923+ case 1:
 924+ break;
 925+ case 2:
 926+ hdc = GetDC(NULL);
 927+ bi.bV4Width = ddsd.dwWidth = bi.bV4Height = ddsd.dwHeight = 16;
 928+ bitmap = CreateDIBSection(hdc,(BITMAPINFO*)&bi,DIB_RGB_COLORS,&bmpbits,NULL,0);
 929+ hmemdc = CreateCompatibleDC(hdc);
 930+ ReleaseDC(NULL,hdc);
 931+ holdbmp = (HBITMAP)SelectObject(hmemdc,bitmap);
 932+ icon = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_DXGL),IMAGE_ICON,16,16,0);
 933+ DrawIconEx(hmemdc,0,0,icon,16,16,0,NULL,DI_NORMAL);
 934+ CreateSurfaceFromBitmap(surface,&ddsd,hmemdc,16,16);
 935+ SelectObject(hmemdc,holdbmp);
 936+ DeleteDC(hmemdc);
 937+ DeleteObject(bitmap);
 938+ if(*surface) d3d7dev->SetTexture(texshaderstate.currentstage,(LPDIRECTDRAWSURFACE7)(*surface)->GetSurface());
 939+ break;
 940+ case 3:
 941+ hdc = GetDC(NULL);
 942+ bi.bV4Width = ddsd.dwWidth = bi.bV4Height = ddsd.dwHeight = 256;
 943+ bitmap = CreateDIBSection(hdc,(BITMAPINFO*)&bi,DIB_RGB_COLORS,&bmpbits,NULL,0);
 944+ hmemdc = CreateCompatibleDC(hdc);
 945+ ReleaseDC(NULL,hdc);
 946+ holdbmp = (HBITMAP)SelectObject(hmemdc,bitmap);
 947+ icon = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_DXGL),IMAGE_ICON,256,256,0);
 948+ DrawIconEx(hmemdc,0,0,icon,256,256,0,NULL,DI_NORMAL);
 949+ CreateSurfaceFromBitmap(surface,&ddsd,hmemdc,256,256);
 950+ SelectObject(hmemdc,holdbmp);
 951+ DeleteDC(hmemdc);
 952+ DeleteObject(bitmap);
 953+ if(*surface) d3d7dev->SetTexture(texshaderstate.currentstage,(LPDIRECTDRAWSURFACE7)(*surface)->GetSurface());
 954+ break;
 955+ case 4:
 956+ break;
 957+ }
868958 }
869959
870960 void SetShaderArg(HWND hWnd, UINT dropdown, UINT checkalpha, UINT checkinv, DWORD *texarg)
@@ -1020,6 +1110,7 @@
10211111 SendDlgItemMessage(hWnd,IDC_COLOROP,CB_SETCURSEL,texshaderstate.texstages[number].colorop-1,0);
10221112 SendDlgItemMessage(hWnd,IDC_ALPHAOP,CB_SETCURSEL,texshaderstate.texstages[number].alphaop-1,0);
10231113 }
 1114+ break;
10241115 case IDC_TEXTURE:
10251116 if(HIWORD(wParam) == CBN_SELCHANGE)
10261117 {
@@ -1029,6 +1120,7 @@
10301121 SelectTexture(&texshaderstate.texstages[number].texture,texshaderstate.texstages[number].texturetype,
10311122 texshaderstate.texstages[number].colorkey,texshaderstate.texstages[number].texturefile);
10321123 }
 1124+ break;
10331125 case IDC_TEXTUREFILE:
10341126 if(HIWORD(wParam) == EN_KILLFOCUS)
10351127 {
@@ -1038,6 +1130,7 @@
10391131 SelectTexture(&texshaderstate.texstages[number].texture,texshaderstate.texstages[number].texturetype,
10401132 texshaderstate.texstages[number].colorkey,texshaderstate.texstages[number].texturefile);
10411133 }
 1134+ break;
10421135 case IDC_CARG1:
10431136 if(HIWORD(wParam) == CBN_SELCHANGE)
10441137 {
@@ -1045,6 +1138,7 @@
10461139 SetShaderArg(hWnd,IDC_CARG1,IDC_CARG1A,IDC_CARG1INV,&texshaderstate.texstages[number].colorarg1);
10471140 d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG1,texshaderstate.texstages[number].colorarg1);
10481141 }
 1142+ break;
10491143 case IDC_CARG1A:
10501144 case IDC_CARG1INV:
10511145 if(HIWORD(wParam) == BN_CLICKED)
@@ -1053,6 +1147,7 @@
10541148 SetShaderArg(hWnd,IDC_CARG1,IDC_CARG1A,IDC_CARG1INV,&texshaderstate.texstages[number].colorarg2);
10551149 d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG1,texshaderstate.texstages[number].colorarg2);
10561150 }
 1151+ break;
10571152 case IDC_CARG2:
10581153 if(HIWORD(wParam) == CBN_SELCHANGE)
10591154 {
@@ -1060,6 +1155,7 @@
10611156 SetShaderArg(hWnd,IDC_CARG2,IDC_CARG2A,IDC_CARG2INV,&texshaderstate.texstages[number].colorarg2);
10621157 d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG2,texshaderstate.texstages[number].colorarg2);
10631158 }
 1159+ break;
10641160 case IDC_CARG2A:
10651161 case IDC_CARG2INV:
10661162 if(HIWORD(wParam) == BN_CLICKED)
@@ -1068,6 +1164,7 @@
10691165 SetShaderArg(hWnd,IDC_CARG2,IDC_CARG2A,IDC_CARG2INV,&texshaderstate.texstages[number].colorarg1);
10701166 d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG2,texshaderstate.texstages[number].colorarg1);
10711167 }
 1168+ break;
10721169 case IDC_AARG1:
10731170 if(HIWORD(wParam) == CBN_SELCHANGE)
10741171 {
@@ -1075,6 +1172,7 @@
10761173 SetShaderArg(hWnd,IDC_AARG1,IDC_AARG1A,IDC_AARG1INV,&texshaderstate.texstages[number].alphaarg1);
10771174 d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG1,texshaderstate.texstages[number].alphaarg1);
10781175 }
 1176+ break;
10791177 case IDC_AARG1A:
10801178 case IDC_AARG1INV:
10811179 if(HIWORD(wParam) == BN_CLICKED)
@@ -1083,6 +1181,7 @@
10841182 SetShaderArg(hWnd,IDC_AARG1,IDC_AARG1A,IDC_AARG1INV,&texshaderstate.texstages[number].alphaarg1);
10851183 d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG1,texshaderstate.texstages[number].alphaarg1);
10861184 }
 1185+ break;
10871186 case IDC_AARG2:
10881187 if(HIWORD(wParam) == CBN_SELCHANGE)
10891188 {
@@ -1090,6 +1189,7 @@
10911190 SetShaderArg(hWnd,IDC_AARG2,IDC_AARG2A,IDC_AARG2INV,&texshaderstate.texstages[number].alphaarg2);
10921191 d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG2,texshaderstate.texstages[number].alphaarg2);
10931192 }
 1193+ break;
10941194 case IDC_AARG2A:
10951195 case IDC_AARG2INV:
10961196 if(HIWORD(wParam) == BN_CLICKED)
@@ -1098,8 +1198,24 @@
10991199 SetShaderArg(hWnd,IDC_AARG2,IDC_AARG2A,IDC_AARG2INV,&texshaderstate.texstages[number].alphaarg2);
11001200 d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG2,texshaderstate.texstages[number].alphaarg2);
11011201 }
 1202+ break;
11021203 }
 1204+ case IDC_COLOROP:
 1205+ if(HIWORD(wParam) == CBN_SELCHANGE)
 1206+ {
 1207+ number = texshaderstate.currentstage;
 1208+ texshaderstate.texstages[number].colorop = (D3DTEXTUREOP)(SendDlgItemMessage(hWnd,IDC_COLOROP,CB_GETCURSEL,0,0)+1);
 1209+ d3d7dev->SetTextureStageState(number,D3DTSS_COLOROP,texshaderstate.texstages[number].colorop);
 1210+ }
11031211 break;
 1212+ case IDC_ALPHAOP:
 1213+ if(HIWORD(wParam) == CBN_SELCHANGE)
 1214+ {
 1215+ number = texshaderstate.currentstage;
 1216+ texshaderstate.texstages[number].alphaop = (D3DTEXTUREOP)(SendDlgItemMessage(hWnd,IDC_ALPHAOP,CB_GETCURSEL,0,0)+1);
 1217+ d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAOP,texshaderstate.texstages[number].alphaop);
 1218+ }
 1219+ break;
11041220 case WM_CLOSE:
11051221 ddinterface->Release();
11061222 EndDialog(hWnd,IDCANCEL);