mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-13 03:01:16 +00:00
* [WIP] 3ds port
Recommit of everything after the 2d renderer merge
* VERY AWESOME FEATURE FRFR
* Stopped CPU suicide and app crashing for now
* put in Texture3DS function thing
* Fix clear color
* Implement 2D rendering via Citro3D
* Set 3dsx smdh metadata
* Render world content, sort of
* Push mesh dynamically
* Remove Citro3D init hacks
* Clean up Citro3D implementation
* Try to upload meshes and convert matricies
* Fix 3D rendering
* Apply optimizations
* Implement lighting
* Set 3dsx smdh metadata
* Revert "Apply optimizations"
This reverts commit 6660082fef.
* Apply optimizations
* Added a cleaner icon (#4)
* Fix pure buffer clear frames (#9)
* Disable OpenGL on 3DS (#10)
* Fix tiled textures and improve UI image quality (#11)
* Create 3DS default config overrides
* 3ds: implement apt hooks
* remove unused import
* Apply suggestions from code review
Co-authored-by: Christian Semmler <mail@csemmler.com>
Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
* Update miniwin/src/d3drm/backends/citro3d/renderer.cpp
Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
* Separate 3DS apt hook code + move cmake 3ds into ISLE_BUILD_APP
* miniwin: use citro3dd if debugging
* Optimize texture encoding (#12)
* Cleanup
* Set correct mipmap level for UI textures (#13)
* cpack: include the .3dsx
* Add 3DS CI
* Fix CI
Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
* syntax
* Refactor c3d renderer (#14)
* Refactor c3d renderer
* format
* Apply suggestions from code review
Co-authored-by: Anders Jenbo <anders@jenbo.dk>
---------
Co-authored-by: Anders Jenbo <anders@jenbo.dk>
* n3ds: just distribute the .3dsx
* upload 3dsx
* Skip uploading 3DS artifacts
* Update ci.yml
* Update ci.yml
* Remove extraneous ifdef
---------
Co-authored-by: MaxBrick <maximusbrick@gmail.com>
Co-authored-by: Anders Jenbo <anders@jenbo.dk>
Co-authored-by: Steven <139715581+StevenSYS@users.noreply.github.com>
Co-authored-by: Christian Semmler <mail@csemmler.com>
Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
193 lines
4.5 KiB
C++
193 lines
4.5 KiB
C++
#include "d3drm_impl.h"
|
|
#include "d3drmdevice_impl.h"
|
|
#include "d3drmobject_impl.h"
|
|
#include "d3drmrenderer.h"
|
|
#include "d3drmviewport_impl.h"
|
|
#include "ddraw_impl.h"
|
|
#include "miniwin.h"
|
|
#include "miniwin/d3drm.h"
|
|
#include "miniwin/miniwindevice.h"
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
Direct3DRMDevice2Impl::Direct3DRMDevice2Impl(DWORD width, DWORD height, Direct3DRMRenderer* renderer)
|
|
: m_virtualWidth(width), m_virtualHeight(height), m_renderer(renderer), m_viewports(new Direct3DRMViewportArrayImpl)
|
|
{
|
|
Resize();
|
|
}
|
|
|
|
Direct3DRMDevice2Impl::~Direct3DRMDevice2Impl()
|
|
{
|
|
for (int i = 0; i < m_viewports->GetSize(); i++) {
|
|
IDirect3DRMViewport* viewport;
|
|
m_viewports->GetElement(i, &viewport);
|
|
static_cast<Direct3DRMViewportImpl*>(viewport)->CloseDevice();
|
|
viewport->Release();
|
|
}
|
|
m_viewports->Release();
|
|
delete m_renderer;
|
|
}
|
|
|
|
HRESULT Direct3DRMDevice2Impl::QueryInterface(const GUID& riid, void** ppvObject)
|
|
{
|
|
if (SDL_memcmp(&riid, &IID_IDirect3DRMDevice2, sizeof(riid)) == 0) {
|
|
this->IUnknown::AddRef();
|
|
*ppvObject = static_cast<IDirect3DRMDevice2*>(this);
|
|
return DD_OK;
|
|
}
|
|
else if (SDL_memcmp(&riid, &IID_IDirect3DRMMiniwinDevice, sizeof(riid)) == 0) {
|
|
this->IUnknown::AddRef();
|
|
*ppvObject = static_cast<IDirect3DRMMiniwinDevice*>(this);
|
|
return DD_OK;
|
|
}
|
|
MINIWIN_NOT_IMPLEMENTED();
|
|
return E_NOINTERFACE;
|
|
}
|
|
|
|
HRESULT Direct3DRMDevice2Impl::SetBufferCount(int count)
|
|
{
|
|
MINIWIN_NOT_IMPLEMENTED();
|
|
return DD_OK;
|
|
}
|
|
|
|
DWORD Direct3DRMDevice2Impl::GetBufferCount()
|
|
{
|
|
MINIWIN_NOT_IMPLEMENTED();
|
|
return 2;
|
|
}
|
|
|
|
HRESULT Direct3DRMDevice2Impl::SetShades(DWORD shadeCount)
|
|
{
|
|
if (shadeCount != 256) {
|
|
MINIWIN_NOT_IMPLEMENTED();
|
|
}
|
|
return DD_OK;
|
|
}
|
|
|
|
DWORD Direct3DRMDevice2Impl::GetShades()
|
|
{
|
|
return 256;
|
|
}
|
|
|
|
HRESULT Direct3DRMDevice2Impl::SetQuality(D3DRMRENDERQUALITY quality)
|
|
{
|
|
if (quality != D3DRMRENDER_GOURAUD && quality != D3DRMRENDER_PHONG) {
|
|
MINIWIN_NOT_IMPLEMENTED();
|
|
}
|
|
return DD_OK;
|
|
}
|
|
|
|
D3DRMRENDERQUALITY Direct3DRMDevice2Impl::GetQuality()
|
|
{
|
|
return D3DRMRENDERQUALITY::GOURAUD;
|
|
}
|
|
|
|
HRESULT Direct3DRMDevice2Impl::SetDither(BOOL dither)
|
|
{
|
|
if (dither) {
|
|
MINIWIN_NOT_IMPLEMENTED();
|
|
}
|
|
return DD_OK;
|
|
}
|
|
|
|
BOOL Direct3DRMDevice2Impl::GetDither()
|
|
{
|
|
MINIWIN_NOT_IMPLEMENTED();
|
|
return false;
|
|
}
|
|
|
|
HRESULT Direct3DRMDevice2Impl::SetTextureQuality(D3DRMTEXTUREQUALITY quality)
|
|
{
|
|
return DD_OK;
|
|
}
|
|
|
|
D3DRMTEXTUREQUALITY Direct3DRMDevice2Impl::GetTextureQuality()
|
|
{
|
|
return D3DRMTEXTUREQUALITY::LINEAR;
|
|
}
|
|
|
|
HRESULT Direct3DRMDevice2Impl::SetRenderMode(D3DRMRENDERMODE mode)
|
|
{
|
|
return DD_OK;
|
|
}
|
|
|
|
D3DRMRENDERMODE Direct3DRMDevice2Impl::GetRenderMode()
|
|
{
|
|
return D3DRMRENDERMODE::BLENDEDTRANSPARENCY;
|
|
}
|
|
|
|
HRESULT Direct3DRMDevice2Impl::Update()
|
|
{
|
|
MINIWIN_NOT_IMPLEMENTED();
|
|
return DD_OK;
|
|
}
|
|
|
|
HRESULT Direct3DRMDevice2Impl::AddViewport(IDirect3DRMViewport* viewport)
|
|
{
|
|
HRESULT status = m_viewports->AddElement(viewport);
|
|
Resize();
|
|
return status;
|
|
}
|
|
|
|
HRESULT Direct3DRMDevice2Impl::GetViewports(IDirect3DRMViewportArray** ppViewportArray)
|
|
{
|
|
m_viewports->AddRef();
|
|
*ppViewportArray = m_viewports;
|
|
return DD_OK;
|
|
}
|
|
|
|
ViewportTransform CalculateViewportTransform(int virtualW, int virtualH, int windowW, int windowH)
|
|
{
|
|
float scaleX = (float) windowW / virtualW;
|
|
float scaleY = (float) windowH / virtualH;
|
|
float scale = (scaleX < scaleY) ? scaleX : scaleY;
|
|
|
|
float viewportW = virtualW * scale;
|
|
float viewportH = virtualH * scale;
|
|
|
|
float offsetX = (windowW - viewportW) * 0.5f;
|
|
float offsetY = (windowH - viewportH) * 0.5f;
|
|
|
|
return {scale, offsetX, offsetY};
|
|
}
|
|
|
|
void Direct3DRMDevice2Impl::Resize()
|
|
{
|
|
int width, height;
|
|
SDL_GetWindowSizeInPixels(DDWindow, &width, &height);
|
|
#ifdef __3DS__
|
|
width = 320; // We are on the lower screen
|
|
height = 240;
|
|
#endif
|
|
m_viewportTransform = CalculateViewportTransform(m_virtualWidth, m_virtualHeight, width, height);
|
|
m_renderer->Resize(width, height, m_viewportTransform);
|
|
for (int i = 0; i < m_viewports->GetSize(); i++) {
|
|
IDirect3DRMViewport* viewport;
|
|
m_viewports->GetElement(i, &viewport);
|
|
static_cast<Direct3DRMViewportImpl*>(viewport)->UpdateProjectionMatrix();
|
|
}
|
|
}
|
|
|
|
bool Direct3DRMDevice2Impl::ConvertEventToRenderCoordinates(SDL_Event* event)
|
|
{
|
|
switch (event->type) {
|
|
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: {
|
|
Resize();
|
|
break;
|
|
}
|
|
case SDL_EVENT_MOUSE_MOTION:
|
|
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
|
case SDL_EVENT_MOUSE_BUTTON_UP: {
|
|
int rawX = event->motion.x;
|
|
int rawY = event->motion.y;
|
|
float x = (rawX - m_viewportTransform.offsetX) / m_viewportTransform.scale;
|
|
float y = (rawY - m_viewportTransform.offsetY) / m_viewportTransform.scale;
|
|
event->motion.x = static_cast<Sint32>(x);
|
|
event->motion.y = static_cast<Sint32>(y);
|
|
break;
|
|
} break;
|
|
}
|
|
|
|
return true;
|
|
}
|