Skip to content

Commit

Permalink
Fixed alpha issue with HUD. Slots are now specified using names.
Browse files Browse the repository at this point in the history
I forgot to erase the HUD background on each frame. This was fixed; but
now the HUD was too transparent. I boosted the alpha value in the shader.

Source Elements and Regions can now be specified using names. Some basic
name validation was added.
  • Loading branch information
Leo Reyes authored and Leo Reyes committed Aug 10, 2019
1 parent f5c5dcb commit ba03aca
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 106 deletions.
107 changes: 52 additions & 55 deletions impl11/ddraw/DeviceResources.cpp
Expand Up @@ -190,60 +190,57 @@ struct MainVertex
}
};

/*
bool LoadNewCockpitTextures(ID3D11Device *device) {
if (!g_bDynCockpitEnabled) {
log_debug("[DBG] [Dyn] Dynamic Cockpit is disabled. Will not load new textures");
g_bNewCockpitTexturesLoaded = false;
goto out;
}
if (g_bNewCockpitTexturesLoaded) {
log_debug("[DBG} [Dyn] New textures for Dynamic Cockpit already loaded, skipping");
return true;
}
if (g_NewHUDLeftRadar == NULL) {
HRESULT res = DirectX::CreateWICTextureFromFile(device, L"./DynamicCockpit/Left-Radar-Round.png",
NULL, &g_NewHUDLeftRadar);
if (FAILED(res)) {
log_debug("[DBG] [Dyn] Failed to load new Left Radar texture: 0x%x", res);
g_NewHUDLeftRadar = NULL;
}
}
if (g_NewHUDRightRadar == NULL) {
HRESULT res = DirectX::CreateWICTextureFromFile(device, L"./DynamicCockpit/Right-Radar-Round.png",
NULL, &g_NewHUDRightRadar);
if (FAILED(res)) {
log_debug("[DBG] [Dyn] Failed to load new Right Radar texture: 0x%x", res);
g_NewHUDRightRadar = NULL;
}
}
g_bNewCockpitTexturesLoaded = (g_NewHUDLeftRadar != NULL && g_NewHUDRightRadar != NULL);
log_debug("[DBG} [Dyn] New cockpit textures loaded");
out:
return g_bNewCockpitTexturesLoaded;
std::vector<const char *>g_HUDRegionNames = {
"LEFT_SENSOR_REGION", // 0
"RIGHT_SENSOR_REGION", // 1
"SHIELDS_REGION", // 2
"BEAM_REGION", // 3
"TARGET_AND_LASERS_REGION", // 4
"LEFT_TEXT_BOX_REGION", // 5
"RIGHT_TEXT_BOX_REGION", // 6
"TOP_LEFT_REGION", // 7
"TOP_RIGHT_REGION" // 8
};
const int MAX_HUD_BOXES = (int )g_HUDRegionNames.size();

std::vector<const char *>g_DCElemSrcNames = {
"LEFT_SENSOR_SRC", // 0
"RIGHT_SENSOR_SRC", // 1
"LASER_RECHARGE_SRC", // 2
"SHIELD_RECHARGE_SRC", // 3
"ENGINE_POWER_SRC", // 4
"BEAM_RECHARGE_SRC", // 5
"SHIELDS_SRC", // 6
"BEAM_LEVEL_SRC" , // 7
"TARGETING_COMPUTER_SRC", // 8
"QUAD_LASERS_LEFT_SRC", // 9
"QUAD_LASERS_RIGHT_SRC", // 10
"LEFT_TEXT_BOX_SRC", // 11
"RIGHT_TEXT_BOX_SRC", // 12
"SPEED_THROTTLE_SRC", // 13
"MISSILES_SRC", // 14
"NAME_TIME_SRC", // 15
"NUM_SHIPS_SRC" // 16
};
const int MAX_DC_SRC_ELEMENTS = (int )g_DCElemSrcNames.size();

int HUDRegionNameToIndex(char *name) {
if (name == NULL || name[0] == '\0')
return -1;
for (int i = 0; i < (int )g_HUDRegionNames.size(); i++)
if (_stricmp(name, g_HUDRegionNames[i]) == 0)
return i;
return -1;
}

void UnloadNewCockpitTextures() {
if (!g_bDynCockpitEnabled || !g_bNewCockpitTexturesLoaded)
return;
log_debug("[DBG] [Dyn] >>>>> Releasing textures");
if (g_NewHUDLeftRadar != NULL) {
g_NewHUDLeftRadar.Release();
g_NewHUDLeftRadar = NULL;
}
if (g_NewHUDRightRadar != NULL) {
g_NewHUDRightRadar.Release();
g_NewHUDRightRadar = NULL;
}
g_bNewCockpitTexturesLoaded = false;
int DCSrcElemNameToIndex(char *name) {
if (name == NULL || name[0] == '\0')
return -1;
for (int i = 0; i < (int )g_DCElemSrcNames.size(); i++)
if (_stricmp(name, g_DCElemSrcNames[i]) == 0)
return i;
return -1;
}
*/

