Add 3d spinning DVD!

This commit is contained in:
Li 2023-03-20 22:39:23 +13:00
parent 83d91b6a73
commit a4b814fed8
24 changed files with 682 additions and 49 deletions

View File

@ -21,6 +21,8 @@
<ItemGroup>
<ClCompile Include="Dvd\DvdRipper.cpp" />
<ClCompile Include="Dvd\TitleKey.cpp" />
<ClCompile Include="Gui\DvdSpin\D3DSpin.cpp" />
<ClCompile Include="Gui\DvdSpin\RenderDvdSpin.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="Gui\D3D.cpp" />
<ClCompile Include="Gui\DumpDVD.cpp" />
@ -35,9 +37,14 @@
<ClInclude Include="Dvd\TitleKey.hpp" />
<ClInclude Include="Gui\D3D.hpp" />
<ClInclude Include="Gui\DumpDVD.hpp" />
<ClInclude Include="Gui\DvdSpin\D3DSpin.hpp" />
<ClInclude Include="Gui\DvdSpin\RenderDvdSpin.hpp" />
<ClInclude Include="Gui\DvdSpin\SpinShaderVarients.h" />
<ClInclude Include="Gui\MainWindow.hpp" />
<ClInclude Include="Gui\Renderer.hpp" />
<ClInclude Include="Gui\SDL.hpp" />
<ClInclude Include="Gui\DvdSpin\ceedee.h" />
<ClInclude Include="Gui\DvdSpin\vec.hpp" />
<ClInclude Include="Utils.hpp" />
<ClInclude Include="Scsi\IoCtl.hpp" />
<ClInclude Include="Scsi\OpticalDrive.hpp" />

View File

