diff --git a/miniwin/src/d3drm/backends/citro3d/renderer.cpp b/miniwin/src/d3drm/backends/citro3d/renderer.cpp index ce8b9ae6..4620a85b 100644 --- a/miniwin/src/d3drm/backends/citro3d/renderer.cpp +++ b/miniwin/src/d3drm/backends/citro3d/renderer.cpp @@ -48,15 +48,25 @@ static const vertex position_list[] = { int g_vertexCount = 0; _Static_assert(sizeof(vbo_data_pos) % 4 == 0, "vertex size not 4-byte aligned"); -static void sceneInit(void) +Citro3DRenderer::Citro3DRenderer(DWORD width, DWORD height) { - // Load the vertex shader, create a shader program and bind it + m_width = 400; + m_height = 240; + m_virtualWidth = width; + m_virtualHeight = height; + + gfxInitDefault(); + consoleInit(GFX_BOTTOM, nullptr); + C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); + + target = C3D_RenderTargetCreate(m_height, m_width, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); + C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); + vshader_dvlb = DVLB_ParseFile((u32*) vshader_shbin, vshader_shbin_size); shaderProgramInit(&program); shaderProgramSetVsh(&program, &vshader_dvlb->DVLE[0]); C3D_BindProgram(&program); - // Get the location of the uniforms uLoc_projection = shaderInstanceGetUniformLocation(program.vertexShader, "projection"); uLoc_modelView = shaderInstanceGetUniformLocation(program.vertexShader, "modelView"); uLoc_meshColor = shaderInstanceGetUniformLocation(program.vertexShader, "meshColor"); @@ -66,33 +76,6 @@ static void sceneInit(void) AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 2); // v1=texcoord AttrInfo_AddLoader(attrInfo, 2, GPU_FLOAT, 3); // v2=normal - - C3D_Mtx projection; - Mtx_OrthoTilt(&projection, 0.0, 400.0, 0.0, 240.0, 0.0, 1.0, true); -} - -Direct3DRMRenderer* Citro3DRenderer::Create(DWORD width, DWORD height) -{ - gfxInitDefault(); - consoleInit(GFX_BOTTOM, nullptr); - C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); - - // Initialize the render target - target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); - C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); - - sceneInit(); - - return new Citro3DRenderer(width, height); -} - -Citro3DRenderer::Citro3DRenderer(DWORD width, DWORD height) -{ - SDL_Log("Citro3DRenderer %dx%d", width, height); - m_width = width; - m_height = height; - m_virtualWidth = width; - m_virtualHeight = height; } Citro3DRenderer::~Citro3DRenderer() @@ -339,15 +322,6 @@ Uint32 Citro3DRenderer::GetMeshId(IDirect3DRMMesh* mesh, const MeshGroup* meshGr void Citro3DRenderer::GetDesc(D3DDEVICEDESC* halDesc, D3DDEVICEDESC* helDesc) { - halDesc->dcmColorModel = D3DCOLORMODEL::RGB; - halDesc->dwFlags = D3DDD_DEVICEZBUFFERBITDEPTH; - halDesc->dwDeviceZBufferBitDepth = DDBD_24; - halDesc->dwDeviceRenderBitDepth = DDBD_32; - halDesc->dpcTriCaps.dwTextureCaps = D3DPTEXTURECAPS_PERSPECTIVE; - halDesc->dpcTriCaps.dwShadeCaps = D3DPSHADECAPS_ALPHAFLATBLEND; - halDesc->dpcTriCaps.dwTextureFilterCaps = D3DPTFILTERCAPS_LINEAR; - - memset(helDesc, 0, sizeof(D3DDEVICEDESC)); } const char* Citro3DRenderer::GetName() diff --git a/miniwin/src/d3drm/d3drm.cpp b/miniwin/src/d3drm/d3drm.cpp index 3b3a4b27..0ae75caa 100644 --- a/miniwin/src/d3drm/d3drm.cpp +++ b/miniwin/src/d3drm/d3drm.cpp @@ -164,7 +164,7 @@ HRESULT Direct3DRMImpl::CreateDeviceFromSurface( #endif #ifdef USE_CITRO3D else if (SDL_memcmp(&guid, &Citro3D_GUID, sizeof(GUID)) == 0) { - DDRenderer = Citro3DRenderer::Create(DDSDesc.dwWidth, DDSDesc.dwHeight); + DDRenderer = new Citro3DRenderer(DDSDesc.dwWidth, DDSDesc.dwHeight); } #endif #ifdef _WIN32 diff --git a/miniwin/src/ddraw/ddraw.cpp b/miniwin/src/ddraw/ddraw.cpp index af095058..ddd2e431 100644 --- a/miniwin/src/ddraw/ddraw.cpp +++ b/miniwin/src/ddraw/ddraw.cpp @@ -349,7 +349,7 @@ HRESULT DirectDrawImpl::CreateDevice( #endif #ifdef USE_CITRO3D else if (SDL_memcmp(&guid, &Citro3D_GUID, sizeof(GUID)) == 0) { - DDRenderer = Citro3DRenderer::Create(DDSDesc.dwWidth, DDSDesc.dwHeight); + DDRenderer = new Citro3DRenderer(DDSDesc.dwWidth, DDSDesc.dwHeight); } #endif #ifdef _WIN32 diff --git a/miniwin/src/internal/d3drmrenderer_citro3d.h b/miniwin/src/internal/d3drmrenderer_citro3d.h index 254303d7..4320ee0e 100644 --- a/miniwin/src/internal/d3drmrenderer_citro3d.h +++ b/miniwin/src/internal/d3drmrenderer_citro3d.h @@ -5,12 +5,11 @@ #include "d3drmtexture_impl.h" #include "ddraw_impl.h" -#include #include -#include +#include #include -DEFINE_GUID(Citro3D_GUID, 0x682656F3, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07); +DEFINE_GUID(Citro3D_GUID, 0x682656F3, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3D, 0x53); struct C3DTextureCacheEntry { IDirect3DRMTexture* texture; @@ -21,27 +20,23 @@ struct C3DTextureCacheEntry { }; struct C3DMeshCacheEntry { - const MeshGroup* meshGroup = nullptr; - Uint32 version = 0; - bool flat = false; + const MeshGroup* meshGroup = nullptr; + Uint32 version = 0; + bool flat = false; - C3D_AttrInfo attrInfo; - C3D_BufInfo bufInfo; + C3D_AttrInfo attrInfo; + C3D_BufInfo bufInfo; - // CPU-side vertex data + // CPU-side vertex data std::vector vertices; - std::vector positions; - std::vector normals; - std::vector texcoords; // Only if you have textures - std::vector indices; // Indices for indexed drawing + std::vector positions; + std::vector normals; + std::vector texcoords; // Only if you have textures + std::vector indices; // Indices for indexed drawing }; - class Citro3DRenderer : public Direct3DRMRenderer { public: - static Direct3DRMRenderer* Create(DWORD width, DWORD height); - - // constructor parameters not finalized Citro3DRenderer(DWORD width, DWORD height); ~Citro3DRenderer() override; @@ -94,10 +89,21 @@ class Citro3DRenderer : public Direct3DRMRenderer { inline static void Citro3DRenderer_EnumDevice(LPD3DENUMDEVICESCALLBACK cb, void* ctx) { - SDL_Log("Hello, enuming device"); - Direct3DRMRenderer* device = Citro3DRenderer::Create(400, 240); - if (device) { - EnumDevice(cb, ctx, device, Citro3D_GUID); - delete device; - } + GUID guid = Citro3D_GUID; + char* deviceNameDup = SDL_strdup("Citro3D"); + char* deviceDescDup = SDL_strdup("Miniwin driver"); + D3DDEVICEDESC halDesc = {}; + halDesc.dcmColorModel = D3DCOLOR_RGB; + halDesc.dwFlags = D3DDD_DEVICEZBUFFERBITDEPTH; + halDesc.dwDeviceZBufferBitDepth = DDBD_24; + halDesc.dwDeviceRenderBitDepth = DDBD_32; + halDesc.dpcTriCaps.dwTextureCaps = D3DPTEXTURECAPS_PERSPECTIVE; + halDesc.dpcTriCaps.dwShadeCaps = D3DPSHADECAPS_ALPHAFLATBLEND; + halDesc.dpcTriCaps.dwTextureFilterCaps = D3DPTFILTERCAPS_LINEAR; + D3DDEVICEDESC helDesc = {}; + + cb(&guid, deviceNameDup, deviceDescDup, &halDesc, &helDesc, ctx); + + SDL_free(deviceDescDup); + SDL_free(deviceNameDup); }