compiles with gcc again, OpenGL works - Vulkan is borked

This commit is contained in:
lachrymaLF 2025-01-23 22:06:36 -05:00
parent 49aad3c989
commit cbd9f9a693
17 changed files with 137 additions and 138 deletions

View file

@ -22,8 +22,8 @@
namespace {
SDL_Window* window;
u16 window_width = 1280;
u16 window_height = 720;
u16 window_width = 1920;
u16 window_height = 1080;
u64 init_time, last_time, current_time, delta_t;
bool running = false, rolling = true;
@ -37,7 +37,7 @@ namespace {
ADVect::MarkupTextTransitionTrack m_text{
.current{},
.pos_x = 280, .pos_y = 90, .w = 800, .h = 500,
.pos_x = 280, .pos_y = 90, .w = 1500, .h = 500,
.opacity = 1.0f, .fill = 0xFFFFFFFF
};
ADVect::TextTrack speaker = {
@ -79,7 +79,7 @@ namespace ADVect {
}
bgfx::Init bgfxInit;
bgfxInit.type = bgfx::RendererType::Count; // Automatically choose a renderer.
bgfxInit.type = bgfx::RendererType::OpenGL; // Automatically choose a renderer.
bgfxInit.resolution.width = window_width;
bgfxInit.resolution.height = window_height;
bgfxInit.resolution.reset = BGFX_RESET_VSYNC;
@ -244,7 +244,7 @@ namespace ADVect {
}
int main(int argc, char* argv[]) {
std::filesystem::current_path("E:\\Archive\\Projects\\NouVeL\\ADVect\\runtime");
std::filesystem::current_path("../../ADVect/runtime");
//std::filesystem::current_path("/Users/lachrymal/Projects/NouVeL/ADVect/runtime/");
NVL::Environment::ENVIRONMENT.enter({
{
@ -294,25 +294,25 @@ int main(int argc, char* argv[]) {
}
});
//std::vector<NVL::Parse::Scene> scenes = NVL::Parse::ParseFile("dialogue.nvl");
//if (scenes.empty()) {
// std::cerr << "Main: Empty NVL parse, check file" << std::endl;
// return EXIT_FAILURE;
//}
std::vector<NVL::Parse::Scene> scenes = NVL::Parse::ParseFile("dialogue.nvl");
if (scenes.empty()) {
std::cerr << "Main: Empty NVL parse, check file" << std::endl;
return EXIT_FAILURE;
}
//auto a = NVL::Compiler::Compile(scenes, 0);
//auto b = NVL::Compiler::Serialize(a);
auto e = NVL::Compiler::Compile(scenes, 0);
// auto b = NVL::Compiler::Serialize(a);
std::ifstream f;
f.open("mmoker.nvlb", std::ios::binary);
// std::ifstream f;
// f.open("mmoker.nvlb", std::ios::binary);
std::stringstream c;
c << f.rdbuf();
f.close();
// std::stringstream c;
// c << f.rdbuf();
// f.close();
std::istringstream d(c.str());
// std::istringstream d(c.str());
auto e = NVL::Compiler::Deserialize(d);
// auto e = NVL::Compiler::Deserialize(d);
if (!ADVect::Init("ADV Test", e)) return EXIT_FAILURE;
ADVect::Run();

View file

@ -1,11 +1,8 @@
#include "Graphics.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#include <bx/math.h>
#include <iostream>
#include <optional>
#include <algorithm>
#define STB_IMAGE_IMPLEMENTATION
@ -20,7 +17,7 @@ namespace {
switch (bgfx::getRendererType()) {
case bgfx::RendererType::Noop:
case bgfx::RendererType::Direct3D9: shaderPath = "shaders/dx9/"; break;
// case bgfx::RendererType::Direct3D9: shaderPath = "shaders/dx9/"; break;
case bgfx::RendererType::Direct3D11:
case bgfx::RendererType::Direct3D12: shaderPath = "shaders/dx11/"; break;
case bgfx::RendererType::Gnm: shaderPath = "shaders/pssl/"; break;
@ -71,53 +68,6 @@ namespace {
FT_Library library;
FT_Error error;
struct Font {
FT_Face face = nullptr;
std::unordered_map<NVL::Char, std::tuple<std::optional<bgfx::TextureHandle>, u32, u32, i32, i32, i32, i32>> cache{};
std::tuple<std::optional<bgfx::TextureHandle>, u32, u32, i32, i32, i32, i32>& get_char(NVL::Char c) {
if (cache.find(c) == cache.end()) {
FT_GlyphSlot slot = face->glyph;
error = FT_Load_Char(face, c, FT_LOAD_RENDER);
if (error) {
std::cerr << "ADV: Failed to load character" << std::endl;
}
if (slot->bitmap.width != 0) {
const bgfx::Memory* buf = bgfx::copy(slot->bitmap.buffer, slot->bitmap.pitch * slot->bitmap.rows);
cache.emplace(c, std::make_tuple(
bgfx::createTexture2D(
slot->bitmap.width,
slot->bitmap.rows,
false,
1,
bgfx::TextureFormat::A8,
BGFX_TEXTURE_NONE | BGFX_SAMPLER_UVW_CLAMP,
buf
),
slot->bitmap.width,
slot->bitmap.rows,
slot->bitmap_left,
slot->bitmap_top,
slot->advance.x,
slot->advance.y
));
}
else cache.emplace(c, std::make_tuple(
std::nullopt,
0,
0,
0,
0,
slot->advance.x,
slot->advance.y));
}
return cache[c];
}
};
std::optional<Font> get_font(const char* path) {
Font f;
@ -188,17 +138,6 @@ namespace {
bgfx::VertexLayout pcvDecl;
std::unordered_map<std::string, ImageTexture> imgs;
inline Font* ResolveStyleFlags(u32 style_flags) {
Font* f = &regular;
switch (style_flags) {
case TEXT_NONE: break;
case TEXT_BOLD: f = &bold; break;
case TEXT_ITALIC: break;
case TEXT_ITALIC | TEXT_BOLD: break;
}
return f;
}
inline void HandleMarkupFlags(const NVL::Environment::MarkupSegment& s, u32& style_flags, const NVL::String*& ruby) {
for (const auto& e : s.efs) {
@ -216,6 +155,59 @@ namespace {
}
namespace ADVect::Graphics {
std::tuple<std::optional<bgfx::TextureHandle>, u32, u32, i32, i32, i32, i32>& Font::get_char(NVL::Char c) {
if (cache.find(c) == cache.end()) {
FT_GlyphSlot slot = face->glyph;
error = FT_Load_Char(face, c, FT_LOAD_RENDER);
if (error) {
std::cerr << "ADV: Failed to load character" << std::endl;
}
if (slot->bitmap.width != 0) {
const bgfx::Memory* buf = bgfx::copy(slot->bitmap.buffer, slot->bitmap.pitch * slot->bitmap.rows);
cache.emplace(c, std::make_tuple(
bgfx::createTexture2D(
slot->bitmap.width,
slot->bitmap.rows,
false,
1,
bgfx::TextureFormat::A8,
BGFX_TEXTURE_NONE | BGFX_SAMPLER_UVW_CLAMP,
buf
),
slot->bitmap.width,
slot->bitmap.rows,
slot->bitmap_left,
slot->bitmap_top,
slot->advance.x,
slot->advance.y
));
}
else cache.emplace(c, std::make_tuple(
std::nullopt,
0,
0,
0,
0,
slot->advance.x,
slot->advance.y));
}
return cache[c];
}
Font* ResolveStyleFlags(u32 style_flags) {
Font* f = &regular;
switch (style_flags) {
case TEXT_NONE: break;
case TEXT_BOLD: f = &bold; break;
case TEXT_ITALIC: break;
case TEXT_ITALIC | TEXT_BOLD: break;
}
return f;
}
bool Init(u16 width, u16 height) {
error = FT_Init_FreeType(&library);
if (error) {
@ -312,36 +304,6 @@ namespace ADVect::Graphics {
DrawTexture(tex, pos_x, pos_y, w, h, (BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) & ~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS), a_program);
}
template <bool DoRender, bool Walk>
void RenderGlyph(NVL::Char c, std::conditional_t<Walk, i32&, i32> pos_x, std::conditional_t<Walk, i32&, i32> pos_y, u32 col, u32 style_flags) {
Font* f = ResolveStyleFlags(style_flags);
auto& [tx, w, h, l, t, x, y] = f->get_char(c);
pos_x += l;
if (auto& buf = tx; DoRender && tx && w != 0) {
DrawTextureStencilAlpha(*buf, pos_x, pos_y - (h - t), w, h);
}
pos_x += x >> 6;
pos_y += y >> 6;
}
template <bool DoRender, bool Walk>
void RenderString(const NVL::String& s, std::conditional_t<Walk, i32&, i32> pos_x, std::conditional_t<Walk, i32&, i32> pos_y, u32 col, u32 style_flags) {
for (const auto& c : s) {
RenderGlyph<DoRender>(c, pos_x, pos_y, col, style_flags);
}
}
template <bool DoRender, bool Walk>
void RenderString(NVL::String::const_iterator cbegin, NVL::String::const_iterator cend, std::conditional_t<Walk, i32&, i32> pos_x, std::conditional_t<Walk, i32&, i32> pos_y, u32 col, u32 style_flags) {
while (cbegin < cend) {
RenderGlyph<DoRender>(*cbegin++, pos_x, pos_y, col, style_flags);
}
}
void RenderStringCentered(const NVL::String& s, i32 pos_x, i32 pos_y, u32 col, u32 style_flags = TEXT_NONE) {
i32 copy_x = 0, copy_y = 0;
RenderString<false, true>(s, copy_x, copy_y, col, style_flags);
@ -358,27 +320,27 @@ namespace ADVect::Graphics {
NVL::String::const_iterator last_copy = last;
i32 copy_x = pos_x, copy_y = pos_y;
while (last != std::min(pos, halt)) {
RenderGlyph(*last++, pos_x, pos_y, col, style_flags);
RenderGlyph<true, true>(*last++, pos_x, pos_y, col, style_flags);
if (pos_x - reset_x > w) {
pos_x = reset_x;
pos_y -= f->face->size->metrics.height / 64;
}
if (last >= halt) {
RenderString<false>(last_copy, pos, copy_x, copy_y, col, style_flags);
RenderString<false, true>(last_copy, pos, copy_x, copy_y, col, style_flags);
return copy_x;
};
}
}
else while (last != end) { // Loop through all segments
i32 copy_x = pos_x, old_x = pos_x, copy_y = pos_y;
RenderString<false>(last, pos, copy_x, copy_y, col, style_flags);
RenderString<false, true>(last, pos, copy_x, copy_y, col, style_flags);
if (copy_x - reset_x > w) { // if walk exceeded max w
copy_x = reset_x, copy_y = pos_y; // try walk again from leftmost of box, see if a soft break works; reset y from last walk
RenderString<false>(last, pos, copy_x, copy_y, col, style_flags);
RenderString<false, true>(last, pos, copy_x, copy_y, col, style_flags);
if (copy_x - reset_x > w) { // soft break won't work, go back to old x and hard break
pos_x = old_x;
while (last != pos) {
RenderGlyph(*last++, pos_x, pos_y, col, style_flags);
RenderGlyph<true, true>(*last++, pos_x, pos_y, col, style_flags);
if (pos_x - reset_x > w) {
pos_x = reset_x;
pos_y -= f->face->size->metrics.height / 64;
@ -390,12 +352,12 @@ namespace ADVect::Graphics {
pos_x = reset_x;
pos_y -= f->face->size->metrics.height / 64;
last++;
RenderString(last, std::min(pos, halt), pos_x, pos_y, col, style_flags);
RenderString<true, true>(last, std::min(pos, halt), pos_x, pos_y, col, style_flags);
if (last >= halt) return copy_x;
}
}
else {
RenderString(last, std::min(pos, halt), pos_x, pos_y, col, style_flags);
RenderString<true, true>(last, std::min(pos, halt), pos_x, pos_y, col, style_flags);
if (last >= halt) return copy_x;
}

View file

@ -2,8 +2,12 @@
#include <SDL.h>
#include <optional>
#include <bgfx/bgfx.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <Common.h>
#include <Environment.h>
@ -27,18 +31,50 @@ namespace ADVect::Graphics {
};
ImageTexture* GetImageTextureFromFile(const std::string& file);
struct Font {
FT_Face face = nullptr;
std::unordered_map<NVL::Char, std::tuple<std::optional<bgfx::TextureHandle>, u32, u32, i32, i32, i32, i32>> cache{};
std::tuple<std::optional<bgfx::TextureHandle>, u32, u32, i32, i32, i32, i32>& get_char(NVL::Char c);
};
void DrawTexture(const bgfx::TextureHandle& tex, i32 pos_x, i32 pos_y, u32 w, u32 h, u64 state, const bgfx::ProgramHandle& pg);
void DrawTextureImage(const bgfx::TextureHandle& tex, i32 pos_x, i32 pos_y, u32 w, u32 h);
void DrawTextureImage(const ImageTexture& img, i32 pos_x, i32 pos_y);
void DrawTextureImageAlpha(const ImageTexture& img, i32 pos_x, i32 pos_y, f32 alpha);
void DrawTextureStencilAlpha(const bgfx::TextureHandle& tex, i32 pos_x, i32 pos_y, u32 w, u32 h);
template <bool DoRender = true, bool Walk = true>
void RenderGlyph(NVL::Char c, std::conditional_t<Walk, i32&, i32> pos_x, std::conditional_t<Walk, i32&, i32> pos_y, u32 col, u32 style_flags = TEXT_NONE);
template <bool DoRender = true, bool Walk = true>
void RenderString(const NVL::String& s, std::conditional_t<Walk, i32&, i32> pos_x, std::conditional_t<Walk, i32&, i32> pos_y, u32 col, u32 style_flags = TEXT_NONE);
template <bool DoRender = true, bool Walk = true>
void RenderString(NVL::String::const_iterator cbegin, NVL::String::const_iterator cend, std::conditional_t<Walk, i32&, i32> pos_x, std::conditional_t<Walk, i32&, i32> pos_y, u32 col, u32 style_flags = TEXT_NONE);
Font* ResolveStyleFlags(u32 style_flags);
template <bool DoRender, bool Walk>
void RenderGlyph(NVL::Char c, std::conditional_t<Walk, i32&, i32> pos_x, std::conditional_t<Walk, i32&, i32> pos_y, u32 col, u32 style_flags) {
Font* f = ResolveStyleFlags(style_flags);
auto& [tx, w, h, l, t, x, y] = f->get_char(c);
pos_x += l;
if (auto& buf = tx; DoRender && tx && w != 0) {
DrawTextureStencilAlpha(*buf, pos_x, pos_y - (h - t), w, h);
}
pos_x += x >> 6;
pos_y += y >> 6;
}
template <bool DoRender, bool Walk>
void RenderString(const NVL::String& s, std::conditional_t<Walk, i32&, i32> pos_x, std::conditional_t<Walk, i32&, i32> pos_y, u32 col, u32 style_flags) {
for (const auto& c : s) {
RenderGlyph<DoRender, true>(c, pos_x, pos_y, col, style_flags);
}
}
template <bool DoRender, bool Walk>
void RenderString(NVL::String::const_iterator cbegin, NVL::String::const_iterator cend, std::conditional_t<Walk, i32&, i32> pos_x, std::conditional_t<Walk, i32&, i32> pos_y, u32 col, u32 style_flags) {
while (cbegin < cend) {
RenderGlyph<DoRender, true>(*cbegin++, pos_x, pos_y, col, style_flags);
}
}
i32 RenderSubstringBox(const NVL::String& s, i32& pos_x, i32& pos_y, i32 reset_x, u32 w, u32 col, u32 style_flags = TEXT_NONE, size_t s_end = NVL::String::npos);
void RenderSubstringMarkupBox(const NVL::Environment::MarkupString& ms, i32 pos_x, i32 pos_y, u32 w, u32 col, size_t end = NVL::String::npos);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 4.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 409 KiB

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 714 KiB

After

Width:  |  Height:  |  Size: 4 MiB

View file

@ -1,17 +1,14 @@
import subprocess, os
#SHADERC = "..\\out\\install\\x64-Debug\\bin\\shaderc"
SHADERC = "/Users/lachrymal/Projects/NouVeL/build/ADVect/ext/bgfx/Debug/shaderc"
#OUT = "..\\out\\build\\x64-Debug\\ADVect\\shaders\\"
# OUT = "..\\build\\ADVect\\shaders\\"
OUT = "/Users/lachrymal/Projects/NouVeL/ADVect/runtime/shaders/"
SHADERC = "/home/lach/Projects/NouVeL/build/ADVect/ext/bgfx/cmake/bgfx/shaderc"
OUT = "/home/lach/Projects/NouVeL/ADVect/runtime/shaders/"
P = lambda location, platform, frag, vert: { 'location': location, 'platform': platform, 'frag': frag, 'vert': vert }
plats = [
# P('glsl', 'windows', '140', '140'),
# P('dx11', 'windows', 'ps_5_0', 'vs_5_0'),
# P('spirv', 'windows', 'spirv', 'spirv'),
P('metal', 'osx', 'metal', 'metal')
P('spirv', 'linux', 'spirv', 'spirv'),
# P('metal', 'osx', 'metal', 'metal')
]
for root, dirs, _ in os.walk('shaders'):
@ -22,15 +19,15 @@ for root, dirs, _ in os.walk('shaders'):
"--platform", config['platform'],
"--profile", config['frag'],
"--varyingdef", os.path.join(root, name, "varying.def.sc"),
"-i", "/Users/lachrymal/Projects/NouVeL/ADVect/ext/bgfx/bgfx/examples/common",
"-i", "/Users/lachrymal/Projects/NouVeL/ADVect/ext/bgfx/bgfx/src",
"-i", "/home/lach/Projects/NouVeL/ADVect/ext/bgfx/bgfx/examples/common",
"-i", "/home/lach/Projects/NouVeL/ADVect/ext/bgfx/bgfx/src",
"-o", OUT + config['location'] + "\\" + name + ".frag.bin"])
subprocess.run([SHADERC, "-f", os.path.join(root, name, name + '.vert'),
"--type", "vertex",
"--platform", config['platform'],
"--profile", config['vert'],
"--varyingdef", os.path.join(root, name, "varying.def.sc"),
"-i", "/Users/lachrymal/Projects/NouVeL/ADVect/ext/bgfx/bgfx/examples/common",
"-i", "/Users/lachrymal/Projects/NouVeL/ADVect/ext/bgfx/bgfx/src",
"-i", "/home/lach/Projects/NouVeL/ADVect/ext/bgfx/bgfx/examples/common",
"-i", "/home/lach/Projects/NouVeL/ADVect/ext/bgfx/bgfx/src",
"-o", OUT + config['location'] + "\\" + name + ".vert.bin"])

View file

@ -7,7 +7,7 @@ namespace {
}
void SerializeString(std::ostringstream& s, const NVL::String& st) {
u16 v = st.size() * sizeof NVL::Char;
u16 v = st.size() * sizeof(NVL::Char);
s.write(reinterpret_cast<const char*>(&v), sizeof v);
s.write(reinterpret_cast<const char*>(st.c_str()), v);
}
@ -45,9 +45,9 @@ namespace {
NVL::String DeserializeString(std::istringstream& s) {
u16 size{};
DeserializeDirect(s, size);
u8* str = new u8[size + sizeof NVL::Char];
u8* str = new u8[size + sizeof(NVL::Char)];
s.read(reinterpret_cast<char*>(str), size);
reinterpret_cast<NVL::Char*>(str)[size / sizeof NVL::Char] = u'\0';
reinterpret_cast<NVL::Char*>(str)[size / sizeof(NVL::Char)] = u'\0';
NVL::String st = NVL::String(reinterpret_cast<NVL::Char*>(str));
delete[] str;
return st;

View file

@ -1,2 +1,5 @@
# NouVeL
NVL Script Engine
## Building
Use `CMakeLists.txt` in the root directory. The default build target is `Game`.

View file

@ -20,6 +20,7 @@
gdb
pkg-config
# jetbrains.clion
python3
xorg.xorgproto
xorg.libX11