# Work at gfx driver system
- Update pool to use template allocator directly instead of std::vector - Add a GfxDriver config Template to be able to modify settings like allocators / Types for specific Drivers - Add glad
This commit is contained in:
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
vendor/* linguist-vendored
|
||||
@@ -17,8 +17,11 @@ if(${PD_BUILD_TOOLS})
|
||||
add_subdirectory(tools)
|
||||
endif()
|
||||
|
||||
add_subdirectory(vendor)
|
||||
|
||||
# # Include Library Source
|
||||
set(PD_SOURCES
|
||||
|
||||
# Core
|
||||
source/core/bits.cpp
|
||||
source/core/color.cpp
|
||||
@@ -26,6 +29,7 @@ set(PD_SOURCES
|
||||
source/core/strings.cpp
|
||||
|
||||
source/drivers/os.cpp
|
||||
source/drivers/gfx.cpp
|
||||
)
|
||||
|
||||
if(${PD_BUILD_SHARED})
|
||||
@@ -83,7 +87,6 @@ install(FILES
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/palladium
|
||||
)
|
||||
|
||||
|
||||
find_program(CLANG_FORMAT clang-format)
|
||||
|
||||
file(GLOB_RECURSE PD_FMTFILES CONFIGURE_DEPENDS
|
||||
@@ -96,4 +99,5 @@ add_custom_target(pd-clang-format
|
||||
COMMENT "Formatting Project Sources"
|
||||
)
|
||||
|
||||
add_subdirectory(backends)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||
|
||||
21
backends/CMakeLists.txt
Normal file
21
backends/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(pd-system)
|
||||
|
||||
option(PD_ENABLE_OPENGL2 "Enable OpenGL 2.1 (On Supported Hardware)" ON)
|
||||
option(PD_ENABLE_OPENGL3 "Enable OpenGL 3.3 (On Supported Hardware)" ON)
|
||||
option(PD_ENABLE_VULKAN "Not implemented yet" OFF)
|
||||
|
||||
add_library(pd-system STATIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/source/gfx_opengl.cpp
|
||||
)
|
||||
target_include_directories(pd-system
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
target_link_libraries(pd-system
|
||||
PUBLIC
|
||||
palladium::palladium
|
||||
glad
|
||||
)
|
||||
42
backends/include/gfx_opengl.hpp
Normal file
42
backends/include/gfx_opengl.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
|
||||
namespace PD {
|
||||
struct GfxOpenGLConfig {
|
||||
// Vertex Allocator
|
||||
template <typename T>
|
||||
using VertexAlloc = std::allocator<T>;
|
||||
// Index Allocator
|
||||
template <typename T>
|
||||
using IndexAlloc = std::allocator<T>;
|
||||
using IndexType = u32; // Index Type
|
||||
|
||||
static constexpr size_t NumVertices = 32768; // 8192*4
|
||||
static constexpr size_t NumIndices = 49152; // 8192*6
|
||||
};
|
||||
class GfxOpenGL : public GfxDriverBase<GfxOpenGLConfig> {
|
||||
public:
|
||||
GfxOpenGL() {}
|
||||
~GfxOpenGL() {}
|
||||
|
||||
void SysInit() override;
|
||||
void SysDeinit() override;
|
||||
void Submit(size_t count, size_t start) override;
|
||||
void BindTexture(TextureID id) override;
|
||||
void SysReset() override;
|
||||
TextureID LoadTexture(const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) override;
|
||||
void DeleteTexture(const TextureID& tex) override;
|
||||
|
||||
private:
|
||||
void pSetupShaderAttribs(u32 shader);
|
||||
u32 pShader = 0;
|
||||
u32 VBO = 0;
|
||||
u32 IBO = 0;
|
||||
int pLocTex = 0;
|
||||
int pLocAlfa = 0;
|
||||
int pLocProjection = 0;
|
||||
};
|
||||
} // namespace PD
|
||||
154
backends/source/gfx_opengl.cpp
Normal file
154
backends/source/gfx_opengl.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <gfx_opengl.hpp>
|
||||
|
||||
namespace PD {
|
||||
GLuint compileShader(const std::string& source, GLenum type) {
|
||||
GLuint shader = glCreateShader(type);
|
||||
const char* src = source.c_str();
|
||||
glShaderSource(shader, 1, &src, nullptr);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint success;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||
if (!success) {
|
||||
char infoLog[512];
|
||||
glGetShaderInfoLog(shader, 512, nullptr, infoLog);
|
||||
std::cerr << "Shader Compilation Error: " << infoLog << std::endl;
|
||||
}
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
GLuint createShaderProgram(const std::string& vertexShaderSource,
|
||||
const std::string& fragmentShaderSource) {
|
||||
GLuint vertexShader = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
||||
GLuint fragmentShader =
|
||||
compileShader(fragmentShaderSource, GL_FRAGMENT_SHADER);
|
||||
|
||||
GLuint shaderProgram = glCreateProgram();
|
||||
glAttachShader(shaderProgram, vertexShader);
|
||||
glAttachShader(shaderProgram, fragmentShader);
|
||||
glLinkProgram(shaderProgram);
|
||||
|
||||
GLint success;
|
||||
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
char infoLog[512];
|
||||
glGetProgramInfoLog(shaderProgram, 512, nullptr, infoLog);
|
||||
std::cerr << "Shader Program Linking Error: " << infoLog << std::endl;
|
||||
}
|
||||
|
||||
glDeleteShader(vertexShader);
|
||||
glDeleteShader(fragmentShader);
|
||||
|
||||
return shaderProgram;
|
||||
}
|
||||
|
||||
const char* vertex_shader = R"(
|
||||
#version 120
|
||||
|
||||
attribute vec2 pos;
|
||||
attribute vec2 uv;
|
||||
attribute vec4 color;
|
||||
|
||||
varying vec2 oUV;
|
||||
varying vec4 oColor;
|
||||
|
||||
// Probably forgot about this matrix and
|
||||
// searched hours for why the rendering isn't working :/
|
||||
uniform mat4 projection;
|
||||
|
||||
void main() {
|
||||
gl_Position = projection*vec4(pos, 0.0, 1.0);
|
||||
oUV = uv;
|
||||
oColor = color;
|
||||
}
|
||||
)";
|
||||
|
||||
const char* frag_shader = R"(
|
||||
#version 120
|
||||
|
||||
varying vec2 oUV;
|
||||
varying vec4 oColor;
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform bool alfa;
|
||||
|
||||
void main() {
|
||||
vec4 tc = texture2D(tex, oUV);
|
||||
if (alfa) {
|
||||
gl_FragColor = vec4(oColor.rgb, tc.a * oColor.a);
|
||||
} else {
|
||||
gl_FragColor = tc * oColor;
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
||||
void GfxOpenGL::pSetupShaderAttribs(u32 shader) {
|
||||
GLint _pos = glGetAttribLocation(shader, "pos");
|
||||
GLint _uv = glGetAttribLocation(shader, "uv");
|
||||
GLint _color = glGetAttribLocation(shader, "color");
|
||||
glVertexAttribPointer(_pos, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, pos));
|
||||
glEnableVertexAttribArray(_pos);
|
||||
|
||||
glVertexAttribPointer(_uv, 2, GL_FLOAT, GL_FALSE, sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, uv));
|
||||
glEnableVertexAttribArray(_uv);
|
||||
|
||||
glVertexAttribPointer(_color, 4, GL_UNSIGNED_BYTE, GL_TRUE,
|
||||
sizeof(PD::Li::Vertex),
|
||||
(void*)offsetof(PD::Li::Vertex, color));
|
||||
glEnableVertexAttribArray(_color);
|
||||
}
|
||||
|
||||
void GfxOpenGL::SysInit() {
|
||||
pShader = createShaderProgram(vertex_shader, frag_shader);
|
||||
glUseProgram(pShader);
|
||||
glGenBuffers(1, &VBO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
pSetupShaderAttribs(pShader);
|
||||
glGenBuffers(1, &IBO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
|
||||
|
||||
pLocTex = glGetUniformLocation(pShader, "tex");
|
||||
pLocAlfa = glGetUniformLocation(pShader, "alfa");
|
||||
pLocProjection = glGetUniformLocation(pShader, "projection");
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void GfxOpenGL::SysDeinit() {
|
||||
glDeleteBuffers(1, &VBO);
|
||||
glDeleteBuffers(1, &IBO);
|
||||
}
|
||||
|
||||
void GfxOpenGL::Submit(size_t count, size_t start) {
|
||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT,
|
||||
(void*)GetIndexBufPtr(start));
|
||||
}
|
||||
|
||||
void GfxOpenGL::BindTexture(TextureID id) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, (GLuint)id);
|
||||
glUniform1i(pLocTex, 0);
|
||||
GLint fmt = 0;
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &fmt);
|
||||
glUniform1i(pLocAlfa, fmt == GL_ALPHA);
|
||||
}
|
||||
|
||||
void GfxOpenGL::SysReset() {}
|
||||
|
||||
TextureID GfxOpenGL::LoadTexture(const std::vector<PD::u8>& pixels, int w,
|
||||
int h, TextureFormat type,
|
||||
TextureFilter filter) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GfxOpenGL::DeleteTexture(const TextureID& tex) {
|
||||
GLuint tex_ = tex;
|
||||
glDeleteTextures(1, &tex_);
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -28,6 +28,7 @@ SOFTWARE.
|
||||
#include <exception>
|
||||
#include <format>
|
||||
#include <fstream>
|
||||
#include <numbers>
|
||||
#include <pd/pd_p_api.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -1,20 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
namespace PD {
|
||||
template <typename T, typename Alloc = std::allocator<T>>
|
||||
class Pool {
|
||||
public:
|
||||
using value_type = T;
|
||||
using iterator = T*;
|
||||
using const_iterator = const iterator*;
|
||||
|
||||
Pool() = default;
|
||||
~Pool() = default;
|
||||
~Pool() {
|
||||
if (pData) {
|
||||
pAlloc.deallocate(pData, pCap);
|
||||
pData = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static Pool* Create(size_t size) { return new Pool(size); }
|
||||
|
||||
void Init(size_t size) {
|
||||
pPos = 0;
|
||||
pCap = size;
|
||||
pPool.resize(size);
|
||||
pData = pAlloc.allocate(size);
|
||||
}
|
||||
|
||||
Pool(const Pool&) = delete;
|
||||
@@ -24,7 +33,7 @@ class Pool {
|
||||
|
||||
T* Allocate(size_t num = 1) {
|
||||
if (CheckLimits(num)) return nullptr;
|
||||
T* ret = &pPool[pPos];
|
||||
T* ret = &pData[pPos];
|
||||
pPos += num;
|
||||
return ret;
|
||||
}
|
||||
@@ -42,10 +51,19 @@ class Pool {
|
||||
|
||||
void Reset() { pPos = 0; }
|
||||
|
||||
size_t size() const { return pPos; }
|
||||
size_t capacity() const { return pCap; }
|
||||
T& at(size_t idx) { return pData[idx]; }
|
||||
const T& at(size_t idx) const { return pData[idx]; }
|
||||
|
||||
T& operator[](size_t idx) { return at(idx); }
|
||||
const T& operator[](size_t idx) const { return at(idx); }
|
||||
|
||||
private:
|
||||
Pool(size_t size) : pCap(size), pPos(0) { pPool.resize(size); }
|
||||
Pool(size_t size) : pCap(size), pPos(0) { pData = pAlloc.allocate(size); }
|
||||
size_t pCap = 0;
|
||||
size_t pPos = 0;
|
||||
std::vector<T, Alloc> pPool;
|
||||
Alloc pAlloc;
|
||||
T* pData = nullptr;
|
||||
};
|
||||
} // namespace PD
|
||||
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include <pd/drivers/os.hpp>
|
||||
#include <pd/drivers/os.hpp>
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
@@ -22,25 +22,78 @@ enum class TextureFormat {
|
||||
A8,
|
||||
};
|
||||
|
||||
// Pre interface class
|
||||
class PD_API GfxDriver : public DriverInterface {
|
||||
public:
|
||||
GfxDriver(std::string_view name = "Default") : DriverInterface(name) {}
|
||||
virtual ~GfxDriver() {}
|
||||
GfxDriver(std::string_view name);
|
||||
virtual ~GfxDriver() = default;
|
||||
|
||||
virtual void Init() {}
|
||||
virtual void Deinit() {}
|
||||
virtual void Submit() {}
|
||||
|
||||
void SetViewPort(const ivec2& size);
|
||||
void SetViewPort(int x, int y);
|
||||
virtual void BindTexture(TextureID id) {}
|
||||
virtual void Reset() {}
|
||||
void Reset();
|
||||
virtual TextureID LoadTexture(const std::vector<PD::u8>& pixels, int w, int h,
|
||||
TextureFormat type = TextureFormat::RGBA32,
|
||||
TextureFilter filter = TextureFilter::Linear) {}
|
||||
TextureFilter filter = TextureFilter::Linear) {
|
||||
return 0;
|
||||
}
|
||||
virtual void DeleteTexture(const TextureID& tex) {}
|
||||
void Draw(const std::vector<Li::Command>& commands) {
|
||||
virtual void Draw(const Pool<Li::Command>& commands) {}
|
||||
|
||||
protected:
|
||||
virtual void SysDeinit() {}
|
||||
virtual void SysInit() {}
|
||||
virtual void SysReset() {}
|
||||
virtual void Submit(size_t count, size_t start) {}
|
||||
virtual void ResetPools() = 0;
|
||||
|
||||
// Counters
|
||||
size_t CountDrawcalls = 0;
|
||||
size_t CountCommands = 0;
|
||||
size_t CountVertices = 0;
|
||||
size_t CountIndices = 0;
|
||||
size_t CurrentIndex = 0;
|
||||
size_t CurrentVertex = 0;
|
||||
TextureID CurrentTex = 0;
|
||||
Mat4 Projection;
|
||||
ivec2 ViewPort;
|
||||
};
|
||||
|
||||
struct DefaultGfxConfig {
|
||||
// Vertex Allocator
|
||||
template <typename T>
|
||||
using VertexAlloc = std::allocator<T>;
|
||||
// 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 {
|
||||
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>>;
|
||||
GfxDriverBase(std::string_view name = "Default") : GfxDriver(name) {}
|
||||
virtual ~GfxDriverBase() {}
|
||||
|
||||
void Init() override {
|
||||
pVtxPool.Init(Config::NumVertices);
|
||||
pIdxPool.Init(Config::NumIndices);
|
||||
SysInit();
|
||||
}
|
||||
|
||||
void Draw(const Pool<Li::Command>& commands) override {
|
||||
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;
|
||||
@@ -48,21 +101,36 @@ class PD_API GfxDriver : public DriverInterface {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
size_t startidx = CurrentIndex;
|
||||
while (index < commands.size() && CurrentTex == commands[index].Tex) {
|
||||
const auto& c = commands[index];
|
||||
CountVertices += c.VertexCount;
|
||||
CountIndices += c.IndexCount;
|
||||
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];
|
||||
}
|
||||
for (size_t i = 0; i < c.VertexCount; i++) {
|
||||
pVtx[i] = c.FirstVertex[i];
|
||||
}
|
||||
index++;
|
||||
}
|
||||
Submit(index - startidx, startidx);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
size_t CurrentIndex = 0;
|
||||
size_t CurrentVertex = 0;
|
||||
TextureID CurrentTex = 0;
|
||||
Mat4 Projection;
|
||||
ivec2 ViewPort;
|
||||
protected:
|
||||
IndexType* GetIndexBufPtr(size_t start) { return &pIdxPool[start]; }
|
||||
Li::Vertex* GetVertexBufPtr(size_t start) { return &pVtxPool[start]; }
|
||||
void ResetPools() override {
|
||||
pVtxPool.Reset();
|
||||
pIdxPool.Reset();
|
||||
}
|
||||
|
||||
// Counters
|
||||
size_t CountDrawcalls = 0;
|
||||
size_t CountCommands = 0;
|
||||
size_t CountVertices = 0;
|
||||
size_t CountIndices = 0;
|
||||
private:
|
||||
VtxPool pVtxPool;
|
||||
IdxPool pIdxPool;
|
||||
};
|
||||
|
||||
class PD_API Gfx {
|
||||
|
||||
19
source/drivers/gfx.cpp
Executable file
19
source/drivers/gfx.cpp
Executable file
@@ -0,0 +1,19 @@
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
|
||||
namespace PD {
|
||||
PD_API std::unique_ptr<GfxDriver> Gfx::driver;
|
||||
|
||||
GfxDriver::GfxDriver(std::string_view name) : DriverInterface(name) {}
|
||||
|
||||
void GfxDriver::SetViewPort(const ivec2& size) { ViewPort = size; }
|
||||
void GfxDriver::SetViewPort(int x, int y) {
|
||||
ViewPort.x = x;
|
||||
ViewPort.y = y;
|
||||
}
|
||||
|
||||
void GfxDriver::Reset() {
|
||||
CurrentVertex = 0;
|
||||
CurrentIndex = 0;
|
||||
SysReset();
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -24,5 +24,10 @@ int main() {
|
||||
PD::Os::UseDriver<PD::OsDriver>();
|
||||
ColorTests();
|
||||
std::cout << PD::Os::GetTime() << std::endl;
|
||||
PD::Pool<int> pool;
|
||||
pool.Init(90);
|
||||
int* elems = pool.Allocate(5);
|
||||
std::cout << std::format("Pool ({}/{})", pool.size(), pool.capacity())
|
||||
<< std::endl;
|
||||
return 0;
|
||||
}
|
||||
8
vendor/CMakeLists.txt
vendored
Normal file
8
vendor/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
# GLAD
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/glad)
|
||||
|
||||
# STB
|
||||
add_library(stb INTERFACE)
|
||||
target_include_directories(stb INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/stb)
|
||||
12
vendor/glad/CMakeLists.txt
vendored
Normal file
12
vendor/glad/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
project(glad LANGUAGES C)
|
||||
|
||||
add_library(glad STATIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/glad.c
|
||||
)
|
||||
target_include_directories(glad
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
7
vendor/glad/README.md
vendored
Normal file
7
vendor/glad/README.md
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# glad OpenGL Loader
|
||||
|
||||
Generator command:
|
||||
|
||||
```bash
|
||||
python3 -m glad --profile core --out-path glad/ --api gl=3.3 --generator=c
|
||||
```
|
||||
311
vendor/glad/include/KHR/khrplatform.h
vendored
Normal file
311
vendor/glad/include/KHR/khrplatform.h
vendored
Normal file
@@ -0,0 +1,311 @@
|
||||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are 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 Materials.
|
||||
**
|
||||
** THE MATERIALS ARE 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
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
*
|
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID:
|
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||
*
|
||||
* Adopters may modify this file to suit their platform. Adopters are
|
||||
* encouraged to submit platform specific modifications to the Khronos
|
||||
* group so that they can be included in future versions of this file.
|
||||
* Please submit changes by filing pull requests or issues on
|
||||
* the EGL Registry repository linked above.
|
||||
*
|
||||
*
|
||||
* See the Implementer's Guidelines for information about where this file
|
||||
* should be located on your system and for more details of its use:
|
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
*
|
||||
* This file should be included as
|
||||
* #include <KHR/khrplatform.h>
|
||||
* by Khronos client API header files that use its types and defines.
|
||||
*
|
||||
* The types in khrplatform.h should only be used to define API-specific types.
|
||||
*
|
||||
* Types defined in khrplatform.h:
|
||||
* khronos_int8_t signed 8 bit
|
||||
* khronos_uint8_t unsigned 8 bit
|
||||
* khronos_int16_t signed 16 bit
|
||||
* khronos_uint16_t unsigned 16 bit
|
||||
* khronos_int32_t signed 32 bit
|
||||
* khronos_uint32_t unsigned 32 bit
|
||||
* khronos_int64_t signed 64 bit
|
||||
* khronos_uint64_t unsigned 64 bit
|
||||
* khronos_intptr_t signed same number of bits as a pointer
|
||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||
* khronos_ssize_t signed size
|
||||
* khronos_usize_t unsigned size
|
||||
* khronos_float_t signed 32 bit floating point
|
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||
* nanoseconds
|
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||
* only be used as a base type when a client API's boolean type is
|
||||
* an enum. Client APIs which use an integer or other type for
|
||||
* booleans cannot use this as the base type for their boolean.
|
||||
*
|
||||
* Tokens defined in khrplatform.h:
|
||||
*
|
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||
*
|
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||
*
|
||||
* Calling convention macros defined in this file:
|
||||
* KHRONOS_APICALL
|
||||
* KHRONOS_APIENTRY
|
||||
* KHRONOS_APIATTRIBUTES
|
||||
*
|
||||
* These may be used in function prototypes as:
|
||||
*
|
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||
* int arg1,
|
||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||
*/
|
||||
|
||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||
# define KHRONOS_STATIC 1
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL
|
||||
*-------------------------------------------------------------------------
|
||||
* This precedes the return type of the function in the function prototype.
|
||||
*/
|
||||
#if defined(KHRONOS_STATIC)
|
||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||
* header compatible with static linking. */
|
||||
# define KHRONOS_APICALL
|
||||
#elif defined(_WIN32)
|
||||
# define KHRONOS_APICALL __declspec(dllimport)
|
||||
#elif defined (__SYMBIAN32__)
|
||||
# define KHRONOS_APICALL IMPORT_C
|
||||
#elif defined(__ANDROID__)
|
||||
# define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||
#else
|
||||
# define KHRONOS_APICALL
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the return type of the function and precedes the function
|
||||
* name in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||
/* Win32 but not WinCE */
|
||||
# define KHRONOS_APIENTRY __stdcall
|
||||
#else
|
||||
# define KHRONOS_APIENTRY
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the closing parenthesis of the function prototype arguments.
|
||||
*/
|
||||
#if defined (__ARMCC_2__)
|
||||
#define KHRONOS_APIATTRIBUTES __softfp
|
||||
#else
|
||||
#define KHRONOS_APIATTRIBUTES
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions
|
||||
*-----------------------------------------------------------------------*/
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
|
||||
|
||||
|
||||
/*
|
||||
* Using <stdint.h>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
/*
|
||||
* To support platform where unsigned long cannot be used interchangeably with
|
||||
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||
* unsigned long long or similar (this results in different C++ name mangling).
|
||||
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||
* platforms where the size of a pointer is larger than the size of long.
|
||||
*/
|
||||
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||
#define KHRONOS_USE_INTPTR_T
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif defined(__VMS ) || defined(__sgi)
|
||||
|
||||
/*
|
||||
* Using <inttypes.h>
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
|
||||
/*
|
||||
* Win32
|
||||
*/
|
||||
typedef __int32 khronos_int32_t;
|
||||
typedef unsigned __int32 khronos_uint32_t;
|
||||
typedef __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
|
||||
/*
|
||||
* Sun or Digital
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#if defined(__arch64__) || defined(_LP64)
|
||||
typedef long int khronos_int64_t;
|
||||
typedef unsigned long int khronos_uint64_t;
|
||||
#else
|
||||
typedef long long int khronos_int64_t;
|
||||
typedef unsigned long long int khronos_uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif 0
|
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#define KHRONOS_SUPPORT_INT64 0
|
||||
#define KHRONOS_SUPPORT_FLOAT 0
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Generic fallback
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms
|
||||
*/
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||
* to be the only LLP64 architecture in current use.
|
||||
*/
|
||||
#ifdef KHRONOS_USE_INTPTR_T
|
||||
typedef intptr_t khronos_intptr_t;
|
||||
typedef uintptr_t khronos_uintptr_t;
|
||||
#elif defined(_WIN64)
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64)
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_ssize_t;
|
||||
typedef unsigned long int khronos_usize_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT
|
||||
/*
|
||||
* Float type
|
||||
*/
|
||||
typedef float khronos_float_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_INT64
|
||||
/* Time types
|
||||
*
|
||||
* These types can be used to represent a time interval in nanoseconds or
|
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||
* time the system booted). The Unadjusted System Time is an unsigned
|
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||
* may be either signed or unsigned.
|
||||
*/
|
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits.
|
||||
*/
|
||||
#ifndef KHRONOS_MAX_ENUM
|
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enumerated boolean type
|
||||
*
|
||||
* Values other than zero should be considered to be true. Therefore
|
||||
* comparisons should not be made against KHRONOS_TRUE.
|
||||
*/
|
||||
typedef enum {
|
||||
KHRONOS_FALSE = 0,
|
||||
KHRONOS_TRUE = 1,
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* __khrplatform_h_ */
|
||||
15903
vendor/glad/include/glad/glad.h
vendored
Normal file
15903
vendor/glad/include/glad/glad.h
vendored
Normal file
File diff suppressed because one or more lines are too long
9075
vendor/glad/src/glad.c
vendored
Normal file
9075
vendor/glad/src/glad.c
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user