Initial Cross Platform Work
This commit is contained in:
46
backends/desktop/include/li_backend_gl2.hpp
Normal file
46
backends/desktop/include/li_backend_gl2.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <glad/glad.h>
|
||||
|
||||
/** SEPARATOR */
|
||||
#include <GLFW/glfw3.h>
|
||||
/** SEPARATOR */
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/backend.hpp>
|
||||
#include <pd_p_bknd_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace LI {
|
||||
class PD_BKND_DESKTOP_API Backend_GL2 : public PD::LI::Backend {
|
||||
public:
|
||||
Backend_GL2() : LI::Backend("OpenGL2") {}
|
||||
~Backend_GL2() {}
|
||||
|
||||
PD_SMART_CTOR(Backend_GL2)
|
||||
|
||||
void Init() override;
|
||||
void Deinit() override;
|
||||
void NewFrame() override;
|
||||
void BindTexture(PD::LI::TexAddress addr) override;
|
||||
void RenderDrawData(const PD::Vec<PD::LI::Command::Ref>& Commands) override;
|
||||
PD::LI::Texture::Ref LoadTexture(
|
||||
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) override;
|
||||
|
||||
private:
|
||||
PD::Vec<PD::LI::Vertex> VertexBuffer;
|
||||
PD::Vec<PD::u16> IndexBuffer;
|
||||
size_t CurrentVertex = 0;
|
||||
size_t CurrentIndex = 0;
|
||||
GLuint Shader;
|
||||
GLuint pLocProjection;
|
||||
GLuint pLocTex;
|
||||
Mat4 Projection;
|
||||
GLuint VBO, IBO;
|
||||
// For Stats
|
||||
PD::u32 num_vtx = 0;
|
||||
PD::u32 num_idx = 0;
|
||||
};
|
||||
|
||||
} // namespace LI
|
||||
} // namespace PD
|
50
backends/desktop/include/pd_hid_glfw.hpp
Normal file
50
backends/desktop/include/pd_hid_glfw.hpp
Normal file
@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 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 <GLFW/glfw3.h>
|
||||
|
||||
#include <pd/core/hid_driver.hpp>
|
||||
#include <pd_p_bknd_api.hpp>
|
||||
|
||||
namespace PD {
|
||||
class PD_BKND_DESKTOP_API HidGLFW : public Hid {
|
||||
public:
|
||||
/**
|
||||
* Constructor to setup Key binds
|
||||
*/
|
||||
HidGLFW(GLFWwindow* win);
|
||||
~HidGLFW() = default;
|
||||
PD_SMART_CTOR(HidGLFW)
|
||||
|
||||
/**
|
||||
* Overrideing the Update Function for Input Checking etc
|
||||
*/
|
||||
void Update() override;
|
||||
|
||||
private:
|
||||
GLFWwindow* Window;
|
||||
int PrevState;
|
||||
};
|
||||
} // namespace PD
|
117
backends/desktop/include/pd_net_desktop.hpp
Normal file
117
backends/desktop/include/pd_net_desktop.hpp
Normal file
@ -0,0 +1,117 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
Copyright (c) 2024 - 2025 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.
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#ifdef _MSVC
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#endif
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#include <pd/net/backend.hpp>
|
||||
namespace PD {
|
||||
class NetBackendDesktop : public PD::Net::Backend {
|
||||
public:
|
||||
#ifdef _WIN32
|
||||
NetBackendDesktop() : Net::Backend("Desktop (Windows)") {
|
||||
#else
|
||||
NetBackendDesktop() : Net::Backend("Desktop (Unix)") {
|
||||
#endif
|
||||
}
|
||||
~NetBackendDesktop() = default;
|
||||
PD_SMART_CTOR(NetBackendDesktop)
|
||||
bool Init() override {
|
||||
#ifdef _WIN32
|
||||
WSADATA wsa_data;
|
||||
return (WSAStartup(MAKEWORD(2, 2), &wsa_data) == 0);
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
void Deinit() override {
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
int NewSocket() override { return socket(AF_INET, SOCK_STREAM, 0); }
|
||||
void Close(int sock_id) override {
|
||||
#ifdef _WIN32
|
||||
closesocket(sock_id);
|
||||
#else
|
||||
close(sock_id);
|
||||
#endif
|
||||
}
|
||||
int GetInvalidRef() const override {
|
||||
#ifdef _WIN32
|
||||
return INVALID_SOCKET;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Bind(int sock_id, u16 port) {
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
return bind(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
|
||||
}
|
||||
bool Listen(int sock_id, int backlog = 5) {
|
||||
return listen(sock_id, backlog) != -1;
|
||||
}
|
||||
bool Accept(int sock_id, Net::Socket::Ref client) {
|
||||
int client_soc = accept(sock_id, nullptr, nullptr);
|
||||
if (client_soc == GetInvalidRef()) {
|
||||
return false;
|
||||
}
|
||||
client->pSocket = client_soc;
|
||||
return true;
|
||||
}
|
||||
bool Connect(int sock_id, const std::string& ip, u16 port) {
|
||||
sockaddr_in addr{};
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
inet_pton(AF_INET, ip.c_str(), &addr.sin_addr);
|
||||
return connect(sock_id, (sockaddr*)&addr, sizeof(addr)) != -1;
|
||||
}
|
||||
int Send(int sock_id, const std::string& data) {
|
||||
return send(sock_id, data.c_str(), static_cast<int>(data.size()), 0);
|
||||
}
|
||||
int Receive(int sock_id, std::string& data, int size = 1024) {
|
||||
char* tmp = new char[size];
|
||||
int res = recv(sock_id, tmp, size, 0);
|
||||
if (res > 0) {
|
||||
data.assign(tmp, res);
|
||||
}
|
||||
delete[] tmp;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
} // namespace PD
|
58
backends/desktop/include/pd_p_bknd_api.hpp
Normal file
58
backends/desktop/include/pd_p_bknd_api.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 - 2025 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef PD_BKND_DESKTOP_STATIC
|
||||
#if defined(__3DS__) // 3ds Specific
|
||||
#error "Desktop backend is not supported on the 3ds!"
|
||||
#endif
|
||||
#define PD_BKND_DESKTOP_API
|
||||
#else
|
||||
#ifdef _WIN32 // Windows (MSVC Tested)
|
||||
#ifdef PD_BKND_DESKTOP_BUILD_SHARED
|
||||
#define PD_BKND_DESKTOP_API __declspec(dllexport)
|
||||
#else
|
||||
#define PD_BKND_DESKTOP_API __declspec(dllimport)
|
||||
#endif
|
||||
#elif defined(__APPLE__) // macOS (untested yet)
|
||||
#ifdef PD_BKND_DESKTOP_BUILD_SHARED
|
||||
#define PD_BKND_DESKTOP_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define PD_BKND_DESKTOP_API
|
||||
#endif
|
||||
#elif defined(__linux__) // Linux (untested yet)
|
||||
#ifdef PD_BKND_DESKTOP_BUILD_SHARED
|
||||
#define PD_BKND_DESKTOP_API __attribute__((visibility("default")))
|
||||
#else
|
||||
#define PD_BKND_DESKTOP_API
|
||||
#endif
|
||||
#elif defined(__3DS__) // 3ds Specific
|
||||
#error "Desktop backend is not supported on the 3ds!"
|
||||
#else
|
||||
#define PD_BKND_DESKTOP_API
|
||||
#endif
|
||||
#endif
|
Reference in New Issue
Block a user