Compare commits
2
Commits
3b0b103eb3
...
baad2ce15c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
baad2ce15c
|
||
|
|
a86c13b9a3
|
@@ -236,7 +236,7 @@ void GfxCitro3D::DeleteTexture(const Li::Texture& tex) {
|
||||
#else
|
||||
namespace PD {
|
||||
void GfxCitro3D::SysInit() {
|
||||
PDLOG(
|
||||
PDERR(
|
||||
"GfxCitro3D::SysInit: Citro3D Driver is not included in "
|
||||
"palladium-system");
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ void GfxDirectX9::SysInit() {
|
||||
HRESULT hr = D3DCompile(g_vsCode, strlen(g_vsCode), nullptr, nullptr,
|
||||
nullptr, "main", "vs_2_0", 0, 0, &vsBlob, &errBlob);
|
||||
if (FAILED(hr)) {
|
||||
PDLOG("Vertex Shader compile error: {}",
|
||||
PDERR("Vertex Shader compile error: {}",
|
||||
errBlob ? (char*)errBlob->GetBufferPointer() : "");
|
||||
} else {
|
||||
impl->Device->CreateVertexShader((DWORD*)vsBlob->GetBufferPointer(),
|
||||
@@ -109,7 +109,7 @@ void GfxDirectX9::SysInit() {
|
||||
if (psBlob) psBlob->Release();
|
||||
if (errBlob) errBlob->Release();
|
||||
} else {
|
||||
PDLOG(
|
||||
PDERR(
|
||||
"GfxDirectX9::SysInit Error: pDevice is not set!\nYOu need to include "
|
||||
"your D3D9 Device as "
|
||||
"folowing:\nPD::Gfx::UseDriver<PD::GfxDirectX9>(D3D9Device);");
|
||||
@@ -276,7 +276,7 @@ void GfxDirectX9::DeleteTexture(const Li::Texture& tex) {
|
||||
#else
|
||||
namespace PD {
|
||||
void GfxDirectX9::SysInit() {
|
||||
PDLOG(
|
||||
PDERR(
|
||||
"GfxDirectX9::SysInit: DirectX9 Driver is not included in "
|
||||
"palladium-system");
|
||||
}
|
||||
|
||||
@@ -82,10 +82,6 @@ void GfxOpenGL2::SysInit() {
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
PDLOG(
|
||||
"GfxOpenGL2::SysInit():\n pShader = {}\n pLocTex = {}\n pLocAlfa = "
|
||||
"{}\n pLocProjection = {}\n VBO = {}\n IBO = {}",
|
||||
pShader, pLocTex, pLocAlfa, pLocProjection, VBO, IBO);
|
||||
}
|
||||
|
||||
void GfxOpenGL2::SysDeinit() {
|
||||
@@ -172,7 +168,7 @@ void GfxOpenGL2::DeleteTexture(const Li::Texture& tex) {
|
||||
#else
|
||||
namespace PD {
|
||||
void GfxOpenGL2::SysInit() {
|
||||
PDLOG(
|
||||
PDERR(
|
||||
"GfxOpenGL2::SysInit: OpenGL2 Driver is not included in "
|
||||
"palladium-system");
|
||||
}
|
||||
|
||||
@@ -52,10 +52,6 @@ void GfxOpenGL3::SysInit() {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
PDLOG(
|
||||
"GfxOpenGL3::SysInit():\n pShader = {}\n pLocTex = {}\n pLocAlfa = "
|
||||
"{}\n pLocProjection = {}\n VBO = {}\n IBO = {}, VAO = {}",
|
||||
pShader, pLocTex, pLocAlfa, pLocProjection, VBO, IBO, VAO);
|
||||
}
|
||||
|
||||
void GfxOpenGL3::SysDeinit() {
|
||||
@@ -142,7 +138,7 @@ void GfxOpenGL3::DeleteTexture(const Li::Texture& tex) {
|
||||
#else
|
||||
namespace PD {
|
||||
void GfxOpenGL3::SysInit() {
|
||||
PDLOG(
|
||||
PDERR(
|
||||
"GfxOpenGL3::SysInit: OpenGL3 Driver is not included in "
|
||||
"palladium-system");
|
||||
}
|
||||
|
||||
+42
-2
@@ -23,6 +23,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#if defined(__GNUG__) && !defined(_MSC_VER)
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
@@ -39,6 +43,11 @@ SOFTWARE.
|
||||
#include <vector>
|
||||
|
||||
namespace PD {
|
||||
enum class LogLevel {
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
};
|
||||
[[noreturn]] inline void Throw(const std::string& msg) {
|
||||
throw std::runtime_error(msg);
|
||||
}
|
||||
@@ -47,17 +56,48 @@ using u16 = unsigned short;
|
||||
using u32 = unsigned int;
|
||||
using u64 = unsigned long long;
|
||||
using ptr = uintptr_t;
|
||||
PD_API void Log(const std::string& txt);
|
||||
PD_API void Log(const std::string& txt, LogLevel lvl = LogLevel::Info);
|
||||
template <typename... Args>
|
||||
void Log(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::string msg = std::format(fmt, std::forward<Args>(args)...);
|
||||
Log(msg);
|
||||
Log(msg, LogLevel::Info);
|
||||
}
|
||||
template <typename... Args>
|
||||
void Log(LogLevel lvl, std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::string msg = std::format(fmt, std::forward<Args>(args)...);
|
||||
Log(msg, lvl);
|
||||
}
|
||||
template <typename T>
|
||||
std::string TypeName() {
|
||||
#if defined(__GNUG__) && !defined(_MSC_VER)
|
||||
int res = 0;
|
||||
std::unique_ptr<char, void (*)(void*)> up{
|
||||
abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &res), std::free};
|
||||
return (res == 0) ? up.get() : typeid(T).name();
|
||||
#else
|
||||
return typeid(T).name(); // no demangler available :/
|
||||
#endif
|
||||
}
|
||||
} // namespace PD
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define PDPRETTYFUNC __PRETTY_FUNCTION__
|
||||
#elif defined(_MSC_VER)
|
||||
#define PDPRETTYFUNC __FUNCSIG__
|
||||
#else
|
||||
#define PDPRETTYFUNC __FUNCTION__
|
||||
#endif
|
||||
#ifdef PD_DEBUG
|
||||
#define PDLOG(fmt, ...) \
|
||||
PD::Log("[{}:{}]: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#define PDWARN(fmt, ...) \
|
||||
PD::Log(PD::LogLevel::Warning, "[{}:{}]: " fmt, __FILE__, __LINE__, \
|
||||
##__VA_ARGS__)
|
||||
#define PDERR(fmt, ...) \
|
||||
PD::Log(PD::LogLevel::Error, "[{}:{}]: " fmt, __FILE__, __LINE__, \
|
||||
##__VA_ARGS__)
|
||||
#else
|
||||
#define PDLOG(fmt, ...)
|
||||
#define PDWARN(fmt, ...)
|
||||
#define PDERR(fmt, ...)
|
||||
#endif
|
||||
@@ -3,6 +3,11 @@
|
||||
#include <memory>
|
||||
#include <pd/common.hpp>
|
||||
namespace PD {
|
||||
// lets take use of c++ 20 concepts
|
||||
// https://en.cppreference.com/w/cpp/language/constraints.html
|
||||
template <typename T>
|
||||
concept Resettable = requires(T& v) { v.Reset(); };
|
||||
|
||||
template <typename T, typename Alloc = std::allocator<T>>
|
||||
class Pool {
|
||||
public:
|
||||
@@ -13,6 +18,9 @@ class Pool {
|
||||
Pool() = default;
|
||||
~Pool() {
|
||||
if (pData) {
|
||||
for (size_t i = 0; i < pCap; i++) {
|
||||
std::allocator_traits<Alloc>::destroy(pAlloc, &pData[i]);
|
||||
}
|
||||
pAlloc.deallocate(pData, pCap);
|
||||
pData = nullptr;
|
||||
}
|
||||
@@ -47,6 +55,11 @@ class Pool {
|
||||
*e = elem;
|
||||
}
|
||||
|
||||
void Put(size_t idx, const T& elem) {
|
||||
if (idx >= pCap) ExpandIf(idx);
|
||||
pData[idx] = elem;
|
||||
}
|
||||
|
||||
void ExpandIf(size_t req) {
|
||||
if ((pPos + req) <= pCap) return;
|
||||
size_t ncap = std::max(pCap * 2, pPos + req);
|
||||
@@ -56,6 +69,9 @@ class Pool {
|
||||
std::allocator_traits<Alloc>::construct(
|
||||
pAlloc, &nu[i], std::move_if_noexcept(pData[i]));
|
||||
}
|
||||
for (size_t i = 0; i < pCap; i++) {
|
||||
std::allocator_traits<Alloc>::destroy(pAlloc, &pData[i]);
|
||||
}
|
||||
pAlloc.deallocate(pData, pCap);
|
||||
}
|
||||
for (size_t i = pPos; i < ncap; i++) {
|
||||
@@ -76,6 +92,21 @@ class Pool {
|
||||
}
|
||||
}
|
||||
|
||||
void ResetFast() {
|
||||
if constexpr (Resettable<T>) {
|
||||
for (size_t i = 0; i < pPos; i++) {
|
||||
pData[i].Reset();
|
||||
}
|
||||
} else if constexpr (!std::is_trivially_destructible_v<T>) {
|
||||
PDWARN(
|
||||
"ResetFast should only be executed with a non destructible type or a "
|
||||
"class/struct that has a Reset func! {} is not "
|
||||
"trivially_destructible and has no reset func.",
|
||||
TypeName<T>());
|
||||
}
|
||||
pPos = 0;
|
||||
}
|
||||
|
||||
size_t size() const { return pPos; }
|
||||
size_t capacity() const { return pCap; }
|
||||
T& at(size_t idx) { return pData[idx]; }
|
||||
@@ -89,7 +120,16 @@ class Pool {
|
||||
const T& operator[](size_t idx) const { return at(idx); }
|
||||
|
||||
private:
|
||||
Pool(size_t size) : pCap(size), pPos(0) { pData = pAlloc.allocate(size); }
|
||||
Pool(size_t size) : pCap(size), pPos(0) {
|
||||
pPos = 0;
|
||||
pCap = size;
|
||||
pData = pAlloc.allocate(size);
|
||||
for (size_t i = 0; i < pCap; i++) {
|
||||
std::allocator_traits<Alloc>::construct(pAlloc, &pData[i]);
|
||||
}
|
||||
PDLOG("Pool::Init({})", size);
|
||||
}
|
||||
|
||||
size_t pCap = 0;
|
||||
size_t pPos = 0;
|
||||
Alloc pAlloc;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <pd/core/mat.hpp>
|
||||
#include <pd/drivers/interface.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/pools.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
using PDBackendFlags = PD::u32;
|
||||
@@ -105,12 +106,12 @@ class GfxDriverBase : public GfxDriver {
|
||||
auto pIdx = pIdxPool.Allocate(c.IndexCount);
|
||||
auto pVtx = pVtxPool.Allocate(c.VertexCount);
|
||||
for (size_t i = 0; i < c.IndexCount; i++) {
|
||||
pIdx[i] = CurrentVertex + c.FirstIndex[i];
|
||||
pIdx[i] = CurrentVertex + Li::GetIndex(c.FirstIndex + i);
|
||||
}
|
||||
CurrentIndex += c.IndexCount;
|
||||
CurrentVertex += c.VertexCount;
|
||||
for (size_t i = 0; i < c.VertexCount; i++) {
|
||||
pVtx[i] = c.FirstVertex[i];
|
||||
pVtx[i] = Li::GetVertex(c.FirstVertex + i);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
@@ -124,8 +125,8 @@ class GfxDriverBase : public GfxDriver {
|
||||
size_t GetVertexPoolSize() const { return pVtxPool.size(); }
|
||||
size_t GetIndexPoolSize() const { return pIdxPool.size(); }
|
||||
void ResetPools() override {
|
||||
pVtxPool.Reset();
|
||||
pIdxPool.Reset();
|
||||
pVtxPool.ResetFast();
|
||||
pIdxPool.ResetFast();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -13,44 +13,58 @@ class Command {
|
||||
~Command() {}
|
||||
|
||||
void Reserve(size_t vtx, size_t idx) {
|
||||
if (!FirstVertex)
|
||||
FirstVertex = AllocateVertices(vtx);
|
||||
else
|
||||
AllocateVertices(vtx);
|
||||
if (!FirstIndex)
|
||||
FirstIndex = AllocateIndices(idx);
|
||||
else
|
||||
AllocateIndices(idx);
|
||||
if (!FirstVertex) {
|
||||
FirstVertex = AllocateVertices(vtx, (PD::ptr)this);
|
||||
VertexCountMax = vtx;
|
||||
} else {
|
||||
ExpandVertices(vtx, (PD::ptr)this);
|
||||
VertexCountMax += vtx;
|
||||
}
|
||||
if (!FirstIndex) {
|
||||
FirstIndex = AllocateIndices(idx, (PD::ptr)this);
|
||||
IndexCountMax = idx;
|
||||
} else {
|
||||
ExpandVertices(idx, (PD::ptr)this);
|
||||
IndexCountMax += idx;
|
||||
}
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
Layer = 0;
|
||||
Tex = 0;
|
||||
FirstIndex = nullptr;
|
||||
FirstVertex = nullptr;
|
||||
FirstIndex = 0;
|
||||
FirstVertex = 0;
|
||||
IndexCount = 0;
|
||||
VertexCount = 0;
|
||||
VertexCountMax = 0;
|
||||
IndexCountMax = 0;
|
||||
}
|
||||
|
||||
Command& Add(const Vertex& vtx) {
|
||||
FirstVertex[VertexCount++] = vtx;
|
||||
if (VertexCount <= VertexCountMax)
|
||||
PutVertex(FirstVertex + VertexCount++, vtx, (PD::ptr)this);
|
||||
return *this;
|
||||
}
|
||||
Command& Add(u16 idx) {
|
||||
FirstIndex[IndexCount++] = VertexCount + idx;
|
||||
if (IndexCount <= IndexCountMax)
|
||||
PutIndex(FirstIndex + IndexCount++, VertexCount + idx, (PD::ptr)this);
|
||||
return *this;
|
||||
}
|
||||
Command& Add(u16 a, u16 b, u16 c) {
|
||||
FirstIndex[IndexCount++] = VertexCount + a;
|
||||
FirstIndex[IndexCount++] = VertexCount + b;
|
||||
FirstIndex[IndexCount++] = VertexCount + c;
|
||||
if (IndexCount + 3 <= IndexCountMax) {
|
||||
size_t idx = FirstIndex + IndexCount;
|
||||
PutIndex(idx + 0, VertexCount + a, (PD::ptr)this);
|
||||
PutIndex(idx + 1, VertexCount + b, (PD::ptr)this);
|
||||
PutIndex(idx + 2, VertexCount + c, (PD::ptr)this);
|
||||
IndexCount += 3;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
int Layer = 0;
|
||||
ptr Tex = 0;
|
||||
Vertex* FirstVertex = nullptr;
|
||||
u16* FirstIndex = nullptr;
|
||||
size_t FirstVertex = 0;
|
||||
size_t FirstIndex = 0;
|
||||
size_t VertexCount = 0;
|
||||
size_t IndexCount = 0;
|
||||
// Todo: implement
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/lithium/atlas.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/rect.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
#include <pd/lithium/vertex.hpp>
|
||||
@@ -107,3 +108,15 @@ struct std::formatter<PD::Li::AtlasState> : std::formatter<std::string> {
|
||||
return std::format_to(ctx.out(), "{}", ret);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter<PD::Li::Command> : std::formatter<std::string> {
|
||||
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const PD::Li::Command& value, FormatContext& ctx) const {
|
||||
return std::format_to(ctx.out(), "[0x{:X}, 0x{:X}] [{}, {}] 0x{:X}",
|
||||
(PD::ptr)value.FirstVertex, (PD::ptr)value.FirstIndex,
|
||||
value.VertexCount, value.IndexCount, value.Tex);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,8 +5,22 @@
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
PD_API Vertex* AllocateVertices(size_t count);
|
||||
PD_API u16* AllocateIndices(size_t count);
|
||||
/**
|
||||
* Allocate an amount of vertices
|
||||
* returns the index of the first vertex
|
||||
*/
|
||||
PD_API size_t AllocateVertices(size_t count, PD::ptr accessor);
|
||||
/**
|
||||
* Allocate an amount of indices
|
||||
* returns the index of the first elem
|
||||
*/
|
||||
PD_API size_t AllocateIndices(size_t count, PD::ptr accessor);
|
||||
PD_API bool ExpandVertices(size_t count, PD::ptr accessor);
|
||||
PD_API bool EcpandIndices(size_t count, PD::ptr accessor);
|
||||
PD_API void PutVertex(size_t loc, const Vertex& vtx, PD::ptr accessor);
|
||||
PD_API void PutIndex(size_t loc, u16 idx, PD::ptr accessor);
|
||||
PD_API const Vertex& GetVertex(size_t loc);
|
||||
PD_API const u16& GetIndex(size_t loc);
|
||||
PD_API void ResetPools();
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
@@ -11,6 +11,12 @@ class Vertex {
|
||||
: pos(pos), uv(uv), color(color) {}
|
||||
~Vertex() {}
|
||||
|
||||
void Reset() {
|
||||
pos = fvec2(0.f);
|
||||
uv = fvec2(0.f);
|
||||
color = 0x00000000;
|
||||
}
|
||||
|
||||
fvec2 pos;
|
||||
fvec2 uv;
|
||||
u32 color = 0x00000000;
|
||||
|
||||
+26
-2
@@ -1,6 +1,30 @@
|
||||
#include <iostream>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
PD_API void PD::Log(const std::string& txt) {
|
||||
std::cout << "[PD] " << txt << std::endl;
|
||||
namespace PD {
|
||||
constexpr const char* pColorNo = "\033[0m";
|
||||
constexpr const char* pColorYellow = "\033[33m";
|
||||
constexpr const char* pColorRed = "\033[31m";
|
||||
static LogLevel pFilter = LogLevel::Info;
|
||||
PD_API void Log(const std::string& txt, LogLevel lvl) {
|
||||
if ((int)lvl < (int)pFilter) return;
|
||||
const char* clr = pColorNo;
|
||||
const char* plvl = "INFO";
|
||||
switch (lvl) {
|
||||
case PD::LogLevel::Info:
|
||||
clr = pColorNo;
|
||||
plvl = "INFO";
|
||||
break;
|
||||
case PD::LogLevel::Warning:
|
||||
clr = pColorYellow;
|
||||
plvl = "WARNING";
|
||||
break;
|
||||
case PD::LogLevel::Error:
|
||||
clr = pColorRed;
|
||||
plvl = "ERROR";
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << clr << "[PD][" << plvl << "] " << txt << pColorNo << std::endl;
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -8,7 +8,7 @@ PD_API GfxDriver::GfxDriver(std::string_view name) : DriverInterface(name) {}
|
||||
|
||||
PD_API GfxDriver::~GfxDriver() {
|
||||
if (pTextureRegestry.size()) {
|
||||
PDLOG("GfxDriver: {} is still holding {} texture{}!", GetName(),
|
||||
PDERR("GfxDriver: {} is still holding {} texture{}!", GetName(),
|
||||
pTextureRegestry.size(), (pTextureRegestry.size() == 1 ? "" : "s"));
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ PD_API void GfxDriver::UnregisterTexture(const Li::Texture& tex) {
|
||||
pTextureRegestry.erase(pTextureRegestry.find(tex.GetID()));
|
||||
PDLOG("GfxDriver: Texture {{ {} }} has been deleted!", tex);
|
||||
} else {
|
||||
PDLOG("GfxDriver: WARNING Texture {{ {} }} does not exist in regestry!",
|
||||
PDWARN("GfxDriver: WARNING Texture {{ {} }} does not exist in regestry!",
|
||||
tex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
#include <pd/lithium/drawlist.hpp>
|
||||
#include <pd/lithium/formatters.hpp>
|
||||
#include <pd/lithium/math.hpp>
|
||||
|
||||
namespace PD {
|
||||
@@ -16,9 +18,10 @@ PD_API void Drawlist::Optimize() {}
|
||||
|
||||
PD_API void Drawlist::Clear() {
|
||||
UnbindTexture();
|
||||
pPath.Reset();
|
||||
pVertices.Reset();
|
||||
pIndices.Reset();
|
||||
pPath.ResetFast();
|
||||
pVertices.ResetFast();
|
||||
pIndices.ResetFast();
|
||||
pCommands.ResetFast();
|
||||
}
|
||||
|
||||
/** Command Allocation */
|
||||
|
||||
@@ -5,12 +5,56 @@ namespace PD {
|
||||
namespace Li {
|
||||
PD::Pool<Vertex> pVtxPool;
|
||||
PD::Pool<u16> pIdxPool;
|
||||
PD::ptr pVertexAccessor = 0;
|
||||
PD::ptr pIndexAccessor = 0;
|
||||
|
||||
PD_API Vertex* AllocateVertices(size_t count) {
|
||||
return pVtxPool.Allocate(count);
|
||||
PD_API size_t AllocateVertices(size_t count, PD::ptr accessor) {
|
||||
pVertexAccessor = accessor;
|
||||
int loc = pVtxPool.size();
|
||||
pVtxPool.Allocate(count);
|
||||
return loc;
|
||||
}
|
||||
|
||||
PD_API u16* AllocateIndices(size_t count) { return pIdxPool.Allocate(count); }
|
||||
PD_API size_t AllocateIndices(size_t count, PD::ptr accessor) {
|
||||
pIndexAccessor = accessor;
|
||||
int loc = pIdxPool.size();
|
||||
pIdxPool.Allocate(count);
|
||||
return loc;
|
||||
}
|
||||
|
||||
PD_API bool ExpandVertices(size_t count, PD::ptr accessor) {
|
||||
if (pVertexAccessor != accessor) return false;
|
||||
pVtxPool.Allocate(count);
|
||||
return true;
|
||||
}
|
||||
|
||||
PD_API bool EcpandIndices(size_t count, PD::ptr accessor) {
|
||||
if (pIndexAccessor != accessor) return false;
|
||||
pVtxPool.Allocate(count);
|
||||
return true;
|
||||
}
|
||||
|
||||
PD_API void PutVertex(size_t loc, const Vertex& vtx, PD::ptr accessor) {
|
||||
if (pVertexAccessor != accessor) return;
|
||||
pVtxPool.Put(loc, vtx);
|
||||
}
|
||||
|
||||
PD_API void PutIndex(size_t loc, u16 idx, PD::ptr accessor) {
|
||||
if (pIndexAccessor != accessor) return;
|
||||
pIdxPool.Put(loc, idx);
|
||||
}
|
||||
|
||||
PD_API const Vertex& GetVertex(size_t loc) {
|
||||
if (loc < pVtxPool.size()) return pVtxPool[loc];
|
||||
static Vertex pErrVtx;
|
||||
return pErrVtx;
|
||||
}
|
||||
|
||||
PD_API const u16& GetIndex(size_t loc) {
|
||||
if (loc < pIdxPool.size()) return pIdxPool[loc];
|
||||
static u16 pErrIdx = 0;
|
||||
return pErrIdx;
|
||||
}
|
||||
|
||||
PD_API void ResetPools() {
|
||||
pVtxPool.Reset();
|
||||
|
||||
@@ -2,8 +2,16 @@ cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(gfx-tests)
|
||||
|
||||
add_executable(gfx-tests ${CMAKE_CURRENT_SOURCE_DIR}/source/main.cpp)
|
||||
add_executable(gfx-tests
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/main.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/os/horizon-nx.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/os/horizon-ctr.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/os/desktopos.cpp
|
||||
)
|
||||
target_link_libraries(gfx-tests PRIVATE palladium::palladium pd-system stb)
|
||||
target_include_directories(gfx-tests
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
target_link_libraries(gfx-tests PRIVATE ctru)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <palladium>
|
||||
|
||||
enum class Driver {
|
||||
Unknown = 0,
|
||||
OpenGL2 = 1,
|
||||
OpenGL3 = 2,
|
||||
DirectX9 = 3,
|
||||
Citro3D = 4,
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
class OsCtx {
|
||||
public:
|
||||
OsCtx(Driver d) : pDriver(d) {}
|
||||
virtual ~OsCtx() {}
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual bool Mainloop() { return false; }
|
||||
virtual void ClearViewPort() {}
|
||||
virtual void SwapBuffers() {}
|
||||
PD::fvec2 SizeTranslate(PD::fvec2 in) {
|
||||
return fvec2(in.x * pViewPort.x, in.y * pViewPort.y);
|
||||
}
|
||||
|
||||
protected:
|
||||
PD::ivec2 pViewPort;
|
||||
const Driver pDriver;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <os-ctx.hpp>
|
||||
|
||||
namespace PD {
|
||||
class DesktopOS : public PD::OsCtx {
|
||||
public:
|
||||
DesktopOS(Driver d = Driver::OpenGL3) : PD::OsCtx(d) {}
|
||||
~DesktopOS() {}
|
||||
|
||||
void Init() override;
|
||||
void Deinit() override;
|
||||
bool Mainloop() override;
|
||||
void ClearViewPort() override;
|
||||
void SwapBuffers() override;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
Impl* impl = nullptr;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <os-ctx.hpp>
|
||||
|
||||
namespace PD {
|
||||
class HorizonCtr : public PD::OsCtx {
|
||||
public:
|
||||
HorizonCtr(Driver d = Driver::Citro3D) : PD::OsCtx(d) {}
|
||||
~HorizonCtr() {}
|
||||
|
||||
void Init() override;
|
||||
void Deinit() override;
|
||||
bool Mainloop() override;
|
||||
void ClearViewPort() override;
|
||||
void SwapBuffers() override;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
Impl* impl = nullptr;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include <os-ctx.hpp>
|
||||
|
||||
namespace PD {
|
||||
class HorizonNX : public PD::OsCtx {
|
||||
public:
|
||||
HorizonNX(Driver d = Driver::OpenGL3) : PD::OsCtx(d) {}
|
||||
~HorizonNX() {}
|
||||
|
||||
void Init() override;
|
||||
void Deinit() override;
|
||||
bool Mainloop() override;
|
||||
void ClearViewPort() override;
|
||||
void SwapBuffers() override;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
Impl* impl = nullptr;
|
||||
};
|
||||
} // namespace PD
|
||||
+33
-238
@@ -1,246 +1,21 @@
|
||||
#if defined(__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));
|
||||
#elif defined(__SWITCH__)
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/glad.h>
|
||||
#include <stdio.h>
|
||||
#include <switch.h>
|
||||
|
||||
static void errorCallback(int errorCode, const char* description) {
|
||||
printf("Glfw Error %d: %s\n", errorCode, description);
|
||||
}
|
||||
|
||||
#define PASSERT(x) \
|
||||
if (!x) { \
|
||||
printf("%s: %s", __PRETTY_FUNCTION__, #x); \
|
||||
exit(0); \
|
||||
}
|
||||
#else
|
||||
#include <glad/glad.h>
|
||||
//////////////////////////
|
||||
#include <GLFW/glfw3.h>
|
||||
#endif
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <os/desktopos.hpp>
|
||||
#include <os/horizon-ctr.hpp>
|
||||
#include <os/horizon-nx.hpp>
|
||||
#include <palladium>
|
||||
#include <pdsystem>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <d3d9.h>
|
||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||
#include <GLFW/glfw3native.h>
|
||||
#endif
|
||||
PD::OsCtx* pOs = nullptr;
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
|
||||
enum class Driver {
|
||||
Unknown = 0,
|
||||
OpenGL2 = 1,
|
||||
OpenGL3 = 2,
|
||||
DirectX9 = 3,
|
||||
};
|
||||
|
||||
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,
|
||||
h);
|
||||
}
|
||||
|
||||
class App {
|
||||
public:
|
||||
App(Driver d = Driver::OpenGL3) : pDriver(d) {
|
||||
PD::Os::UseDriver<PD::OsDriver>();
|
||||
#if defined(__3DS__)
|
||||
romfsInit();
|
||||
gfxInitDefault();
|
||||
consoleInit(GFX_BOTTOM, nullptr);
|
||||
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>();
|
||||
#elif defined(__SWITCH__)
|
||||
PASSERT(glfwInit());
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
window =
|
||||
glfwCreateWindow(1280, 720, "gfx_test (OpenGL3)", nullptr, nullptr);
|
||||
PASSERT(window);
|
||||
glfwMakeContextCurrent(window);
|
||||
PASSERT(gladLoadGL());
|
||||
glfwSwapInterval(1);
|
||||
PD::Gfx::UseDriver<PD::GfxOpenGL3>();
|
||||
const char* ResourcePath(const char* in) {
|
||||
#if defined(__SWITCH__) || defined(__3DS__)
|
||||
static char rbuf[512];
|
||||
std::snprintf(rbuf, sizeof(rbuf), "romfs:/%s", in);
|
||||
return rbuf;
|
||||
#else
|
||||
glfwInit();
|
||||
std::string winname = "gfx_test";
|
||||
if (d == Driver::OpenGL2) {
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, 0);
|
||||
#endif
|
||||
PD::Gfx::UseDriver<PD::GfxOpenGL2>();
|
||||
winname += " (OpenGL2)";
|
||||
} else if (d == Driver::OpenGL3) {
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, 0);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, 1);
|
||||
#endif
|
||||
PD::Gfx::UseDriver<PD::GfxOpenGL3>();
|
||||
winname += " (OpenGL3)";
|
||||
} else if (d == Driver::DirectX9) {
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
winname += " (DirectX9)";
|
||||
}
|
||||
window = glfwCreateWindow(1280, 720, winname.c_str(), nullptr, nullptr);
|
||||
glfwMakeContextCurrent(window);
|
||||
if (d == Driver::OpenGL2 || d == Driver::OpenGL3) {
|
||||
gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress));
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (d == Driver::DirectX9) {
|
||||
d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
auto hwnd = glfwGetWin32Window(window);
|
||||
D3DPRESENT_PARAMETERS d3dpp = {};
|
||||
d3dpp.Windowed = TRUE;
|
||||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
d3dpp.hDeviceWindow = hwnd;
|
||||
|
||||
HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
|
||||
D3DCREATE_HARDWARE_VERTEXPROCESSING,
|
||||
&d3dpp, &dx9_device);
|
||||
if (FAILED(hr)) {
|
||||
MessageBoxW(nullptr, L"Failed to create D3D9 device", L"Error", MB_OK);
|
||||
std::abort();
|
||||
}
|
||||
PD::Gfx::UseDriver<PD::GfxDirectX9>(dx9_device);
|
||||
}
|
||||
#endif
|
||||
glfwSwapInterval(1);
|
||||
#endif
|
||||
PD::Gfx::Init();
|
||||
#if defined(__3DS__) || defined(__SWITCH__)
|
||||
pTex = LoadTex("romfs:/icon.png");
|
||||
#else
|
||||
pTex = LoadTex("icon.png");
|
||||
#endif
|
||||
pList.DrawRectFilled(0, 50, 0xff00ffff);
|
||||
pList.BindTexture(pTex);
|
||||
pList.DrawRectFilled(50, pTex.GetSize(), 0xffffffff);
|
||||
pList.DrawCircleFilled(500, 100, 0xffffffff, 50);
|
||||
// pList.PathRect(300, 700, 40.f);
|
||||
// pList.PathFill(0xffffffff);
|
||||
std::cout << "GfxDriver: " << PD::Gfx::GetDriverName() << std::endl;
|
||||
}
|
||||
~App() {
|
||||
PD::Gfx::DeleteTexture(pTex);
|
||||
PD::Gfx::Deinit();
|
||||
#if !defined(__3DS__)
|
||||
glfwTerminate();
|
||||
return in;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Run() {
|
||||
#if defined(__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);
|
||||
#elif defined(__SWITCH__)
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
GLFWgamepadstate _gs;
|
||||
if (glfwGetGamepadState(GLFW_JOYSTICK_1, &_gs)) {
|
||||
if (_gs.buttons[GLFW_GAMEPAD_BUTTON_START] == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||
}
|
||||
}
|
||||
PD::Gfx::SetViewPort(1280, 720);
|
||||
glClearColor(0.1, 0.1, 0.1, 0.1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, 1280, 720);
|
||||
#else
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
int ww, wh;
|
||||
glfwGetFramebufferSize(window, &ww, &wh);
|
||||
PD::Gfx::SetViewPort(ww, wh);
|
||||
if (pDriver == Driver::OpenGL2 || pDriver == Driver::OpenGL3) {
|
||||
glClearColor(0.1, 0.1, 0.1, 0.1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, ww, wh);
|
||||
} else if (pDriver == Driver::DirectX9) {
|
||||
#ifdef _WIN32
|
||||
if (dx9_device) {
|
||||
dx9_device->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
|
||||
D3DCOLOR_XRGB(25, 25, 25), 1.0f, 0);
|
||||
dx9_device->BeginScene();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
PD::Gfx::Reset();
|
||||
|
||||
PD::Gfx::Draw(pList);
|
||||
#if defined(__3DS__)
|
||||
C3D_FrameEnd(0);
|
||||
#else
|
||||
glfwPollEvents();
|
||||
if (pDriver == Driver::DirectX9) {
|
||||
#ifdef _WIN32
|
||||
if (dx9_device) {
|
||||
dx9_device->EndScene();
|
||||
dx9_device->Present(nullptr, nullptr, nullptr, nullptr);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
#if defined(__3DS__)
|
||||
C3D_RenderTarget* Top = nullptr;
|
||||
C3D_RenderTarget* Bottom = nullptr;
|
||||
#else
|
||||
GLFWwindow* window = nullptr;
|
||||
#endif
|
||||
PD::Li::Drawlist pList;
|
||||
PD::Li::Texture pTex;
|
||||
Driver pDriver;
|
||||
#ifdef _WIN32
|
||||
IDirect3D9* d3d = nullptr;
|
||||
IDirect3DDevice9* dx9_device = nullptr;
|
||||
#endif
|
||||
};
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
#if defined(__SWITCH__)
|
||||
socketInitializeDefault();
|
||||
nxlinkStdio();
|
||||
romfsInit();
|
||||
printf("Starting Palladium GFX Tests...\n");
|
||||
glfwSetErrorCallback(errorCallback);
|
||||
#endif
|
||||
Driver drv = Driver::OpenGL3;
|
||||
if (argc == 2) {
|
||||
if (std::string(argv[1]) == "gl2") {
|
||||
@@ -251,8 +26,28 @@ int main(int argc, char** argv) {
|
||||
drv = Driver::DirectX9;
|
||||
}
|
||||
}
|
||||
App* app = new App(drv);
|
||||
app->Run();
|
||||
delete app;
|
||||
#if defined(__SWITCH__)
|
||||
pOs = new PD::HorizonNX(drv);
|
||||
#elif defined(__3DS__)
|
||||
pOs = new PD::HorizonCtr(drv);
|
||||
#else
|
||||
pOs = new PD::DesktopOS(drv);
|
||||
#endif
|
||||
pOs->Init();
|
||||
PD::Gfx::Init();
|
||||
PD::Li::Drawlist pList;
|
||||
while (pOs->Mainloop()) {
|
||||
pOs->ClearViewPort();
|
||||
PD::Li::ResetPools();
|
||||
pList.PathRect(pOs->SizeTranslate(0.05), pOs->SizeTranslate(0.4f), 10.f);
|
||||
pList.PathFill(0xff00ffff);
|
||||
PD::Gfx::Reset();
|
||||
PD::Gfx::Draw(pList);
|
||||
pList.Clear();
|
||||
pOs->SwapBuffers();
|
||||
}
|
||||
PD::Gfx::Deinit();
|
||||
pOs->Deinit();
|
||||
delete pOs;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
#include <os/desktopos.hpp>
|
||||
|
||||
#if !defined(__SWITCH__) && !defined(__3DS__)
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <pdsystem>
|
||||
|
||||
namespace PD {
|
||||
struct DesktopOS::Impl {
|
||||
GLFWwindow* win = nullptr;
|
||||
};
|
||||
|
||||
void DesktopOS::Init() {
|
||||
if (impl) return;
|
||||
impl = new Impl();
|
||||
std::string winname = "gfx_test";
|
||||
glfwInit();
|
||||
if (pDriver == Driver::OpenGL2) {
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
|
||||
PD::Gfx::UseDriver<PD::GfxOpenGL2>();
|
||||
winname += " (OpenGL2)";
|
||||
} else if (pDriver == Driver::OpenGL3) {
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, 1);
|
||||
#endif
|
||||
PD::Gfx::UseDriver<PD::GfxOpenGL3>();
|
||||
winname += " (OpenGL3)";
|
||||
} else if (pDriver == Driver::DirectX9) {
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
winname += " (DirectX9)";
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, 0);
|
||||
#endif
|
||||
impl->win = glfwCreateWindow(1280, 720, winname.c_str(), nullptr, nullptr);
|
||||
glfwMakeContextCurrent(impl->win);
|
||||
if (pDriver == Driver::OpenGL2 || pDriver == Driver::OpenGL3) {
|
||||
gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress));
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (pDriver == Driver::DirectX9) {
|
||||
d3d = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
auto hwnd = glfwGetWin32Window(impl->win);
|
||||
D3DPRESENT_PARAMETERS d3dpp = {};
|
||||
d3dpp.Windowed = TRUE;
|
||||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
d3dpp.hDeviceWindow = hwnd;
|
||||
|
||||
HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
|
||||
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp,
|
||||
&dx9_device);
|
||||
if (FAILED(hr)) {
|
||||
MessageBoxW(nullptr, L"Failed to create D3D9 device", L"Error", MB_OK);
|
||||
std::abort();
|
||||
}
|
||||
PD::Gfx::UseDriver<PD::GfxDirectX9>(dx9_device);
|
||||
}
|
||||
#endif
|
||||
glfwSwapInterval(1);
|
||||
}
|
||||
|
||||
void DesktopOS::Deinit() {
|
||||
glfwTerminate();
|
||||
if (impl) {
|
||||
delete impl;
|
||||
impl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool DesktopOS::Mainloop() {
|
||||
glfwPollEvents();
|
||||
glfwGetFramebufferSize(impl->win, &pViewPort.x, &pViewPort.y);
|
||||
return !glfwWindowShouldClose(impl->win);
|
||||
}
|
||||
|
||||
void DesktopOS::ClearViewPort() {
|
||||
PD::Gfx::SetViewPort(pViewPort);
|
||||
glClearColor(0.1, 0.1, 0.1, 0.1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, pViewPort.x, pViewPort.y);
|
||||
}
|
||||
|
||||
void DesktopOS::SwapBuffers() { glfwSwapBuffers(impl->win); }
|
||||
|
||||
} // namespace PD
|
||||
#endif
|
||||
@@ -0,0 +1,64 @@
|
||||
#include <os/horizon-ctr.hpp>
|
||||
|
||||
#if defined(__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));
|
||||
|
||||
#include <pdsystem>
|
||||
|
||||
namespace PD {
|
||||
struct HorizonCtr::Impl {
|
||||
C3D_RenderTarget* Top = nullptr;
|
||||
C3D_RenderTarget* Bottom = nullptr;
|
||||
};
|
||||
|
||||
void HorizonCtr::Init() {
|
||||
if (impl) return;
|
||||
impl = new Impl();
|
||||
romfsInit();
|
||||
gfxInitDefault();
|
||||
consoleInit(GFX_BOTTOM, nullptr);
|
||||
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE);
|
||||
impl->Top =
|
||||
C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
|
||||
impl->Bottom =
|
||||
C3D_RenderTargetCreate(240, 320, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTargetSetOutput(impl->Top, GFX_TOP, GFX_LEFT, DisplayTransferFlags);
|
||||
C3D_RenderTargetSetOutput(impl->Bottom, GFX_BOTTOM, GFX_LEFT,
|
||||
DisplayTransferFlags);
|
||||
PD::Gfx::UseDriver<PD::GfxCitro3D>();
|
||||
}
|
||||
|
||||
void HorizonCtr::Deinit() {
|
||||
if (impl) {
|
||||
C3D_RenderTargetDelete(impl->Top);
|
||||
C3D_RenderTargetDelete(impl->Bottom);
|
||||
C3D_Fini();
|
||||
gfxExit();
|
||||
romfsExit();
|
||||
delete impl;
|
||||
impl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool HorizonCtr::Mainloop() {
|
||||
pViewPort = ivec2(400, 240);
|
||||
return aptMainLoop();
|
||||
}
|
||||
|
||||
void HorizonCtr::ClearViewPort() {
|
||||
PD::Gfx::SetViewPort(pViewPort);
|
||||
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
|
||||
C3D_FrameDrawOn(impl->Top);
|
||||
C3D_RenderTargetClear(impl->Top, C3D_CLEAR_ALL, PD::Color(25, 25, 25, 25), 0);
|
||||
}
|
||||
|
||||
void HorizonCtr::SwapBuffers() { C3D_FrameEnd(0); }
|
||||
|
||||
} // namespace PD
|
||||
#endif
|
||||
@@ -0,0 +1,62 @@
|
||||
#include <os/horizon-nx.hpp>
|
||||
|
||||
#if defined(__SWITCH__)
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/glad.h>
|
||||
#include <switch.h>
|
||||
|
||||
#include <pdsystem>
|
||||
|
||||
namespace PD {
|
||||
struct HorizonNX::Impl {
|
||||
GLFWwindow* win = nullptr;
|
||||
};
|
||||
|
||||
void HorizonNX::Init() {
|
||||
if (impl) return;
|
||||
impl = new Impl();
|
||||
romfsInit();
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
impl->win =
|
||||
glfwCreateWindow(1280, 720, "gfx_test (OpenGL3)", nullptr, nullptr);
|
||||
glfwMakeContextCurrent(impl->win);
|
||||
gladLoadGL();
|
||||
glfwSwapInterval(1);
|
||||
PD::Gfx::UseDriver<PD::GfxOpenGL3>();
|
||||
}
|
||||
|
||||
void HorizonNX::Deinit() {
|
||||
glfwTerminate();
|
||||
if (impl) {
|
||||
delete impl;
|
||||
impl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool HorizonNX::Mainloop() {
|
||||
glfwPollEvents();
|
||||
GLFWgamepadstate _gs;
|
||||
if (glfwGetGamepadState(GLFW_JOYSTICK_1, &_gs)) {
|
||||
if (_gs.buttons[GLFW_GAMEPAD_BUTTON_START] == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(impl->win, GLFW_TRUE);
|
||||
}
|
||||
}
|
||||
glfwGetFramebufferSize(impl->win, &pViewPort.x, &pViewPort.y);
|
||||
return !glfwWindowShouldClose(impl->win);
|
||||
}
|
||||
|
||||
void HorizonNX::ClearViewPort() {
|
||||
PD::Gfx::SetViewPort(pViewPort);
|
||||
glClearColor(0.1, 0.1, 0.1, 0.1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glViewport(0, 0, pViewPort.x, pViewPort.y);
|
||||
}
|
||||
|
||||
void HorizonNX::SwapBuffers() { glfwSwapBuffers(impl->win); }
|
||||
|
||||
} // namespace PD
|
||||
#endif
|
||||
Reference in New Issue
Block a user