Add backends
- Renamed GfxOpenGL to GfxOPenGL2 - Added GfxOpenGL3 backend for OpenGL 3.3+ - Added WIP DirectX9 backend - Added structure for Citro3D - Added linear Allocator
This commit is contained in:
@@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
@@ -43,7 +44,7 @@ using u16 = unsigned short;
|
||||
using u32 = unsigned int;
|
||||
using u64 = unsigned long long;
|
||||
using ptr = uintptr_t;
|
||||
void Log(const std::string& txt);
|
||||
PD_API void Log(const std::string& txt);
|
||||
template <typename... Args>
|
||||
void Log(std::format_string<Args...> fmt, Args&&... args) {
|
||||
std::string msg = std::format(fmt, std::forward<Args>(args)...);
|
||||
|
||||
@@ -93,6 +93,6 @@ struct std::formatter<PD::Color> : std::formatter<std::string> {
|
||||
std::format_parse_context::const_iterator end,
|
||||
size_t len, const char* what) {
|
||||
return (end - it >= static_cast<std::ptrdiff_t>(len) &&
|
||||
std::string_view(it, len) == what);
|
||||
std::string_view(&*it, len) == what); // msvc things...
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/drivers/formatters.hpp>
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
44
include/pd/drivers/formatters.hpp
Normal file
44
include/pd/drivers/formatters.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
|
||||
template <>
|
||||
struct std::formatter<PD::TextureFilter> {
|
||||
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const PD::TextureFilter& value, FormatContext& ctx) const {
|
||||
std::string_view ret = "Unknown";
|
||||
switch (value) {
|
||||
case PD::TextureFilter::Linear:
|
||||
ret = "Linear";
|
||||
break;
|
||||
case PD::TextureFilter::Nearest:
|
||||
ret = "Nearest";
|
||||
break;
|
||||
}
|
||||
return std::format_to(ctx.out(), "{}", ret);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct std::formatter<PD::TextureFormat> {
|
||||
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const PD::TextureFormat& value, FormatContext& ctx) const {
|
||||
std::string_view ret = "Unknown";
|
||||
switch (value) {
|
||||
case PD::TextureFormat::RGBA32:
|
||||
ret = "RGBA32";
|
||||
break;
|
||||
case PD::TextureFormat::RGB24:
|
||||
ret = "RGB24";
|
||||
break;
|
||||
case PD::TextureFormat::A8:
|
||||
ret = "A8";
|
||||
break;
|
||||
}
|
||||
return std::format_to(ctx.out(), "{}", ret);
|
||||
}
|
||||
};
|
||||
@@ -19,6 +19,7 @@ enum class TextureFilter {
|
||||
|
||||
enum class TextureFormat {
|
||||
RGBA32,
|
||||
RGB24,
|
||||
A8,
|
||||
};
|
||||
|
||||
@@ -69,20 +70,17 @@ struct DefaultGfxConfig {
|
||||
// Index Allocator
|
||||
template <typename T>
|
||||
using IndexAlloc = std::allocator<T>;
|
||||
using IndexType = u16; // Index Type
|
||||
|
||||
static constexpr size_t NumVertices = 32768; // 8192*4
|
||||
static constexpr size_t NumIndices = 49152; // 8192*6
|
||||
};
|
||||
|
||||
template <typename Config = DefaultGfxConfig>
|
||||
class PD_API GfxDriverBase : public GfxDriver {
|
||||
class GfxDriverBase : public GfxDriver {
|
||||
public:
|
||||
using IndexType = Config::IndexType;
|
||||
using VtxPool =
|
||||
Pool<Li::Vertex, typename Config::template VertexAlloc<Li::Vertex>>;
|
||||
using IdxPool =
|
||||
Pool<IndexType, typename Config::template VertexAlloc<IndexType>>;
|
||||
using IdxPool = Pool<u16, typename Config::template VertexAlloc<u16>>;
|
||||
GfxDriverBase(std::string_view name = "Default") : GfxDriver(name) {}
|
||||
virtual ~GfxDriverBase() {}
|
||||
|
||||
@@ -111,17 +109,19 @@ class PD_API GfxDriverBase : public GfxDriver {
|
||||
for (size_t i = 0; i < c.IndexCount; i++) {
|
||||
pIdx[i] = CurrentVertex + c.FirstIndex[i];
|
||||
}
|
||||
CurrentIndex += c.IndexCount;
|
||||
CurrentVertex += c.VertexCount;
|
||||
for (size_t i = 0; i < c.VertexCount; i++) {
|
||||
pVtx[i] = c.FirstVertex[i];
|
||||
}
|
||||
index++;
|
||||
}
|
||||
Submit(index - startidx, startidx);
|
||||
Submit(CurrentIndex - startidx, startidx);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
IndexType* GetIndexBufPtr(size_t start) { return &pIdxPool[start]; }
|
||||
u16* GetIndexBufPtr(size_t start) { return &pIdxPool[start]; }
|
||||
Li::Vertex* GetVertexBufPtr(size_t start) { return &pVtxPool[start]; }
|
||||
void ResetPools() override {
|
||||
pVtxPool.Reset();
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
void InitPools(size_t max_vertices = 32768);
|
||||
Vertex* AllocateVertices(size_t count);
|
||||
u16* AllocateIndices(size_t count);
|
||||
PD_API void InitPools(size_t max_vertices = 32768);
|
||||
PD_API Vertex* AllocateVertices(size_t count);
|
||||
PD_API u16* AllocateIndices(size_t count);
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
Reference in New Issue
Block a user