Index: dxgltest/Tests3D.cpp |
— | — | @@ -862,8 +862,98 @@ |
863 | 863 | }
|
864 | 864 | }
|
865 | 865 |
|
| 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 | +
|
866 | 888 | void SelectTexture(MultiDirectDrawSurface **surface, int type, DWORD colorkey, LPCTSTR file)
|
867 | 889 | {
|
| 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 | + }
|
868 | 958 | }
|
869 | 959 |
|
870 | 960 | void SetShaderArg(HWND hWnd, UINT dropdown, UINT checkalpha, UINT checkinv, DWORD *texarg)
|
— | — | @@ -1020,6 +1110,7 @@ |
1021 | 1111 | SendDlgItemMessage(hWnd,IDC_COLOROP,CB_SETCURSEL,texshaderstate.texstages[number].colorop-1,0);
|
1022 | 1112 | SendDlgItemMessage(hWnd,IDC_ALPHAOP,CB_SETCURSEL,texshaderstate.texstages[number].alphaop-1,0);
|
1023 | 1113 | }
|
| 1114 | + break;
|
1024 | 1115 | case IDC_TEXTURE:
|
1025 | 1116 | if(HIWORD(wParam) == CBN_SELCHANGE)
|
1026 | 1117 | {
|
— | — | @@ -1029,6 +1120,7 @@ |
1030 | 1121 | SelectTexture(&texshaderstate.texstages[number].texture,texshaderstate.texstages[number].texturetype,
|
1031 | 1122 | texshaderstate.texstages[number].colorkey,texshaderstate.texstages[number].texturefile);
|
1032 | 1123 | }
|
| 1124 | + break;
|
1033 | 1125 | case IDC_TEXTUREFILE:
|
1034 | 1126 | if(HIWORD(wParam) == EN_KILLFOCUS)
|
1035 | 1127 | {
|
— | — | @@ -1038,6 +1130,7 @@ |
1039 | 1131 | SelectTexture(&texshaderstate.texstages[number].texture,texshaderstate.texstages[number].texturetype,
|
1040 | 1132 | texshaderstate.texstages[number].colorkey,texshaderstate.texstages[number].texturefile);
|
1041 | 1133 | }
|
| 1134 | + break;
|
1042 | 1135 | case IDC_CARG1:
|
1043 | 1136 | if(HIWORD(wParam) == CBN_SELCHANGE)
|
1044 | 1137 | {
|
— | — | @@ -1045,6 +1138,7 @@ |
1046 | 1139 | SetShaderArg(hWnd,IDC_CARG1,IDC_CARG1A,IDC_CARG1INV,&texshaderstate.texstages[number].colorarg1);
|
1047 | 1140 | d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG1,texshaderstate.texstages[number].colorarg1);
|
1048 | 1141 | }
|
| 1142 | + break;
|
1049 | 1143 | case IDC_CARG1A:
|
1050 | 1144 | case IDC_CARG1INV:
|
1051 | 1145 | if(HIWORD(wParam) == BN_CLICKED)
|
— | — | @@ -1053,6 +1147,7 @@ |
1054 | 1148 | SetShaderArg(hWnd,IDC_CARG1,IDC_CARG1A,IDC_CARG1INV,&texshaderstate.texstages[number].colorarg2);
|
1055 | 1149 | d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG1,texshaderstate.texstages[number].colorarg2);
|
1056 | 1150 | }
|
| 1151 | + break;
|
1057 | 1152 | case IDC_CARG2:
|
1058 | 1153 | if(HIWORD(wParam) == CBN_SELCHANGE)
|
1059 | 1154 | {
|
— | — | @@ -1060,6 +1155,7 @@ |
1061 | 1156 | SetShaderArg(hWnd,IDC_CARG2,IDC_CARG2A,IDC_CARG2INV,&texshaderstate.texstages[number].colorarg2);
|
1062 | 1157 | d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG2,texshaderstate.texstages[number].colorarg2);
|
1063 | 1158 | }
|
| 1159 | + break;
|
1064 | 1160 | case IDC_CARG2A:
|
1065 | 1161 | case IDC_CARG2INV:
|
1066 | 1162 | if(HIWORD(wParam) == BN_CLICKED)
|
— | — | @@ -1068,6 +1164,7 @@ |
1069 | 1165 | SetShaderArg(hWnd,IDC_CARG2,IDC_CARG2A,IDC_CARG2INV,&texshaderstate.texstages[number].colorarg1);
|
1070 | 1166 | d3d7dev->SetTextureStageState(number,D3DTSS_COLORARG2,texshaderstate.texstages[number].colorarg1);
|
1071 | 1167 | }
|
| 1168 | + break;
|
1072 | 1169 | case IDC_AARG1:
|
1073 | 1170 | if(HIWORD(wParam) == CBN_SELCHANGE)
|
1074 | 1171 | {
|
— | — | @@ -1075,6 +1172,7 @@ |
1076 | 1173 | SetShaderArg(hWnd,IDC_AARG1,IDC_AARG1A,IDC_AARG1INV,&texshaderstate.texstages[number].alphaarg1);
|
1077 | 1174 | d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG1,texshaderstate.texstages[number].alphaarg1);
|
1078 | 1175 | }
|
| 1176 | + break;
|
1079 | 1177 | case IDC_AARG1A:
|
1080 | 1178 | case IDC_AARG1INV:
|
1081 | 1179 | if(HIWORD(wParam) == BN_CLICKED)
|
— | — | @@ -1083,6 +1181,7 @@ |
1084 | 1182 | SetShaderArg(hWnd,IDC_AARG1,IDC_AARG1A,IDC_AARG1INV,&texshaderstate.texstages[number].alphaarg1);
|
1085 | 1183 | d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG1,texshaderstate.texstages[number].alphaarg1);
|
1086 | 1184 | }
|
| 1185 | + break;
|
1087 | 1186 | case IDC_AARG2:
|
1088 | 1187 | if(HIWORD(wParam) == CBN_SELCHANGE)
|
1089 | 1188 | {
|
— | — | @@ -1090,6 +1189,7 @@ |
1091 | 1190 | SetShaderArg(hWnd,IDC_AARG2,IDC_AARG2A,IDC_AARG2INV,&texshaderstate.texstages[number].alphaarg2);
|
1092 | 1191 | d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG2,texshaderstate.texstages[number].alphaarg2);
|
1093 | 1192 | }
|
| 1193 | + break;
|
1094 | 1194 | case IDC_AARG2A:
|
1095 | 1195 | case IDC_AARG2INV:
|
1096 | 1196 | if(HIWORD(wParam) == BN_CLICKED)
|
— | — | @@ -1098,8 +1198,24 @@ |
1099 | 1199 | SetShaderArg(hWnd,IDC_AARG2,IDC_AARG2A,IDC_AARG2INV,&texshaderstate.texstages[number].alphaarg2);
|
1100 | 1200 | d3d7dev->SetTextureStageState(number,D3DTSS_ALPHAARG2,texshaderstate.texstages[number].alphaarg2);
|
1101 | 1201 | }
|
| 1202 | + break;
|
1102 | 1203 | }
|
| 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 | + }
|
1103 | 1211 | 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;
|
1104 | 1220 | case WM_CLOSE:
|
1105 | 1221 | ddinterface->Release();
|
1106 | 1222 | EndDialog(hWnd,IDCANCEL);
|