load shader from resource

This commit is contained in:
Zack Buhman 2025-12-30 22:13:55 -06:00
parent 26eb97286d
commit 24c7faad4d
5 changed files with 58 additions and 26 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
*.manifest
*.idb
*.obj
*.res

View File

@ -1,8 +1,15 @@
fxc /Od /Zi /T fx_4_0 /nologo /Fo main.fxo main.fx
rem build main resource
rc.exe /d "_UNICODE" /d "UNICODE" /fo"Debug\main.res" ".\main.rc"
rem compile
cl.exe @"compile.rsp" "main.cpp"
link.exe @"link.rsp" /OUT:"Debug\d3d10.exe" /PDB:"Debug\d3d10.pdb" ".\Debug\main.obj" /NOLOGO /ERRORREPORT:PROMPT
rem link
link.exe @"link.rsp" /NOLOGO /ERRORREPORT:PROMPT
fxc /Od /Zi /T fx_4_0 /nologo /Fo main.fxo main.fx
mt.exe -manifest d3d10.exe.manifest -outputresource:Debug\d3d10.exe;1
@if %errorlevel% neq 0 exit /b %errorlevel%

View File

@ -1,7 +1,10 @@
/INCREMENTAL
/DEBUG
/SUBSYSTEM:WINDOWS
/MANIFEST:NO
/MACHINE:X86
/OUT:"Debug\d3d10.exe"
/PDB:"Debug\d3d10.pdb"
d3d10.lib
d3dx10.lib
kernel32.lib
@ -16,5 +19,5 @@ oleaut32.lib
uuid.lib
odbc32.lib
odbccp32.lib
".\Debug\main.obj"
".\Debug\main.res"

View File

@ -65,6 +65,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
if (FAILED(InitDirect3DDevice())) {
print("InitDirect3DDevice\n");
system("pause");
return 0;
}
@ -78,6 +79,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
}
}
system("pause");
return 0;
}
@ -159,19 +161,33 @@ HRESULT InitDirect3DDevice()
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
D3D10_DRIVER_TYPE driverTypes[] = {
D3D10_DRIVER_TYPE_HARDWARE,
D3D10_DRIVER_TYPE_REFERENCE,
};
UINT numDriverTypes = (sizeof (driverTypes)) / (sizeof (driverTypes[0]));
HRESULT hr;
hr = D3D10CreateDeviceAndSwapChain(NULL,
D3D10_DRIVER_TYPE_REFERENCE,
NULL,
D3D10_CREATE_DEVICE_DEBUG,
D3D10_SDK_VERSION,
&sd,
&g_pSwapChain,
&g_pd3dDevice);
D3D10_DRIVER_TYPE driverType = D3D10_DRIVER_TYPE_NULL;
for (UINT i = 0; i < numDriverTypes; i++) {
driverType = driverTypes[i];
hr = D3D10CreateDeviceAndSwapChain(NULL,
driverType,
NULL,
0,
//D3D10_CREATE_DEVICE_DEBUG,
D3D10_SDK_VERSION,
&sd,
&g_pSwapChain,
&g_pd3dDevice);
if (SUCCEEDED(hr))
break;
}
if (FAILED(hr)) {
print("D3D10CreateDeviceAndSwapChain\n");
return hr;
}
print("driverType %d\n", driverType);
ID3D10Texture2D * pBackBuffer;
hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID *)&pBackBuffer);
@ -202,22 +218,26 @@ HRESULT InitDirect3DDevice()
ID3D10Blob * pBlobErrors = NULL;
DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_DEBUG;
hr = D3DX10CreateEffectFromFile(L"c:/Users/dot/d3d10/main.fx",
NULL,
NULL,
"fx_4_0",
dwShaderFlags,
0,
g_pd3dDevice,
NULL,
NULL,
&g_pEffect,
&pBlobErrors,
NULL);
hr = D3DX10CreateEffectFromResource(NULL,
L"RES_MAIN_FXO",
L"main.fxo",
NULL,
NULL,
"fx_4_0",
dwShaderFlags,
0,
g_pd3dDevice,
NULL,
NULL,
&g_pEffect,
&pBlobErrors,
NULL);
if (FAILED(hr)) {
print("D3DX10CreateEffectFromFile\n");
const char * pError = (const char *)pBlobErrors->GetBufferPointer();
(void)pError;
if (pBlobErrors != NULL) {
const char * pError = (const char *)pBlobErrors->GetBufferPointer();
print("pError: %p\n", pError);
}
return hr;
}

1
main.rc Normal file
View File

@ -0,0 +1 @@
RES_MAIN_FXO RCDATA "main.fxo"