0.7.0 rewrite dev
- remove everyting - keep core -rename bit_utils to bits - add formatter for color - add float getters to color - start with new drivers api
This commit is contained in:
@@ -1,119 +1,82 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2026 René Amthor (tobid7)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/drivers/types.hpp>
|
||||
#include <pd/core/mat.hpp>
|
||||
#include <pd/drivers/interface.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
#include <pd/lithium/texture.hpp>
|
||||
|
||||
using LiBackendFlags = PD::u32;
|
||||
enum LiBackendFlags_ {
|
||||
LiBackendFlags_None = 0,
|
||||
LiBackendFlags_FlipUV_Y = PD_BIT(0), // Essential for font loading
|
||||
LiBackendFlags_FlipUV_Y = 1 << 0, // Essential for font loading
|
||||
};
|
||||
|
||||
namespace PD {
|
||||
// The backend api nobody asked for
|
||||
class GfxDriver2 {
|
||||
public:
|
||||
GfxDriver2(const std::string& name = "NullGfx") : pName(name) {};
|
||||
~GfxDriver2() = default;
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual void Draw(const PD::Li::CmdPool& pool) {}
|
||||
virtual void TexBind(PD::Li::TexAddress addr) {}
|
||||
virtual PD::Li::TexAddress TexLoad(
|
||||
const std::vector<PD::u8>& pixels, int w, int h,
|
||||
PD::Li::Texture::Type type = PD::Li::Texture::Type::RGBA32,
|
||||
PD::Li::Texture::Filter filter = PD::Li::Texture::Filter::LINEAR) {
|
||||
return 0;
|
||||
}
|
||||
virtual void TexDelete(PD::Li::TexAddress tex) {}
|
||||
|
||||
protected:
|
||||
const std::string pName;
|
||||
LiBackendFlags pFlags = 0;
|
||||
size_t CurrentIndex = 0;
|
||||
size_t CurrentVertex = 0;
|
||||
ivec2 ViewPort;
|
||||
using TextureID = ptr;
|
||||
enum class TextureFilter {
|
||||
Linear,
|
||||
Nearest,
|
||||
};
|
||||
class GfxDriver {
|
||||
|
||||
enum class TextureFormat {
|
||||
RGBA32,
|
||||
A8,
|
||||
};
|
||||
|
||||
class PD_API GfxDriver : public DriverInterface {
|
||||
public:
|
||||
GfxDriver(const std::string& name = "NullGfx") : pName(name) {}
|
||||
GfxDriver(PDDriverData data) : pName("NullGfx") {}
|
||||
~GfxDriver() = default;
|
||||
|
||||
PD_SHARED(GfxDriver);
|
||||
|
||||
void PostInit();
|
||||
GfxDriver(std::string_view name = "Default") : DriverInterface(name) {}
|
||||
virtual ~GfxDriver() {}
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual void NewFrame() {}
|
||||
|
||||
virtual void BindTex(Li::TexAddress addr) {}
|
||||
|
||||
virtual void RenderDrawData(const Li::CmdPool& Commands) {}
|
||||
|
||||
void SetViewPort(const ivec2& vp) { ViewPort = vp; }
|
||||
void SetViewPort(int w, int h) { ViewPort = PD::ivec2(w, h); }
|
||||
|
||||
virtual Li::Texture::Ref LoadTex(
|
||||
const std::vector<u8>& pixels, int w, int h,
|
||||
Li::Texture::Type type = Li::Texture::Type::RGBA32,
|
||||
Li::Texture::Filter filter = Li::Texture::Filter::LINEAR) {
|
||||
// Texture loading not supported (when this func not get override)
|
||||
return nullptr;
|
||||
virtual void Submit() {}
|
||||
virtual void BindTexture(TextureID id) {}
|
||||
virtual void Reset() {}
|
||||
virtual TextureID LoadTexture(const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) {}
|
||||
virtual void DeleteTexture(const TextureID& tex) {}
|
||||
void Draw(const std::vector<Li::Command>& commands) {
|
||||
CountCommands += commands.size();
|
||||
// Bind shader
|
||||
Projection = Mat4::Ortho(0.f, ViewPort.x, ViewPort.y, 0.f, 1.f, -1.f);
|
||||
// Shader Set Mtx
|
||||
size_t index = 0;
|
||||
while (index < commands.size()) {
|
||||
CurrentTex = commands[index].Tex;
|
||||
if (!CurrentTex) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void DestroyTex(PD::Li::Texture::Ref tex) {}
|
||||
|
||||
Li::Texture::Ref GetSolidTex() { return pSolid; }
|
||||
|
||||
const std::string& GetName() const { return pName; }
|
||||
|
||||
const std::string pName = "NullGfx";
|
||||
LiBackendFlags Flags = 0;
|
||||
ivec2 ViewPort;
|
||||
Mat4 Projection;
|
||||
Li::Texture::Ref pSolid;
|
||||
size_t CurrentVertex = 0;
|
||||
private:
|
||||
size_t CurrentIndex = 0;
|
||||
size_t CurrentVertex = 0;
|
||||
TextureID CurrentTex = 0;
|
||||
Mat4 Projection;
|
||||
ivec2 ViewPort;
|
||||
|
||||
/** Debug Variables */
|
||||
// Counters
|
||||
size_t CountDrawcalls = 0;
|
||||
size_t CountCommands = 0;
|
||||
size_t CountVertices = 0;
|
||||
size_t CountIndices = 0;
|
||||
};
|
||||
|
||||
// Optional Index counter
|
||||
u32 IndexCounter;
|
||||
// Optional Vertex counter
|
||||
u32 VertexCounter;
|
||||
// Optional Frame Counter
|
||||
u64 FrameCounter;
|
||||
// Draw calls counter
|
||||
u32 DrawCalls;
|
||||
// Command Counter
|
||||
u32 DrawCommands;
|
||||
class PD_API Gfx {
|
||||
public:
|
||||
Gfx() = default;
|
||||
~Gfx() = default;
|
||||
|
||||
template <typename T, typename... Args>
|
||||
static void UseDriver(Args&&... args) {
|
||||
// assert(driver == nullptr && "OS Driver already set");
|
||||
driver = std::make_unique<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
static std::unique_ptr<GfxDriver> driver;
|
||||
};
|
||||
} // namespace PD
|
||||
Reference in New Issue
Block a user