@ -45,6 +45,12 @@
<ClCompile Include="Dvd\DvdRipper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Gui\DvdSpin\D3DSpin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Gui\DvdSpin\RenderDvdSpin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Scsi\IoCtl.hpp">
@ -77,5 +83,20 @@
<ClInclude Include="Dvd\DvdRipper.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Gui\DvdSpin\ceedee.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Gui\DvdSpin\vec.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Gui\DvdSpin\D3DSpin.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Gui\DvdSpin\SpinShaderVarients.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Gui\DvdSpin\RenderDvdSpin.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -1,9 +1,14 @@
#include "D3D.hpp"
#include <string>
#include <iostream>
#include <SDL.h>
#include <imgui.h>
#include <imgui_impl_dx11.h>
#include <DirectXMath.h>
#include <d3dcompiler.h>
#include <d3d11.h>
namespace Li::Gui {
void D3D::createRenderTarget() {
ID3D11Texture2D* backBuffer;
@ -12,35 +17,37 @@ namespace Li::Gui {
backBuffer->Release();
}
bool D3D::createDeviceD3D() {
// Setup swap chain
DXGI_SWAP_CHAIN_DESC sd;
memset(&sd, 0, sizeof(sd));
sd.BufferCount = 2;
sd.BufferDesc.Width = 0;
sd.BufferDesc.Height = 0;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = this->hwnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
bool D3D::createDeviceD3D() {
// Setup swap chain
DXGI_SWAP_CHAIN_DESC sd;
memset(&sd, 0, sizeof(sd));
sd.BufferCount = 2;
sd.BufferDesc.Width = this->windowWidth;
sd.BufferDesc.Height = this->windowHeight;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = this->hwnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = TRUE;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
UINT createDeviceFlags = 0;
//createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
D3D_FEATURE_LEVEL featureLevel;
const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &this->swapChain, &this->d3dDevice, &featureLevel, &this->d3dDeviceContext) != S_OK)
return false;
UINT createDeviceFlags = 0;
#ifdef DEBUG
createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
D3D_FEATURE_LEVEL featureLevel;
const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &this->swapChain, &this->d3dDevice, &featureLevel, &this->d3dDeviceContext) != S_OK)
return false;
return true;
}
return true;
}
void D3D::cleanupDeviceD3D() {
if (this->swapChain) {
this->swapChain->Release();
@ -76,31 +83,92 @@ namespace Li::Gui {
ImGui_ImplDX11_Init(this->d3dDevice, this->d3dDeviceContext);
}
void D3D::ImGuiNewFrame() {
DirectX::XMFLOAT4 clearColor(0.0f, 0.0f, 0.0f, 1.0f);
const float clearColorWithAlpha[4] = { clearColor.x * clearColor.w, clearColor.y * clearColor.w, clearColor.z * clearColor.w, clearColor.w };
this->d3dDeviceContext->ClearRenderTargetView(this->mainRenderTargetView, clearColorWithAlpha);
ImGui_ImplDX11_NewFrame();
}
void D3D::Resize() {
void D3D::Resize(int newWidth, int newHeight) {
this->cleanupRenderTarget();
this->swapChain->ResizeBuffers(0, 0, 0, DXGI_FORMAT_UNKNOWN, 0);
this->windowWidth = newWidth;
this->windowHeight = newHeight;
this->swapChain->ResizeBuffers(0, newWidth, newHeight, DXGI_FORMAT_UNKNOWN, 0);
this->createRenderTarget();
this->setupRenderTarget();
}
void D3D::Render(ImVec4 clearColor) {
const float clearColorWithAlpha[4] = { clearColor.x * clearColor.w, clearColor.y * clearColor.w, clearColor.z * clearColor.w, clearColor.w };
int D3D::CompileShader(std::string shaderSrc, std::string entryPoint, std::string shaderModel, void** shaderObjectOut) {
DWORD shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#ifdef _DEBUG
shaderFlags |= D3DCOMPILE_DEBUG;
shaderFlags |= D3DCOMPILE_SKIP_OPTIMIZATION;
#endif
ID3DBlob* errorObj = nullptr;
HRESULT res = D3DCompile(shaderSrc.c_str(), shaderSrc.size(), nullptr, nullptr, nullptr, entryPoint.c_str(), shaderModel.c_str(), shaderFlags, 0, (ID3DBlob**)shaderObjectOut, &errorObj);
if (res < 0) {
if (errorObj)
{
std::string error = std::string((const char*)(errorObj->GetBufferPointer()));
std::cerr << error << std::endl;
errorObj->Release();
}
return res;
}
if (errorObj) errorObj->Release();
return S_OK;
}
void D3D::setupRenderTarget() {
this->d3dDeviceContext->OMSetRenderTargets(1, &this->mainRenderTargetView, NULL);
this->d3dDeviceContext->ClearRenderTargetView(this->mainRenderTargetView, clearColorWithAlpha);
D3D11_VIEWPORT vp;
vp.Width = (FLOAT)this->windowWidth;
vp.Height = (FLOAT)this->windowHeight;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
this->d3dDeviceContext->RSSetViewports(1, &vp);
this->d3dDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
}
void D3D::Render() {
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
this->swapChain->Present(1, 0);
}
D3D::D3D(HWND hwnd) {
int D3D::WindowHeight() {
return this->windowHeight;
}
int D3D::WindowWidth() {
return this->windowWidth;
}
D3D::D3D(HWND hwnd, int windowWidth, int windowHeight) {
this->hwnd = hwnd;
this->windowWidth = windowWidth;
this->windowHeight = windowHeight;
this->createDeviceD3D();
this->createRenderTarget();
this->setupRenderTarget();
};
D3D::~D3D() {
this->cleanupRenderTarget();
this->cleanupDeviceD3D();
}
}

View File

@ -8,9 +8,9 @@
#include <imgui.h>
#include <imgui_impl_dx11.h>
#include <d3d11.h>
#include <Windows.h>
#include <string>
namespace Li::Gui {
class D3D : public Renderer {
@ -20,21 +20,30 @@ namespace Li::Gui {
ID3D11DeviceContext* d3dDeviceContext;
IDXGISwapChain* swapChain;
ID3D11RenderTargetView* mainRenderTargetView;
int windowWidth;
int windowHeight;
bool createDeviceD3D();
void cleanupDeviceD3D();
void createRenderTarget();
void setupRenderTarget();
void cleanupRenderTarget();
void cleanupDeviceD3D();
public:
ID3D11Device* D3dDevice();
ID3D11DeviceContext* D3dDeviceContext();
void Resize();
int CompileShader(std::string shaderSrc, std::string entryPoint, std::string shaderModel, void** shaderObjectOut);
void Resize(int newWidth, int newHeight);
void InitImgui();
void ImGuiNewFrame();
void Render(ImVec4 clearColor);
void Render();
D3D(HWND hwnd);
int WindowWidth();
int WindowHeight();
D3D(HWND hwnd, int windowWidth, int windowHeight);
~D3D();
};
}

View File

@ -24,7 +24,6 @@ namespace Li::Gui {
this->imRippinIt = false;
this->selectedDrive = 0;
this->selectedDriveSpeed = 0;
this->counter = 0;
this->drivesList = Li::Scsi::OpticalDrive::ListOpticalDrives();
this->pollDrives = new std::thread(&DumpDVD::pollDrivesThread, this);
@ -287,6 +286,7 @@ namespace Li::Gui {
this->lock->unlock();
}
void DumpDVD::RenderUI() {
if (this->drivesList == nullptr) return;
@ -313,7 +313,6 @@ namespace Li::Gui {
if (showDemoWindow)
ImGui::ShowDemoWindow(&showDemoWindow);
#endif
this->counter++;
}
}

View File

@ -24,7 +24,6 @@ namespace Li::Gui {
bool discInserted;
int selectedDrive;
int selectedDriveSpeed;
uint32_t counter;
char outputFile[0x8000];
std::vector<Li::Scsi::OpticalDrive*>* drivesList;

View File

@ -0,0 +1,236 @@
#include "ceedee.h"
#include "vec.hpp"
#include "SpinShaderVarients.h"
#include <imgui.h>
#include <d3d11.h>
#include <directxmath.h>
#include <d3dcompiler.h>
#include "D3DSpin.hpp"
namespace Li::Gui::DvdSpin {
// dvd spin
void D3DSpin::setupSpinningDVD() {
this->createCdVertexShader();
this->createCdVertexLayout();
this->setCdVertexLayout();
this->createCdPixelShader();
this->createCdVertexBuffer();
this->setCdVertexBuffer();
this->createCdIndexBuffer();
this->setCdIndexBuffer();
this->createCamBuffer();
this->updateCamBuffer();
this->createCdTexture();
this->createCdResourceView();
this->createCdSampler();
}
HRESULT D3DSpin::createCdPixelShader() {
ID3DBlob* pixelShaderBlob;
d3d->CompileShader(std::string(spinShaderSrc), "pixelShaderMain", "ps_4_0", (void**)&pixelShaderBlob);
HRESULT hres = d3d->D3dDevice()->CreatePixelShader(pixelShaderBlob->GetBufferPointer(), pixelShaderBlob->GetBufferSize(), nullptr, &this->cdPixelShader);
pixelShaderBlob->Release();
return hres;
}
HRESULT D3DSpin::createCdVertexShader() {
d3d->CompileShader(std::string(spinShaderSrc), "vertexShaderMain", "vs_4_0", (void**)&this->cdVertexShaderBlob);
return d3d->D3dDevice()->CreateVertexShader(this->cdVertexShaderBlob->GetBufferPointer(), this->cdVertexShaderBlob->GetBufferSize(), nullptr, &this->cdVertexShader);
}
HRESULT D3DSpin::createCdVertexLayout() {
// define the layout
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "UV", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
// actually create it
return d3d->D3dDevice()->CreateInputLayout(layout, ARRAYSIZE(layout), this->cdVertexShaderBlob->GetBufferPointer(), this->cdVertexShaderBlob->GetBufferSize(), &this->cdVertexLayout);
}
void D3DSpin::setCdVertexLayout() {
this->cdVertexShaderBlob->Release();
d3d->D3dDeviceContext()->IASetInputLayout(this->cdVertexLayout);
}
void D3DSpin::updateCamBuffer() {
this->camWorld = DirectX::XMMatrixIdentity();
this->camView = DirectX::XMMatrixLookAtLH(this->eye, this->at, this->up);
this->camProjection = DirectX::XMMatrixPerspectiveFovLH(DirectX::XM_PIDIV2, this->d3d->WindowWidth() / (FLOAT)d3d->WindowHeight(), 0.01f, 100.0f);
}
HRESULT D3DSpin::createCamBuffer() {
D3D11_BUFFER_DESC camBufferDesc;
memset(&camBufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
camBufferDesc.Usage = D3D11_USAGE_DEFAULT;
camBufferDesc.ByteWidth = (sizeof(DirectX::XMMATRIX) * 3);
camBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
camBufferDesc.CPUAccessFlags = 0;
return d3d->D3dDevice()->CreateBuffer(&camBufferDesc, nullptr, &this->camBuffer);
}
HRESULT D3DSpin::createCdIndexBuffer() {
D3D11_BUFFER_DESC indexBufferDesc;
memset(&indexBufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
indexBufferDesc.ByteWidth = (sizeof(uint16_t) * ceedeeModelTotalIndices);
indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDesc.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA indexBufferInitData;
memset(&indexBufferInitData, 0, sizeof(D3D11_SUBRESOURCE_DATA));
indexBufferInitData.pSysMem = ceedeeModelIndexBuffer;
return d3d->D3dDevice()->CreateBuffer(&indexBufferDesc, &indexBufferInitData, &this->cdIndexBuffer);
}
void D3DSpin::setCdIndexBuffer() {
d3d->D3dDeviceContext()->IASetIndexBuffer(this->cdIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
}
void D3DSpin::setCdVertexBuffer() {
uint32_t stride = sizeof(ModelVertex);
uint32_t offset = 0;
return d3d->D3dDeviceContext()->IASetVertexBuffers(0, 1, &this->cdVertexBuffer, &stride, &offset);
}
HRESULT D3DSpin::createCdVertexBuffer() {
D3D11_BUFFER_DESC vertexBufferDesc;
memset(&vertexBufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof(ModelVertex) * ceedeeModelTotalVertices;
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA vertexBufferInitData;
memset(&vertexBufferInitData, 0, sizeof(D3D11_SUBRESOURCE_DATA));
vertexBufferInitData.pSysMem = ceedeeModelVertexBuffer;
return d3d->D3dDevice()->CreateBuffer(&vertexBufferDesc, &vertexBufferInitData, &this->cdVertexBuffer);
}
HRESULT D3DSpin::createCdTexture() {
D3D11_TEXTURE2D_DESC tdesc;
tdesc.Width = ceedeeImgWidth;
tdesc.Height = ceedeeImgHeight;
tdesc.MipLevels = 1;
tdesc.ArraySize = 1;
tdesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
tdesc.SampleDesc.Count = 1;
tdesc.SampleDesc.Quality = 0;
tdesc.Usage = D3D11_USAGE_DEFAULT;
tdesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
tdesc.CPUAccessFlags = 0;
tdesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA tres = {};
tres.pSysMem = ceedeeImgData;
tres.SysMemPitch = (ceedeeImgWidth * ceedeeImgChannels);
tres.SysMemSlicePitch = 0;
return d3d->D3dDevice()->CreateTexture2D(&tdesc, &tres, &this->cdTexture);
}
HRESULT D3DSpin::createCdResourceView() {
return d3d->D3dDevice()->CreateShaderResourceView(this->cdTexture, NULL, &this->cdResourceView);
}
HRESULT D3DSpin::createCdSampler() {
D3D11_SAMPLER_DESC sdesc;
sdesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
sdesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
sdesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
sdesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
sdesc.MipLODBias = 1.0f;
sdesc.MaxAnisotropy = 1;
sdesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
sdesc.BorderColor[0] = 1.0f;
sdesc.BorderColor[1] = 1.0f;
sdesc.BorderColor[2] = 1.0f;
sdesc.BorderColor[3] = 1.0f;
sdesc.MinLOD = -FLT_MAX;
sdesc.MaxLOD = FLT_MAX;
return d3d->D3dDevice()->CreateSamplerState(&sdesc, &this->cdSampler);
}
void D3DSpin::RenderDVD() {
this->counter++;
this->camWorld = DirectX::XMMatrixRotationY((float)((float)this->counter / 10.0f));
DirectX::XMMATRIX camBufData[3];
camBufData[0] = XMMatrixTranspose(this->camWorld);
camBufData[1] = XMMatrixTranspose(this->camView);
camBufData[2] = XMMatrixTranspose(this->camProjection);
d3d->D3dDeviceContext()->UpdateSubresource(this->camBuffer, 0, nullptr, &camBufData, 0, 0);
d3d->D3dDeviceContext()->VSSetShader(this->cdVertexShader, nullptr, 0);
d3d->D3dDeviceContext()->VSSetConstantBuffers(0, 1, &this->camBuffer);
d3d->D3dDeviceContext()->PSSetShader(this->cdPixelShader, nullptr, 0);
d3d->D3dDeviceContext()->PSSetShaderResources(0, 1, &this->cdResourceView);
d3d->D3dDeviceContext()->PSSetSamplers(0, 1, &this->cdSampler);
d3d->D3dDeviceContext()->DrawIndexed(ceedeeModelTotalIndices, 0, 0);
this->updateCamBuffer();
#ifdef _DEBUG
ImGui::Begin("Debug Position");
ImGui::DragFloat4("Eye", (float*)this->eye.m128_f32);
ImGui::DragFloat4("At", (float*)this->at.m128_f32);
ImGui::DragFloat4("Up", (float*)this->up.m128_f32);
ImGui::End();
#endif
}
D3DSpin::D3DSpin(D3D* d3d) {
this->eye = DirectX::XMVectorSet(0.0f, 2.0f, 3.0f, 0.0f);
this->at = DirectX::XMVectorSet(0.0f, 2.0f, 0.0f, 0.0f);
this->up = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
this->d3d = d3d;
this->cdVertexShader = nullptr;
this->cdPixelShader = nullptr;
this->cdVertexLayout = nullptr;
this->cdVertexBuffer = nullptr;
this->cdIndexBuffer = nullptr;
this->camBuffer = nullptr;
this->cdTexture = nullptr;
this->cdSampler = nullptr;
this->cdResourceView = nullptr;
this->setupSpinningDVD();
}
D3DSpin::~D3DSpin() {
this->cdVertexShader->Release();
this->cdPixelShader->Release();
this->cdVertexLayout->Release();
this->cdVertexBuffer->Release();
this->cdIndexBuffer->Release();
this->camBuffer->Release();
this->cdTexture->Release();
this->cdSampler->Release();
this->cdResourceView->Release();
}
}

View File

@ -0,0 +1,67 @@
#ifndef _LI_D3DSPIN
#define _LI_D3DSPIN 1
#include <DirectXMath.h>
#include "RenderDvdSpin.hpp"
#include "../D3D.hpp"
namespace Li::Gui::DvdSpin {
class D3DSpin : public RenderDvdSpin {
private:
D3D* d3d;
uint32_t counter;
// dvd spin state
DirectX::XMMATRIX camWorld;
DirectX::XMMATRIX camView;
DirectX::XMMATRIX camProjection;
DirectX::XMVECTOR eye;
DirectX::XMVECTOR at;
DirectX::XMVECTOR up;
ID3DBlob* cdVertexShaderBlob;
ID3D11VertexShader* cdVertexShader;
ID3D11PixelShader* cdPixelShader;
ID3D11InputLayout* cdVertexLayout;
ID3D11Buffer* cdVertexBuffer;
ID3D11Buffer* cdIndexBuffer;
ID3D11Buffer* camBuffer;
ID3D11Texture2D* cdTexture;
ID3D11SamplerState* cdSampler;
ID3D11ShaderResourceView* cdResourceView;
// dvd spin model
void setupSpinningDVD();
HRESULT createViewport();
HRESULT createCdVertexShader();
HRESULT createCdPixelShader();
HRESULT createCdVertexLayout();
HRESULT createCdVertexBuffer();
HRESULT createCdIndexBuffer();
HRESULT createCamBuffer();
void setCdVertexBuffer();
void setCdIndexBuffer();
void setCdVertexLayout();
void updateCamBuffer();
// dvd spin texture
HRESULT createCdTexture();
HRESULT createCdSampler();
HRESULT createCdResourceView();
public:
void RenderDVD();
D3DSpin(D3D* d3d);
~D3DSpin();
};
}
#endif

View File

@ -0,0 +1,29 @@
#include "RenderDvdSpin.hpp"
#include "../Renderer.hpp"
#ifdef _WIN32
#include "../D3D.hpp"
#include "D3DSpin.hpp"
#endif
namespace Li::Gui::DvdSpin {
RenderDvdSpin* RenderDvdSpin::CreateDvdSpinner(Renderer* renderer)
{
#ifdef _WIN32
D3D* d3d = (D3D*)renderer;
return new D3DSpin(d3d);
#endif
}
void RenderDvdSpin::DeleteDvdSpinner(RenderDvdSpin* spin)
{
#ifdef _WIN32
D3DSpin* d3dSpin = (D3DSpin*)spin;
delete d3dSpin;
#endif
}
}

View File

@ -0,0 +1,14 @@
#ifndef _LI_RENDER_DVD_SPIN
#define _LI_RENDER_DVD_SPIN 1
#include "../Renderer.hpp"
namespace Li::Gui::DvdSpin {
class RenderDvdSpin {
public:
virtual void RenderDVD() {};
static RenderDvdSpin* CreateDvdSpinner(Renderer* renderer);
static void DeleteDvdSpinner(RenderDvdSpin* spinner);
};
}
#endif

View File

@ -0,0 +1,30 @@
Texture2D cdTexture;
SamplerState cdSampler;
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float2 Uv : UV;
};
cbuffer CamBuffer : register( b0 )
{
matrix camWorld;
matrix camView;
matrix camProjection;
}
float4 pixelShaderMain(VS_OUTPUT input) : SV_Target
{
return cdTexture.Sample(cdSampler, input.Uv);
}
VS_OUTPUT vertexShaderMain( float4 Position : POSITION, float2 Uv : UV )
{
VS_OUTPUT output = (VS_OUTPUT)0;
output.Pos = mul( Position, camWorld );
output.Pos = mul( output.Pos, camView );
output.Pos = mul( output.Pos, camProjection );
output.Uv = Uv;
return output;
}

View File

@ -0,0 +1,8 @@
#ifndef _LI_SPINSHADER_H
#define _LI_SPINSHADER_H 1
#include <stdint.h>
#ifdef _WIN32
static char spinShaderSrc[0x271] {0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x20, 0x63, 0x64, 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x3B, 0x0D, 0x0A, 0x53, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x65, 0x20, 0x63, 0x64, 0x53, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x72, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x56, 0x53, 0x5F, 0x4F, 0x55, 0x54, 0x50, 0x55, 0x54, 0x0D, 0x0A, 0x7B, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x34, 0x20, 0x50, 0x6F, 0x73, 0x20, 0x3A, 0x20, 0x53, 0x56, 0x5F, 0x50, 0x4F, 0x53, 0x49, 0x54, 0x49, 0x4F, 0x4E, 0x3B, 0x0D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x32, 0x20, 0x55, 0x76, 0x20, 0x3A, 0x20, 0x55, 0x56, 0x3B, 0x0D, 0x0A, 0x7D, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x63, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x20, 0x43, 0x61, 0x6D, 0x42, 0x75, 0x66, 0x66, 0x65, 0x72, 0x20, 0x3A, 0x20, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x28, 0x20, 0x62, 0x30, 0x20, 0x29, 0x0D, 0x0A, 0x7B, 0x0D, 0x0A, 0x09, 0x6D, 0x61, 0x74, 0x72, 0x69, 0x78, 0x20, 0x63, 0x61, 0x6D, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x3B, 0x0D, 0x0A, 0x09, 0x6D, 0x61, 0x74, 0x72, 0x69, 0x78, 0x20, 0x63, 0x61, 0x6D, 0x56, 0x69, 0x65, 0x77, 0x3B, 0x0D, 0x0A, 0x09, 0x6D, 0x61, 0x74, 0x72, 0x69, 0x78, 0x20, 0x63, 0x61, 0x6D, 0x50, 0x72, 0x6F, 0x6A, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x3B, 0x0D, 0x0A, 0x7D, 0x0D, 0x0A, 0x0D, 0x0A, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x34, 0x20, 0x70, 0x69, 0x78, 0x65, 0x6C, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4D, 0x61, 0x69, 0x6E, 0x28, 0x56, 0x53, 0x5F, 0x4F, 0x55, 0x54, 0x50, 0x55, 0x54, 0x20, 0x69, 0x6E, 0x70, 0x75, 0x74, 0x29, 0x20, 0x3A, 0x20, 0x53, 0x56, 0x5F, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x0D, 0x0A, 0x7B, 0x0D, 0x0A, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6E, 0x20, 0x63, 0x64, 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x2E, 0x53, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x28, 0x63, 0x64, 0x53, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x72, 0x2C, 0x20, 0x69, 0x6E, 0x70, 0x75, 0x74, 0x2E, 0x55, 0x76, 0x29, 0x3B, 0x0D, 0x0A, 0x7D, 0x0D, 0x0A, 0x0D, 0x0A, 0x56, 0x53, 0x5F, 0x4F, 0x55, 0x54, 0x50, 0x55, 0x54, 0x20, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4D, 0x61, 0x69, 0x6E, 0x28, 0x20, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x34, 0x20, 0x50, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x3A, 0x20, 0x50, 0x4F, 0x53, 0x49, 0x54, 0x49, 0x4F, 0x4E, 0x2C, 0x20, 0x66, 0x6C, 0x6F, 0x61, 0x74, 0x32, 0x20, 0x55, 0x76, 0x20, 0x3A, 0x20, 0x55, 0x56, 0x20, 0x29, 0x0D, 0x0A, 0x7B, 0x0D, 0x0A, 0x09, 0x56, 0x53, 0x5F, 0x4F, 0x55, 0x54, 0x50, 0x55, 0x54, 0x20, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x3D, 0x20, 0x28, 0x56, 0x53, 0x5F, 0x4F, 0x55, 0x54, 0x50, 0x55, 0x54, 0x29, 0x30, 0x3B, 0x0D, 0x0A, 0x09, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2E, 0x50, 0x6F, 0x73, 0x20, 0x3D, 0x20, 0x6D, 0x75, 0x6C, 0x28, 0x20, 0x50, 0x6F, 0x73, 0x69, 0x74, 0x69, 0x6F, 0x6E, 0x2C, 0x20, 0x63, 0x61, 0x6D, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x20, 0x29, 0x3B, 0x0D, 0x0A, 0x09, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2E, 0x50, 0x6F, 0x73, 0x20, 0x3D, 0x20, 0x6D, 0x75, 0x6C, 0x28, 0x20, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2E, 0x50, 0x6F, 0x73, 0x2C, 0x20, 0x63, 0x61, 0x6D, 0x56, 0x69, 0x65, 0x77, 0x20, 0x29, 0x3B, 0x0D, 0x0A, 0x09, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2E, 0x50, 0x6F, 0x73, 0x20, 0x3D, 0x20, 0x6D, 0x75, 0x6C, 0x28, 0x20, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2E, 0x50, 0x6F, 0x73, 0x2C, 0x20, 0x63, 0x61, 0x6D, 0x50, 0x72, 0x6F, 0x6A, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x29, 0x3B, 0x0D, 0x0A, 0x09, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2E, 0x55, 0x76, 0x20, 0x3D, 0x20, 0x55, 0x76, 0x3B, 0x0D, 0x0A, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6E, 0x20, 0x6F, 0x75, 0x74, 0x70, 0x75, 0x74, 0x3B, 0x0D, 0x0A, 0x7D, 0x00};
#endif
#endif

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

View File

@ -0,0 +1,63 @@
import struct
from PIL import Image
imgName = "ceedee"
hdr = "#ifndef _LI_"+imgName.upper()+"_H\n"
hdr += "#define _LI_"+imgName.upper()+"_H 1\n"
hdr += "#include \"vec.hpp\"\n"
hdr += "#include <stdint.h>\n"
def readTexture(imgName):
global hdr
with Image.open(imgName+".png") as img:
img = img.convert("RGBA")
imgWidth, imgHeight = img.size
hdr += "const uint32_t "+imgName+"ImgWidth = "+hex(imgWidth)+";\n"
hdr += "const uint32_t "+imgName+"ImgHeight = "+hex(imgHeight)+";\n"
hdr += "const uint32_t "+imgName+"ImgChannels = "+hex(4)+";\n"
rgbaValues = []
for y in range(0, imgHeight):
for x in range(0, imgWidth):
r, g, b, a = img.getpixel((x, y))
rgba = 0;
rgba |= a << 24
rgba |= b << 16
rgba |= g << 8
rgba |= r
rgbaValues.append(hex(rgba))
hdr += "const uint32_t "+imgName+"ImgDataSz = "+hex(len(rgbaValues))+";\n"
hdr += "static uint32_t "+imgName+"ImgData["+hex(len(rgbaValues))+"] {"+", ".join(rgbaValues)+"};\n"
def read3D(vboName):
global hdr
with open(vboName + ".vbo", "rb") as vbo:
totalVertex, totalIndex = struct.unpack("II", vbo.read(4 * 2))
hdr += "const uint32_t "+imgName+"ModelTotalVertices = "+hex(totalVertex)+";\n"
hdr += "const uint32_t "+imgName+"ModelTotalIndices = "+hex(totalIndex)+";\n"
verticies = []
indicies = []
for i in range(0, totalVertex):
posX, posY, posZ = struct.unpack("fff", vbo.read(4 * 3))
norX, norY, norZ = struct.unpack("fff", vbo.read(4 * 3))
texX, texY = struct.unpack("ff", vbo.read(4 * 2))
verticies.append("{ Vec3({"+str(posX*30.0)+"f, "+str(posY*30.0)+"f, "+str(posZ*30.0)+"f}), Vec2({"+str(texX)+"f, "+str(texY)+"f}) }")
for i in range(0, totalIndex):
index = struct.unpack("H", vbo.read(2))
indicies.append(hex(index[0]))
hdr += "static ModelVertex "+imgName+"ModelVertexBuffer["+hex(len(verticies))+"] { "+", ".join(verticies)+"};\n"
hdr += "static uint16_t "+imgName+"ModelIndexBuffer["+hex(len(indicies))+"] { "+", ".join(indicies)+" };\n"
readTexture(imgName)
read3D(imgName)
hdr += "#endif"
print(hdr)

View File

@ -0,0 +1,16 @@
def getShdrVarient(fname):
dbytes = []
sl = bytearray(open(fname, "rb").read())
for i in range(0, len(sl)):
dbytes.append(f"0x{sl[i]:02X}")
dbytes.append("0x00")
return "static char spinShaderSrc["+hex(len(dbytes))+"] {"+", ".join(dbytes)+"};\n"
hdr = "#ifndef _LI_SPINSHADER_H\n"
hdr += "#define _LI_SPINSHADER_H 1\n"
hdr += "#include <stdint.h>\n"
hdr += "#ifdef _WIN32\n"
hdr += getShdrVarient("SpinShader.hlsl")
hdr += "#endif\n"
hdr += "#endif\n"
print(hdr)

View File

@ -0,0 +1,27 @@
#ifndef _LI_VEC_H
#define _LI_VEC_H 1
typedef struct Vec2{
float x;
float y;
} Vec2;
typedef struct Vec3{
float x;
float y;
float z;
} Vec3;
typedef struct Vec4{
float x;
float y;
float z;
float w;
} Vec4;
typedef struct Vertex{
Vec3 Pos;
Vec2 Uv;
} ModelVertex;
#endif

View File

@ -2,6 +2,9 @@
#include "SDL.hpp"
#include "DumpDVD.hpp"
#include "D3D.hpp"
#include "DvdSpin/D3DSpin.hpp"
#include <iostream>
#include <string>
#include <vector>
@ -12,16 +15,20 @@ namespace Li::Gui {
this->sdl = new SDL("DumpDVD", 800, 400);
this->sdl->SetMaxFPS(24.0);
// Create dvd spinner
Li::Gui::DvdSpin::RenderDvdSpin* spin = Li::Gui::DvdSpin::RenderDvdSpin::CreateDvdSpinner(sdl->Renderer());
// Create menu
DumpDVD* dumpDvdMenu = new DumpDVD();
while (!this->sdl->IsExiting()) {
this->sdl->PollEvent();
this->sdl->NewFrame();
spin->RenderDVD();
dumpDvdMenu->RenderUI();
this->sdl->Render();
}
Li::Gui::DvdSpin::RenderDvdSpin::DeleteDvdSpinner(spin);
delete dumpDvdMenu;
}

View File

@ -1,12 +1,17 @@
#ifndef _LI_RENDERER_H
#define _LI_RENDERER_H 1
#include <imgui.h>
#include <string>
namespace Li::Gui {
class Renderer {
public:
virtual void InitImgui() {};
virtual void ImGuiNewFrame() {};
virtual void Render(ImVec4 clearColor) {};
virtual void Render() {};
virtual void Resize(int newWidth, int newHeight) {};
virtual int WindowWidth() { return 0; };
virtual int WindowHeight() { return 0; };
virtual int CompileShader(std::string shaderSrc, std::string entryPoint, std::string shaderModel, void** shaderObjectOut) { return -1; };
};
}
#endif

View File

@ -2,6 +2,8 @@
#ifdef _WIN32
#include "D3D.hpp"
#include "DvdSpin/D3DSpin.hpp"
#include <windows.h>
#include <imgui_impl_dx11.h>
#endif
@ -34,7 +36,9 @@ namespace Li::Gui {
#ifdef _WIN32
HWND hwnd = (HWND)this->wmInfo.info.win.window;
this->renderer = new D3D(hwnd);
D3D* d3dObj = new D3D(hwnd, windowWidth, windowHeight);
this->renderer = d3dObj;
//this->dvdSpinner = new Li::Gui::DvdSpin::D3DSpin(d3dObj);
#else
#error no renderer for this platform
#endif
@ -73,14 +77,23 @@ namespace Li::Gui {
{
// Release all outstanding references to the swap chain's buffers before resizing.
#ifdef _WIN32
int width;
int height;
SDL_GetWindowSize(this->window, &width, &height);
D3D* d3d = (D3D*)this->renderer;
d3d->Resize();
d3d->Resize(width, height);
#else
#error No resize method provided for this platform
#endif
}
}
}
Renderer* SDL::Renderer() {
return this->renderer;
}
void SDL::NewFrame() {
this->curRenderTime = SDL_GetTicks();
@ -91,13 +104,12 @@ namespace Li::Gui {
void SDL::SetMaxFPS(float fpsLimit) {
this->maxFps = fpsLimit;
this->limit = (1000 / this->maxFps);
this->limit = (uint32_t)((float)1000.0 / this->maxFps);
}
void SDL::Render() {
ImGui::Render();
ImVec4 clearColor = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
this->renderer->Render(clearColor);
this->renderer->Render();
this->lastRenderTime = this->curRenderTime;
this->delta = (this->curRenderTime - this->lastRenderTime);
@ -116,7 +128,7 @@ namespace Li::Gui {
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
delete renderer;
delete this->renderer;
SDL_DestroyWindow(this->window);
SDL_Quit();
}

View File

@ -1,6 +1,8 @@
#ifndef _LI_SDL_H
#define _LI_SDL_H 1
#include "Renderer.hpp"
#include "DvdSpin/RenderDvdSpin.hpp"
#include <SDL.h>
#include <SDL_syswm.h>
#include <string>
@ -12,7 +14,6 @@ namespace Li::Gui {
SDL_SysWMinfo wmInfo;
SDL_Window* window;
float maxFps;
uint32_t limit;
@ -29,6 +30,7 @@ namespace Li::Gui {
void SetMaxFPS(float fpsLimit);
void PollEvent();
void Render();
Renderer* Renderer();
SDL(std::string windowTitle, int windowWidth, int windowHeight);
~SDL();
};

Binary file not shown.