DeviceResources::DeviceResources()
{
Expand Down Expand Up @@ -559,7 +556,7 @@ HRESULT DeviceResources::OnSizeChanged(HWND hWnd, DWORD dwWidth, DWORD dwHeight)
this->_renderTargetViewDynCockpitAsInputBG.Release();
this->_offscreenBufferDynCockpit.Release();
this->_offscreenBufferDynCockpitBG.Release();
this->_offscreenBufferAsInputDynCockpit.Release();
this->_offscreenAsInputDynCockpit.Release();
this->_offscreenAsInputDynCockpitBG.Release();
this->_offscreenAsInputSRVDynCockpit.Release();
this->_offscreenAsInputSRVDynCockpitBG.Release();
Expand Down Expand Up @@ -890,7 +887,7 @@ HRESULT DeviceResources::OnSizeChanged(HWND hWnd, DWORD dwWidth, DWORD dwHeight)
log_err("Flags: 0x%x\n", desc.BindFlags);

step = "_offscreenBufferAsInputDynCockpit";
hr = this->_d3dDevice->CreateTexture2D(&desc, nullptr, &this->_offscreenBufferAsInputDynCockpit);
hr = this->_d3dDevice->CreateTexture2D(&desc, nullptr, &this->_offscreenAsInputDynCockpit);
if (FAILED(hr)) {
log_err("Failed to create _offscreenBufferAsInputDynCockpit, error: 0x%x\n", hr);
log_err("GetDeviceRemovedReason: 0x%x\n", this->_d3dDevice->GetDeviceRemovedReason());
Expand Down Expand Up @@ -980,7 +977,7 @@ HRESULT DeviceResources::OnSizeChanged(HWND hWnd, DWORD dwWidth, DWORD dwHeight)
if (g_bDynCockpitEnabled) {
// Create the SRSV for _offscreenBufferAsInputDynCockpit
step = "_offscreenBufferAsInputDynCockpit";
hr = this->_d3dDevice->CreateShaderResourceView(this->_offscreenBufferAsInputDynCockpit,
hr = this->_d3dDevice->CreateShaderResourceView(this->_offscreenAsInputDynCockpit,
&shaderResourceViewDesc, &this->_offscreenAsInputSRVDynCockpit);
if (FAILED(hr)) {
log_err("dwWidth, Height: %u, %u\n", dwWidth, dwHeight);
Expand Down Expand Up @@ -1044,7 +1041,7 @@ HRESULT DeviceResources::OnSizeChanged(HWND hWnd, DWORD dwWidth, DWORD dwHeight)
CD3D11_RENDER_TARGET_VIEW_DESC renderTargetViewDescNoMSAA(D3D11_RTV_DIMENSION_TEXTURE2D);
step = "_renderTargetViewDynCockpitAsInput";
// This RTV writes to a non-MSAA texture
hr = this->_d3dDevice->CreateRenderTargetView(this->_offscreenBufferAsInputDynCockpit, &renderTargetViewDescNoMSAA,
hr = this->_d3dDevice->CreateRenderTargetView(this->_offscreenAsInputDynCockpit, &renderTargetViewDescNoMSAA,
&this->_renderTargetViewDynCockpitAsInput);
if (FAILED(hr)) goto out;

Expand Down
12 changes: 9 additions & 3 deletions impl11/ddraw/DeviceResources.h
Expand Up @@ -37,7 +37,10 @@ const int LEFT_MSG_HUD_BOX_IDX = 5;
const int RIGHT_MSG_HUD_BOX_IDX = 6;
const int TOP_LEFT_BOX_IDX = 7;
const int TOP_RIGHT_BOX_IDX = 8;
const int MAX_HUD_BOXES = 9;
extern const int MAX_HUD_BOXES;
extern std::vector<const char *>g_HUDRegionNames;
// Convert a string into a *_HUD_BOX_IDX constant
int HUDRegionNameToIndex(char *name);

class DCHUDBox {
public:
Expand Down Expand Up @@ -85,7 +88,10 @@ const int SPEED_N_THROTTLE_DC_ELEM_SRC_IDX = 13;
const int MISSILES_DC_ELEM_SRC_IDX = 14;
const int NAME_TIME_DC_ELEM_SRC_IDX = 15;
const int NUM_CRAFTS_DC_ELEM_SRC_IDX = 16;
const int MAX_DC_SRC_ELEMENTS = 17;
extern const int MAX_DC_SRC_ELEMENTS;
extern std::vector<const char *>g_DCElemSrcNames;
// Convert a string into a *_DC_ELEM_SRC_IDX constant
int DCSrcElemNameToIndex(char *name);

class DCElemSrcBox {
public:
Expand Down Expand Up @@ -263,7 +269,7 @@ class DeviceResources
ComPtr<ID3D11Texture2D> _offscreenBufferDynCockpitBG; // Used to render the targeting computer dynamically <-- Need to re-check this claim
ComPtr<ID3D11Texture2D> _offscreenBufferAsInput;
ComPtr<ID3D11Texture2D> _offscreenBufferAsInputR; // When SteamVR is used, this is the right eye as input buffer
ComPtr<ID3D11Texture2D> _offscreenBufferAsInputDynCockpit; // HUD elements buffer
ComPtr<ID3D11Texture2D> _offscreenAsInputDynCockpit; // HUD elements buffer
ComPtr<ID3D11Texture2D> _offscreenAsInputDynCockpitBG; // HUD element backgrounds buffer
ComPtr<ID3D11Texture2D> _offscreenBufferAsInputReshade;
ComPtr<ID3D11Texture2D> _offscreenBufferPost; // This is the output of the barrel effect
Expand Down

0 comments on commit ba03aca

Please sign in to comment.