Work at 3ds support and backend upgrades
- Track textures (not sure if this is done tbh) - Add lithium formatters and move TextureID, TextureFormat and TextureFilter to lithium - Only include gl-helper if any glDriver is included - Add Li::Rect for UV stuff - Add Li::Texture as Info holder (still thinking of making them to ptrs - Add Check if textures are still loaded on exit
This commit is contained in:
@@ -3,4 +3,8 @@ cmake_minimum_required(VERSION 3.22)
|
||||
project(gfx-tests)
|
||||
|
||||
add_executable(gfx-tests ${CMAKE_CURRENT_SOURCE_DIR}/source/main.cpp)
|
||||
target_link_libraries(gfx-tests PRIVATE palladium::palladium pd-system glfw stb)
|
||||
target_link_libraries(gfx-tests PRIVATE palladium::palladium pd-system stb)
|
||||
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
target_link_libraries(gfx-tests PRIVATE glfw)
|
||||
endif()
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
#ifndef __3DS__
|
||||
#include <glad/glad.h>
|
||||
//////////////////////////
|
||||
#include <GLFW/glfw3.h>
|
||||
#endif
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <palladium>
|
||||
#include <pdsystem>
|
||||
|
||||
#include "pd/core/vec2.hpp"
|
||||
#include "pd/lithium/pools.hpp"
|
||||
#include "pd/lithium/vertex.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <d3d9.h>
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
@@ -27,7 +25,7 @@ enum class Driver {
|
||||
DirectX9 = 3,
|
||||
};
|
||||
|
||||
PD::TextureID LoadTex(const std::string& path) {
|
||||
PD::Li::Texture LoadTex(const std::string& path) {
|
||||
int w, h, c;
|
||||
stbi_uc* buf = stbi_load(path.c_str(), &w, &h, &c, 4);
|
||||
return PD::Gfx::LoadTexture(std::vector<PD::u8>(buf, buf + (w * h * 4)), w,
|
||||
@@ -38,6 +36,7 @@ class App {
|
||||
public:
|
||||
App(Driver d = Driver::OpenGL3) : pDriver(d) {
|
||||
PD::Os::UseDriver<PD::OsDriver>();
|
||||
#ifndef __3DS__
|
||||
glfwInit();
|
||||
std::string winname = "gfx_test";
|
||||
if (d == Driver::OpenGL2) {
|
||||
@@ -80,9 +79,16 @@ class App {
|
||||
}
|
||||
#endif
|
||||
glfwSwapInterval(1);
|
||||
#else
|
||||
PD::Gfx::UseDriver<PD::GfxCitro3D>();
|
||||
#endif
|
||||
PD::Gfx::Init();
|
||||
PD::Li::InitPools(8192);
|
||||
#ifdef __3DS__
|
||||
pTex = LoadTex("sdmc:/icon.png");
|
||||
#else
|
||||
pTex = LoadTex("icon.png");
|
||||
#endif
|
||||
/*std::vector<PD::u8> img(16 * 16 * 4, 0xff);
|
||||
pTex = PD::Gfx::LoadTexture(img, 16, 16);*/
|
||||
std::cout << "GfxDriver: " << PD::Gfx::GetDriverName() << std::endl;
|
||||
@@ -92,18 +98,27 @@ class App {
|
||||
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(256, 0), PD::fvec2(1, 0), 0xffffffff));
|
||||
cmd->Add(PD::Li::Vertex(PD::fvec2(256, 256), PD::fvec2(1, 1), 0xffffffff));
|
||||
cmd->Add(PD::Li::Vertex(PD::fvec2(0, 256), PD::fvec2(0, 1), 0xffffffff));
|
||||
cmd->Tex = pTex;
|
||||
cmd->Add(PD::Li::Vertex(PD::fvec2(pTex.GetSize().x, 0), PD::fvec2(1, 0),
|
||||
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));
|
||||
cmd->Tex = pTex.GetID();
|
||||
}
|
||||
~App() {
|
||||
PD::Gfx::DeleteTexture(pTex);
|
||||
PD::Gfx::Deinit();
|
||||
#ifndef __3DS__
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Run() {
|
||||
#ifdef __3DS__
|
||||
while (aptMainLoop()) {
|
||||
#else
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
if (pDriver == Driver::OpenGL2 || pDriver == Driver::OpenGL3) {
|
||||
glClearColor(0.1, 0.1, 0.1, 0.1);
|
||||
@@ -118,9 +133,12 @@ class App {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
PD::Gfx::Reset();
|
||||
PD::Gfx::SetViewPort(1280, 720);
|
||||
PD::Gfx::Draw(pPool);
|
||||
#ifdef __3DS__
|
||||
#else
|
||||
glfwPollEvents();
|
||||
if (pDriver == Driver::DirectX9) {
|
||||
#ifdef _WIN32
|
||||
@@ -132,13 +150,16 @@ class App {
|
||||
} else {
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
#ifndef __3DS__
|
||||
GLFWwindow* window = nullptr;
|
||||
#endif
|
||||
PD::Pool<PD::Li::Command> pPool;
|
||||
PD::ptr pTex = 0;
|
||||
PD::Li::Texture pTex;
|
||||
Driver pDriver;
|
||||
#ifdef _WIN32
|
||||
IDirect3D9* d3d = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user