Full 3ds support and fix dx9
This commit is contained in:
@@ -13,6 +13,10 @@ option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)
|
||||
option(PD_BUILD_SHARED "Build Shared Library" OFF)
|
||||
option(PD_BUILD_TOOLS "Build Palladium Tools" OFF)
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
add_compile_options(-Wno-psabi)
|
||||
endif()
|
||||
|
||||
if(${PD_BUILD_TOOLS})
|
||||
add_subdirectory(tools)
|
||||
endif()
|
||||
@@ -29,6 +33,7 @@ set(PD_SOURCES
|
||||
source/core/color.cpp
|
||||
source/core/mat.cpp
|
||||
source/core/strings.cpp
|
||||
source/core/timer.cpp
|
||||
|
||||
# Drivers
|
||||
source/drivers/os.cpp
|
||||
|
||||
@@ -55,6 +55,7 @@ struct GfxCitro3D::Impl {
|
||||
shaderProgram_s pShader;
|
||||
DVLB_s* pCode;
|
||||
int uLocProjection = 0;
|
||||
C3D_Tex* CurrentTex = nullptr;
|
||||
std::vector<u8> pShaderRaw;
|
||||
|
||||
GPU_TEXCOLOR TextureTranslateFormat(TextureFormat fmt) {
|
||||
@@ -83,14 +84,15 @@ struct GfxCitro3D::Impl {
|
||||
}
|
||||
}
|
||||
|
||||
void SetupPixelStage(GPU_TEXCOLOR clr) {
|
||||
void SetupPixelStage() {
|
||||
shaderProgramUse(&pShader);
|
||||
C3D_BindProgram(&pShader);
|
||||
C3D_SetAttrInfo(&pAttr);
|
||||
C3D_DepthTest(false, GPU_GREATER, GPU_WRITE_ALL);
|
||||
if (!CurrentTex) return;
|
||||
C3D_TexEnv* env = C3D_GetTexEnv(0);
|
||||
C3D_TexEnvInit(env);
|
||||
switch (clr) {
|
||||
switch (CurrentTex->fmt) {
|
||||
case GPU_A4:
|
||||
case GPU_A8:
|
||||
case GPU_L4:
|
||||
@@ -142,15 +144,30 @@ void GfxCitro3D::SysDeinit() {
|
||||
|
||||
void GfxCitro3D::Submit(size_t count, size_t start) {
|
||||
if (!impl) return;
|
||||
BindTexture(CurrentTex);
|
||||
impl->SetupPixelStage(); // needs to be called after
|
||||
C3D_Mtx proj;
|
||||
Mtx_OrthoTilt(&proj, 0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f, false);
|
||||
C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, impl->uLocProjection, &proj);
|
||||
// C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, impl->uLocProjection,
|
||||
// (C3D_Mtx*)&Projection);
|
||||
auto buf = C3D_GetBufInfo();
|
||||
BufInfo_Init(buf);
|
||||
BufInfo_Add(buf, GetVertexBufPtr(0), sizeof(Li::Vertex), 3, 0x210);
|
||||
C3D_DrawElements(GPU_TRIANGLES, count, C3D_UNSIGNED_SHORT,
|
||||
GetIndexBufPtr(start));
|
||||
impl->CurrentTex = nullptr;
|
||||
}
|
||||
|
||||
void GfxCitro3D::BindTexture(TextureID id) {
|
||||
if (!impl) return;
|
||||
if (!impl || !id) return;
|
||||
impl->CurrentTex = (C3D_Tex*)id;
|
||||
C3D_TexBind(0, (C3D_Tex*)id);
|
||||
}
|
||||
|
||||
void GfxCitro3D::SysReset() {
|
||||
if (!impl) return;
|
||||
C3D_CullFace(GPU_CULL_NONE);
|
||||
}
|
||||
|
||||
Li::Texture GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
@@ -210,7 +227,7 @@ Li::Texture GfxCitro3D::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
|
||||
void GfxCitro3D::DeleteTexture(const Li::Texture& tex) {
|
||||
if (!tex.GetID()) return;
|
||||
UnRegisterTexture(tex);
|
||||
UnregisterTexture(tex);
|
||||
C3D_Tex* t = reinterpret_cast<C3D_Tex*>(tex.GetID());
|
||||
C3D_TexDelete(t);
|
||||
delete t;
|
||||
|
||||
@@ -37,7 +37,7 @@ VS_OUT main(VS_IN input) {
|
||||
|
||||
static const char* g_psCode = R"(
|
||||
sampler2D tex : register(s0);
|
||||
bool alfa;
|
||||
float alfa;
|
||||
|
||||
struct PS_IN {
|
||||
float2 uv : TEXCOORD0;
|
||||
@@ -46,7 +46,7 @@ struct PS_IN {
|
||||
|
||||
float4 main(PS_IN input) : COLOR0 {
|
||||
float4 tc = tex2D(tex, input.uv);
|
||||
if (alfa)
|
||||
if (alfa > 0.5)
|
||||
return float4(input.col.rgb, tc.a * input.col.a);
|
||||
else
|
||||
return tc * input.col;
|
||||
@@ -136,6 +136,7 @@ void GfxDirectX9::SysDeinit() {
|
||||
void GfxDirectX9::Submit(size_t count, size_t start) {
|
||||
if (!impl || !impl->Device || !impl->VBO || !impl->IBO) return;
|
||||
|
||||
BindTexture(CurrentTex);
|
||||
impl->Device->SetVertexShaderConstantF(
|
||||
0, reinterpret_cast<const float*>(&Projection), 4);
|
||||
|
||||
@@ -186,7 +187,7 @@ void GfxDirectX9::SysReset() {
|
||||
Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
if (!impl || !impl->Device) return 0;
|
||||
if (!impl || !impl->Device) return Li::Texture();
|
||||
IDirect3DTexture9* tex = nullptr;
|
||||
D3DFORMAT fmt = D3DFMT_A8R8G8B8;
|
||||
if (type == TextureFormat::RGB24)
|
||||
@@ -196,7 +197,7 @@ Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
|
||||
HRESULT hr = impl->Device->CreateTexture(w, h, 1, 0, fmt, D3DPOOL_MANAGED,
|
||||
&tex, nullptr);
|
||||
if (FAILED(hr) || !tex) return 0;
|
||||
if (FAILED(hr) || !tex) return Li::Texture();
|
||||
|
||||
D3DLOCKED_RECT rect;
|
||||
tex->LockRect(0, &rect, nullptr, 0);
|
||||
@@ -209,7 +210,7 @@ Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
u8 r = pixels[(y * w + x) * 3 + 0];
|
||||
u8 g = pixels[(y * w + x) * 3 + 1];
|
||||
u8 b = pixels[(y * w + x) * 3 + 2];
|
||||
dst[x] = (0xFF << 24) | (r << 16) | (g << 8) | b; // X8R8G8B8
|
||||
dst[x] = (0xFF << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
dstRow += rect.Pitch;
|
||||
}
|
||||
@@ -222,7 +223,7 @@ Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
u8 g = pixels[(y * w + x) * 4 + 1];
|
||||
u8 b = pixels[(y * w + x) * 4 + 2];
|
||||
u8 a = pixels[(y * w + x) * 4 + 3];
|
||||
dst[x] = (a << 24) | (r << 16) | (g << 8) | b; // A8R8G8B8
|
||||
dst[x] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
dstRow += rect.Pitch;
|
||||
}
|
||||
@@ -246,7 +247,7 @@ Li::Texture GfxDirectX9::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
|
||||
void GfxDirectX9::DeleteTexture(const Li::Texture& tex) {
|
||||
if (!tex.GetID()) return;
|
||||
UnRegisterTexture(tex);
|
||||
UnregisterTexture(tex);
|
||||
IDirect3DTexture9* t = (IDirect3DTexture9*)tex.GetID();
|
||||
t->Release();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
#ifndef __3DS__
|
||||
#ifdef __3DS__
|
||||
#include <3ds.h>
|
||||
#include <citro3d.h>
|
||||
const u32 DisplayTransferFlags =
|
||||
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) |
|
||||
GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) |
|
||||
GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) |
|
||||
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO));
|
||||
#else
|
||||
#include <glad/glad.h>
|
||||
//////////////////////////
|
||||
#include <GLFW/glfw3.h>
|
||||
@@ -80,6 +88,15 @@ class App {
|
||||
#endif
|
||||
glfwSwapInterval(1);
|
||||
#else
|
||||
gfxInitDefault();
|
||||
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
|
||||
Top =
|
||||
C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
|
||||
Bottom =
|
||||
C3D_RenderTargetCreate(240, 320, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetOutput(Top, GFX_TOP, GFX_LEFT, DisplayTransferFlags);
|
||||
C3D_RenderTargetSetOutput(Bottom, GFX_BOTTOM, GFX_LEFT,
|
||||
DisplayTransferFlags);
|
||||
PD::Gfx::UseDriver<PD::GfxCitro3D>();
|
||||
#endif
|
||||
PD::Gfx::Init();
|
||||
@@ -97,13 +114,14 @@ class App {
|
||||
cmd->Reserve(4, 6);
|
||||
cmd->Add(0, 1, 2);
|
||||
cmd->Add(0, 2, 3);
|
||||
cmd->Add(PD::Li::Vertex(PD::fvec2(0, 0), PD::fvec2(0, 0), 0xffffffff));
|
||||
cmd->Add(PD::Li::Vertex(PD::fvec2(pTex.GetSize().x, 0), PD::fvec2(1, 0),
|
||||
0xffffffff));
|
||||
cmd->Add(
|
||||
PD::Li::Vertex(PD::fvec2(0, 0), pTex.GetUV().TopLeft(), 0xffffffff));
|
||||
cmd->Add(PD::Li::Vertex(PD::fvec2(pTex.GetSize().x, 0),
|
||||
pTex.GetUV().TopRight(), 0xffffffff));
|
||||
cmd->Add(PD::Li::Vertex(PD::fvec2(pTex.GetSize().x, pTex.GetSize().y),
|
||||
PD::fvec2(1, 1), 0xffffffff));
|
||||
cmd->Add(PD::Li::Vertex(PD::fvec2(0, pTex.GetSize().y), PD::fvec2(0, 1),
|
||||
0xffffffff));
|
||||
pTex.GetUV().BotRight(), 0xffffffff));
|
||||
cmd->Add(PD::Li::Vertex(PD::fvec2(0, pTex.GetSize().y),
|
||||
pTex.GetUV().BotLeft(), 0xffffffff));
|
||||
cmd->Tex = pTex.GetID();
|
||||
}
|
||||
~App() {
|
||||
@@ -118,8 +136,13 @@ class App {
|
||||
void Run() {
|
||||
#ifdef __3DS__
|
||||
while (aptMainLoop()) {
|
||||
PD::Gfx::SetViewPort(400, 240);
|
||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||
C3D_FrameDrawOn(Top);
|
||||
C3D_RenderTargetClear(Top, C3D_CLEAR_ALL, PD::Color(25, 25, 25, 25), 0);
|
||||
#else
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
PD::Gfx::SetViewPort(1280, 720);
|
||||
if (pDriver == Driver::OpenGL2 || pDriver == Driver::OpenGL3) {
|
||||
glClearColor(0.1, 0.1, 0.1, 0.1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
@@ -135,9 +158,10 @@ class App {
|
||||
}
|
||||
#endif
|
||||
PD::Gfx::Reset();
|
||||
PD::Gfx::SetViewPort(1280, 720);
|
||||
|
||||
PD::Gfx::Draw(pPool);
|
||||
#ifdef __3DS__
|
||||
C3D_FrameEnd(0);
|
||||
#else
|
||||
glfwPollEvents();
|
||||
if (pDriver == Driver::DirectX9) {
|
||||
@@ -155,7 +179,10 @@ class App {
|
||||
}
|
||||
|
||||
private:
|
||||
#ifndef __3DS__
|
||||
#ifdef __3DS__
|
||||
C3D_RenderTarget* Top = nullptr;
|
||||
C3D_RenderTarget* Bottom = nullptr;
|
||||
#else
|
||||
GLFWwindow* window = nullptr;
|
||||
#endif
|
||||
PD::Pool<PD::Li::Command> pPool;
|
||||
|
||||
Reference in New Issue
Block a user