feat(BgfxRenderer): Complete Phase 2-3 with shaders and triangle rendering

Phase 2 - RHI Layer:
- Fix Command struct default constructor for union with non-trivial types
- Add missing mutex includes in ResourceCache.cpp
- Fix const_cast for getChildReadOnly in SceneCollector

Phase 3 - Shaders & Visual Test:
- Add ShaderManager for centralized shader loading
- Embed pre-compiled shaders (OpenGL, Vulkan, DX11, Metal)
- Add test_20_bgfx_rhi: 23 unit tests for RHI components
- Add test_21_bgfx_triangle: visual test rendering colored triangle

Test results:
- RHI unit tests: 23/23 passing
- Visual test: ~567 FPS with Vulkan renderer

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
StillHammer 2025-11-26 16:43:17 +08:00
parent 69f5a1cc6c
commit 1443c1209e
14 changed files with 1362 additions and 1 deletions

View File

@ -43,6 +43,9 @@ add_library(BgfxRenderer SHARED
# RenderGraph # RenderGraph
RenderGraph/RenderGraph.cpp RenderGraph/RenderGraph.cpp
# Shaders
Shaders/ShaderManager.cpp
# Passes # Passes
Passes/ClearPass.cpp Passes/ClearPass.cpp
Passes/SpritePass.cpp Passes/SpritePass.cpp

View File

@ -39,6 +39,12 @@ struct Command {
struct { uint32_t indexCount; uint32_t instanceCount; } drawInstanced; struct { uint32_t indexCount; uint32_t instanceCount; } drawInstanced;
struct { ViewId view; ShaderHandle shader; uint32_t depth; } submit; struct { ViewId view; ShaderHandle shader; uint32_t depth; } submit;
}; };
// Default constructor required because union contains non-trivial types
Command() : type(CommandType::SetState) { std::memset(&setState, 0, sizeof(setState)); }
~Command() = default;
Command(const Command&) = default;
Command& operator=(const Command&) = default;
}; };
// ============================================================================ // ============================================================================

View File

@ -1,5 +1,7 @@
#include "ResourceCache.h" #include "ResourceCache.h"
#include "../RHI/RHIDevice.h" #include "../RHI/RHIDevice.h"
#include <mutex>
#include <shared_mutex>
namespace grove { namespace grove {

View File

@ -178,7 +178,9 @@ void SceneCollector::parseSprite(const IDataNode& data) {
void SceneCollector::parseSpriteBatch(const IDataNode& data) { void SceneCollector::parseSpriteBatch(const IDataNode& data) {
// Get sprites child node and iterate // Get sprites child node and iterate
IDataNode* spritesNode = data.getChildReadOnly("sprites"); // Note: const_cast needed because IDataNode::getChildReadOnly() is not const
// (it should be, but changing the interface requires broader refactoring)
IDataNode* spritesNode = const_cast<IDataNode&>(data).getChildReadOnly("sprites");
if (!spritesNode) return; if (!spritesNode) return;
for (const auto& name : spritesNode->getChildNames()) { for (const auto& name : spritesNode->getChildNames()) {

View File

@ -0,0 +1,131 @@
#include "ShaderManager.h"
// Embedded shader bytecode
#include "vs_color.bin.h"
#include "fs_color.bin.h"
namespace grove {
ShaderManager::~ShaderManager() {
shutdown();
}
void ShaderManager::init(bgfx::RendererType::Enum rendererType) {
if (m_initialized) {
return;
}
m_rendererType = rendererType;
loadBuiltinShaders();
m_initialized = true;
}
void ShaderManager::shutdown() {
for (auto& [name, program] : m_programs) {
if (bgfx::isValid(program)) {
bgfx::destroy(program);
}
}
m_programs.clear();
m_initialized = false;
}
bgfx::ProgramHandle ShaderManager::getProgram(const std::string& name) {
auto it = m_programs.find(name);
if (it != m_programs.end()) {
return it->second;
}
return BGFX_INVALID_HANDLE;
}
bool ShaderManager::hasProgram(const std::string& name) const {
return m_programs.find(name) != m_programs.end();
}
bgfx::ShaderHandle ShaderManager::loadShader(const char* name) {
const uint8_t* data = nullptr;
uint32_t size = 0;
bool isVertex = (name[0] == 'v');
switch (m_rendererType) {
case bgfx::RendererType::OpenGL:
if (isVertex) {
data = vs_drawstress_glsl;
size = sizeof(vs_drawstress_glsl);
} else {
data = fs_drawstress_glsl;
size = sizeof(fs_drawstress_glsl);
}
break;
case bgfx::RendererType::OpenGLES:
if (isVertex) {
data = vs_drawstress_essl;
size = sizeof(vs_drawstress_essl);
} else {
data = fs_drawstress_essl;
size = sizeof(fs_drawstress_essl);
}
break;
case bgfx::RendererType::Vulkan:
if (isVertex) {
data = vs_drawstress_spv;
size = sizeof(vs_drawstress_spv);
} else {
data = fs_drawstress_spv;
size = sizeof(fs_drawstress_spv);
}
break;
case bgfx::RendererType::Direct3D11:
case bgfx::RendererType::Direct3D12:
if (isVertex) {
data = vs_drawstress_dx11;
size = sizeof(vs_drawstress_dx11);
} else {
data = fs_drawstress_dx11;
size = sizeof(fs_drawstress_dx11);
}
break;
case bgfx::RendererType::Metal:
if (isVertex) {
data = vs_drawstress_mtl;
size = sizeof(vs_drawstress_mtl);
} else {
data = fs_drawstress_mtl;
size = sizeof(fs_drawstress_mtl);
}
break;
default:
return BGFX_INVALID_HANDLE;
}
return bgfx::createShader(bgfx::copy(data, size));
}
void ShaderManager::loadBuiltinShaders() {
// Load color shader program (for sprites, debug shapes, etc.)
bgfx::ShaderHandle vsh = loadShader("vs_color");
bgfx::ShaderHandle fsh = loadShader("fs_color");
if (bgfx::isValid(vsh) && bgfx::isValid(fsh)) {
bgfx::ProgramHandle colorProgram = bgfx::createProgram(vsh, fsh, true);
if (bgfx::isValid(colorProgram)) {
m_programs["color"] = colorProgram;
// Alias for sprites (same shader for now)
m_programs["sprite"] = colorProgram;
m_programs["debug"] = colorProgram;
}
}
// TODO: Add more specialized shaders as needed:
// - "sprite_textured" for textured sprites
// - "text" for text rendering
// - "particle" for particle systems
}
} // namespace grove

View File

@ -0,0 +1,61 @@
#pragma once
#include "../RHI/RHITypes.h"
#include <bgfx/bgfx.h>
#include <string>
#include <unordered_map>
namespace grove {
/**
* @brief Manages shader loading and caching for BgfxRenderer
*
* Loads embedded pre-compiled shaders based on the current renderer type.
* Supports: OpenGL, OpenGL ES, Vulkan, DirectX 11/12, Metal
*/
class ShaderManager {
public:
ShaderManager() = default;
~ShaderManager();
// Non-copyable
ShaderManager(const ShaderManager&) = delete;
ShaderManager& operator=(const ShaderManager&) = delete;
/**
* @brief Initialize with current renderer type
*/
void init(bgfx::RendererType::Enum rendererType);
/**
* @brief Shutdown and destroy all shaders
*/
void shutdown();
/**
* @brief Get a shader program by name
* @param name Program name (e.g., "color", "sprite", "debug")
* @return Valid program handle or invalid handle if not found
*/
bgfx::ProgramHandle getProgram(const std::string& name);
/**
* @brief Check if a program exists
*/
bool hasProgram(const std::string& name) const;
/**
* @brief Get current renderer type
*/
bgfx::RendererType::Enum getRendererType() const { return m_rendererType; }
private:
bgfx::ShaderHandle loadShader(const char* name);
void loadBuiltinShaders();
bgfx::RendererType::Enum m_rendererType = bgfx::RendererType::Count;
std::unordered_map<std::string, bgfx::ProgramHandle> m_programs;
bool m_initialized = false;
};
} // namespace grove

View File

@ -0,0 +1,97 @@
static const uint8_t fs_drawstress_glsl[87] =
{
0x46, 0x53, 0x48, 0x0b, 0xa4, 0x8b, 0xef, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, // FSH....I......D.
0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, // ..varying vec4 v
0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, // _color0;.void ma
0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, // in ().{. gl_Fra
0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // gColor = v_color
0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // 0;.}...
};
static const uint8_t fs_drawstress_essl[93] =
{
0x46, 0x53, 0x48, 0x0b, 0xa4, 0x8b, 0xef, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, // FSH....I......J.
0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, // ..varying highp
0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, // vec4 v_color0;.v
0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{.
0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x76, // gl_FragColor = v
0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // _color0;.}...
};
static const uint8_t fs_drawstress_spv[406] =
{
0x46, 0x53, 0x48, 0x0b, 0xa4, 0x8b, 0xef, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, // FSH....I........
0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0b, 0x00, 0x08, 0x00, 0x31, 0x00, // ....#.........1.
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, // ................
0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, // ......GLSL.std.4
0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, // 50..............
0x00, 0x00, 0x0f, 0x00, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, // ..............ma
0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x10, 0x00, // in....%...0.....
0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, // ................
0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, // ..............ma
0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x25, 0x00, 0x00, 0x00, 0x76, 0x5f, // in........%...v_
0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x30, 0x00, // color0........0.
0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, // ..bgfx_FragData0
0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, // ..G...%.........
0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, // ..G...0.........
0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, // ..........!.....
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, // .............. .
0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, // ................
0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, // .. ...!.........
0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x01, 0x00, // ..;...!...%.....
0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, // .. .../.........
0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x03, 0x00, // ..;.../...0.....
0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, // ..6.............
0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x3d, 0x00, // ..............=.
0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x3e, 0x00, // ......&...%...>.
0x03, 0x00, 0x30, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, // ..0...&.......8.
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // ......
};
static const uint8_t fs_drawstress_dx11[270] =
{
0x46, 0x53, 0x48, 0x0b, 0xa4, 0x8b, 0xef, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, // FSH....I........
0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0x50, 0xef, 0x6d, 0x1a, 0x00, 0x93, 0x06, 0x9c, 0xf0, 0x68, // ..DXBCP.m......h
0xce, 0x7c, 0xb9, 0x39, 0x12, 0x62, 0x01, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x03, 0x00, // .|.9.b..........
0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x49, 0x53, // ..,...........IS
0x47, 0x4e, 0x4c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, // GNL...........8.
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // ................
0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......D.........
0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x53, 0x56, // ..............SV
0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, // _POSITION.COLOR.
0xab, 0xab, 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, // ..OSGN,.........
0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, // .. .............
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, // ..........SV_TAR
0x47, 0x45, 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x45, 0x58, 0x3c, 0x00, 0x00, 0x00, 0x50, 0x00, // GET...SHEX<...P.
0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x6a, 0x08, 0x00, 0x01, 0x62, 0x10, 0x00, 0x03, 0xf2, 0x10, // ......j...b.....
0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, // ......e.... ....
0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x1e, // ..6.... ......F.
0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, // ......>.......
};
static const uint8_t fs_drawstress_mtl[386] =
{
0x46, 0x53, 0x48, 0x0b, 0xa4, 0x8b, 0xef, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x01, // FSH....I......l.
0x00, 0x00, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, // ..#include <meta
0x6c, 0x5f, 0x73, 0x74, 0x64, 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, // l_stdlib>.#inclu
0x64, 0x65, 0x20, 0x3c, 0x73, 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, // de <simd/simd.h>
0x0a, 0x0a, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, // ..using namespac
0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // e metal;..struct
0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out
0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // .{. float4 bg
0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData0 [[c
0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, // olor(0)]];.};..s
0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, // truct xlatMtlMai
0x6e, 0x5f, 0x69, 0x6e, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, // n_in.{. float
0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x5b, 0x5b, 0x75, 0x73, 0x65, // 4 v_color0 [[use
0x72, 0x28, 0x6c, 0x6f, 0x63, 0x6e, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, // r(locn0)]];.};..
0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, // fragment xlatMtl
0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, // Main_out xlatMtl
0x4d, 0x61, 0x69, 0x6e, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, // Main(xlatMtlMain
0x5f, 0x69, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, // _in in [[stage_i
0x6e, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, // n]]).{. xlatM
0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, // tlMain_out out =
0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, // {};. out.bgf
0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x3d, 0x20, 0x69, 0x6e, // x_FragData0 = in
0x2e, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, // .v_color0;. r
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x00, // eturn out;.}....
0x00, 0x00, // ..
};
extern const uint8_t* fs_drawstress_pssl;
extern const uint32_t fs_drawstress_pssl_size;

View File

@ -0,0 +1,8 @@
$input v_color0
#include <bgfx_shader.sh>
void main()
{
gl_FragColor = v_color0;
}

View File

@ -0,0 +1,8 @@
// Varying definitions for bgfx shaders
vec4 v_color0 : COLOR0 = vec4(1.0, 1.0, 1.0, 1.0);
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
vec3 a_position : POSITION;
vec4 a_color0 : COLOR0;
vec2 a_texcoord0 : TEXCOORD0;

View File

@ -0,0 +1,203 @@
static const uint8_t vs_drawstress_glsl[303] =
{
0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x8b, 0xef, 0x49, 0x01, 0x00, 0x0f, 0x75, // VSH........I...u
0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, // _modelViewProj..
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x61, 0x74, 0x74, 0x72, // ............attr
0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, // ibute vec4 a_col
0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x76, // or0;.attribute v
0x65, 0x63, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, // ec3 a_position;.
0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, // varying vec4 v_c
0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x6d, // olor0;.uniform m
0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, // at4 u_modelViewP
0x72, 0x6f, 0x6a, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, // roj;.void main (
0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, // ).{. vec4 tmpva
0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, // r_1;. tmpvar_1.
0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, // w = 1.0;. tmpva
0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, // r_1.xyz = a_posi
0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, // tion;. gl_Posit
0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x28, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, // ion = (u_modelVi
0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // ewProj * tmpvar_
0x31, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x3d, // 1);. v_color0 =
0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // a_color0;.}...
};
static const uint8_t vs_drawstress_essl[333] =
{
0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x8b, 0xef, 0x49, 0x01, 0x00, 0x0f, 0x75, // VSH........I...u
0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, // _modelViewProj..
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x61, 0x74, 0x74, 0x72, // ........ ...attr
0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, // ibute highp vec4
0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, // a_color0;.attri
0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, // bute highp vec3
0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, // a_position;.vary
0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, // ing highp vec4 v
0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, // _color0;.uniform
0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x6d, 0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x6d, 0x6f, // highp mat4 u_mo
0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x3b, 0x0a, 0x76, 0x6f, 0x69, // delViewProj;.voi
0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x68, 0x69, // d main ().{. hi
0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // ghp vec4 tmpvar_
0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, // 1;. tmpvar_1.w
0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // = 1.0;. tmpvar_
0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, // 1.xyz = a_positi
0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, // on;. gl_Positio
0x6e, 0x20, 0x3d, 0x20, 0x28, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, // n = (u_modelView
0x50, 0x72, 0x6f, 0x6a, 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x29, // Proj * tmpvar_1)
0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x3d, 0x20, 0x61, // ;. v_color0 = a
0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // _color0;.}...
};
static const uint8_t vs_drawstress_spv[1060] =
{
0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x8b, 0xef, 0x49, 0x01, 0x00, 0x0f, 0x75, // VSH........I...u
0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, // _modelViewProj..
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, // ..............#.
0x00, 0x00, 0x01, 0x00, 0x0b, 0x00, 0x08, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........_.......
0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, // ................
0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, // GLSL.std.450....
0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x09, 0x00, // ................
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, // ........main....
0x2f, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, // /...3...<...?...
0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, // ................
0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, // ....main........
0x20, 0x00, 0x00, 0x00, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x6c, 0x6f, 0x63, 0x6b, // ...UniformBlock
0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x07, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........ .......
0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x00, // u_modelViewProj.
0x05, 0x00, 0x03, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, // ...."...........
0x2f, 0x00, 0x00, 0x00, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, // /...a_color0....
0x05, 0x00, 0x05, 0x00, 0x33, 0x00, 0x00, 0x00, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, // ....3...a_positi
0x6f, 0x6e, 0x00, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, // on......<...@ent
0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2e, 0x67, 0x6c, // ryPointOutput.gl
0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x09, 0x00, // _Position.......
0x3f, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, // ?...@entryPointO
0x75, 0x74, 0x70, 0x75, 0x74, 0x2e, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x00, 0x00, // utput.v_color0..
0x48, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, // H... ...........
0x48, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, // H... .......#...
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ....H... .......
0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x00, // ........G... ...
0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, // ....G..."..."...
0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, // ....G..."...!...
0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, // ....G.../.......
0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x33, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, // ....G...3.......
0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, // ....G...<.......
0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, // ....G...?.......
0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, // ............!...
0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, // ................
0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, // ...............
0x04, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, // ................
0x03, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, // ............ ...
0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, // ....+...........
0x00, 0x00, 0x80, 0x3f, 0x2b, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, // ...?+...........
0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x04, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, // ................
0x04, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, // ........ .......
0x20, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, // ...!....... ...
0x3b, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // ;...!...".......
0x20, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, // ...#...........
0x20, 0x00, 0x04, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, // ...............
0x3b, 0x00, 0x04, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // ;......./.......
0x20, 0x00, 0x04, 0x00, 0x32, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, // ...2...........
0x3b, 0x00, 0x04, 0x00, 0x32, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // ;...2...3.......
0x20, 0x00, 0x04, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, // ...;...........
0x3b, 0x00, 0x04, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // ;...;...<.......
0x3b, 0x00, 0x04, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // ;...;...?.......
0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 6...............
0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, // ............=...
0x07, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, // ....0.../...=...
0x09, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, // ....4...3...Q...
0x06, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ....X...4.......
0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, // Q.......Y...4...
0x01, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, // ....Q.......Z...
0x34, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, // 4.......P.......
0x5b, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, // [...X...Y...Z...
0x15, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x23, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, // ....A...#.......
0x22, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x1f, 0x00, 0x00, 0x00, // ".......=.......
0x5d, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x90, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, // ]...............
0x5e, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x5d, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, // ^...[...]...>...
0x3c, 0x00, 0x00, 0x00, 0x5e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x3f, 0x00, 0x00, 0x00, // <...^...>...?...
0x30, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x02, 0x05, 0x00, // 0.......8.......
0x01, 0x00, 0x40, 0x00, // ..@.
};
static const uint8_t vs_drawstress_dx11[524] =
{
0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x8b, 0xef, 0x49, 0x01, 0x00, 0x0f, 0x75, // VSH........I...u
0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x00, // _modelViewProj..
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x01, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, // ............DXBC
0x19, 0x40, 0x51, 0x48, 0x64, 0xf0, 0x4f, 0x1e, 0x9e, 0x94, 0x2e, 0xc7, 0x38, 0x04, 0x0f, 0xf4, // .@QHd.O.....8...
0x01, 0x00, 0x00, 0x00, 0xd8, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, // ............,...
0x7c, 0x00, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x48, 0x00, 0x00, 0x00, // |.......ISGNH...
0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........8.......
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, // ................
0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // >...............
0x01, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0x50, 0x4f, // ........COLOR.PO
0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0xab, 0x4f, 0x53, 0x47, 0x4e, 0x4c, 0x00, 0x00, 0x00, // SITION..OSGNL...
0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........8.......
0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, // ................
0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // D...............
0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, // ........SV_POSIT
0x49, 0x4f, 0x4e, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0xab, 0xab, 0x53, 0x48, 0x45, 0x58, // ION.COLOR...SHEX
0x00, 0x01, 0x00, 0x00, 0x50, 0x00, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x6a, 0x08, 0x00, 0x01, // ....P...@...j...
0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, // Y...F. .........
0x5f, 0x00, 0x00, 0x03, 0xf2, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, // _..........._...
0x72, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x04, 0xf2, 0x20, 0x10, 0x00, // r.......g.... ..
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, // ........e.... ..
0x01, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x08, // ....h.......8...
0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x15, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, // ........V.......
0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, // F. .........2...
0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // ........F. .....
0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, // ............F...
0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....2...........
0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xa6, 0x1a, 0x10, 0x00, // F. .............
0x01, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, // ....F...........
0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // . ......F.......
0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, // F. .........6...
0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // . ......F.......
0x3e, 0x00, 0x00, 0x01, 0x00, 0x02, 0x05, 0x00, 0x01, 0x00, 0x40, 0x00, // >.........@.
};
static const uint8_t vs_drawstress_mtl[733] =
{
0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x8b, 0xef, 0x49, 0x01, 0x00, 0x0f, 0x75, // VSH........I...u
0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, // _modelViewProj..
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa9, 0x02, 0x00, 0x00, 0x23, 0x69, 0x6e, 0x63, // ............#inc
0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, 0x6c, // lude <metal_stdl
0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, 0x69, // ib>.#include <si
0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, 0x73, 0x69, 0x6e, // md/simd.h>..usin
0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, // g namespace meta
0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, 0x62, // l;..struct _Glob
0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x78, // al.{. float4x
0x34, 0x20, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, // 4 u_modelViewPro
0x6a, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, // j;.};..struct xl
0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x0a, 0x7b, 0x0a, // atMtlMain_out.{.
0x09, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x6d, 0x65, 0x74, 0x61, // .float bgfx_meta
0x6c, 0x5f, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x53, 0x69, 0x7a, 0x65, 0x20, 0x5b, 0x5b, 0x70, 0x6f, // l_pointSize [[po
0x69, 0x6e, 0x74, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x5d, 0x5d, 0x20, 0x3d, 0x20, 0x31, 0x3b, 0x0a, // int_size]] = 1;.
0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x5f, 0x65, 0x6e, 0x74, 0x72, // float4 _entr
0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x63, // yPointOutput_v_c
0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x5b, 0x5b, 0x75, 0x73, 0x65, 0x72, 0x28, 0x6c, 0x6f, 0x63, // olor0 [[user(loc
0x6e, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, // n0)]];. float
0x34, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5b, 0x5b, // 4 gl_Position [[
0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, // position]];.};..
0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, // struct xlatMtlMa
0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, // in_in.{. floa
0x74, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x5b, 0x5b, 0x61, 0x74, // t4 a_color0 [[at
0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // tribute(0)]];.
0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, // float3 a_posit
0x69, 0x6f, 0x6e, 0x20, 0x5b, 0x5b, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, // ion [[attribute(
0x31, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, // 1)]];.};..vertex
0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out
0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x28, 0x78, 0x6c, 0x61, // xlatMtlMain(xla
0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x5b, // tMtlMain_in in [
0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, // [stage_in]], con
0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, // stant _Global& _
0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, // mtl_u [[buffer(0
0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, // )]]).{. xlatM
0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, // tlMain_out out =
0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x67, 0x6c, 0x5f, // {};. out.gl_
0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, // Position = _mtl_
0x75, 0x2e, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, // u.u_modelViewPro
0x6a, 0x20, 0x2a, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x28, 0x69, 0x6e, 0x2e, 0x61, 0x5f, // j * float4(in.a_
0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, 0x0a, // position, 1.0);.
0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x5f, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, // out._entryPo
0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // intOutput_v_colo
0x72, 0x30, 0x20, 0x3d, 0x20, 0x69, 0x6e, 0x2e, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, // r0 = in.a_color0
0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, // ;. return out
0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x02, 0x05, 0x00, 0x01, 0x00, 0x40, 0x00, // ;.}........@.
};
extern const uint8_t* vs_drawstress_pssl;
extern const uint32_t vs_drawstress_pssl_size;

View File

@ -0,0 +1,10 @@
$input a_position, a_color0
$output v_color0
#include <bgfx_shader.sh>
void main()
{
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
v_color0 = a_color0;
}

View File

@ -626,3 +626,54 @@ target_link_libraries(benchmark_e2e PRIVATE
GroveEngine::impl GroveEngine::impl
topictree::topictree topictree::topictree
) )
# ================================================================================
# BgfxRenderer Tests (only if GROVE_BUILD_BGFX_RENDERER is ON)
# ================================================================================
if(GROVE_BUILD_BGFX_RENDERER)
# Test 20: BgfxRenderer RHI Unit Tests (no window required)
add_executable(test_20_bgfx_rhi
integration/test_20_bgfx_rhi.cpp
../modules/BgfxRenderer/RHI/RHICommandBuffer.cpp
../modules/BgfxRenderer/Frame/FrameAllocator.cpp
)
target_include_directories(test_20_bgfx_rhi PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../modules/BgfxRenderer
)
target_link_libraries(test_20_bgfx_rhi PRIVATE
GroveEngine::core
)
# CTest integration
add_test(NAME BgfxRHI COMMAND test_20_bgfx_rhi WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
# Test 21: Visual Triangle Test (requires SDL2 and display)
find_package(SDL2 QUIET)
if(SDL2_FOUND OR EXISTS "/usr/include/SDL2/SDL.h")
add_executable(test_21_bgfx_triangle
visual/test_bgfx_triangle.cpp
)
target_include_directories(test_21_bgfx_triangle PRIVATE
/usr/include/SDL2
)
target_link_libraries(test_21_bgfx_triangle PRIVATE
bgfx
bx
SDL2
pthread
dl
X11
GL
)
# Not added to CTest (requires display)
message(STATUS "Visual test 'test_21_bgfx_triangle' enabled (run manually)")
else()
message(STATUS "SDL2 not found - visual tests disabled")
endif()
endif()

View File

@ -0,0 +1,447 @@
/**
* Test 20: BgfxRenderer RHI Unit Tests
*
* Tests the RHI layer components without requiring a graphical window:
* - Command buffer recording
* - Frame packet construction
* - Scene collector parsing
* - Render graph compilation
*/
#include <iostream>
#include <cassert>
#include <cstring>
// Include RHI components directly (no bgfx needed for these tests)
#include "../../modules/BgfxRenderer/RHI/RHITypes.h"
#include "../../modules/BgfxRenderer/RHI/RHICommandBuffer.h"
#include "../../modules/BgfxRenderer/Frame/FramePacket.h"
#include "../../modules/BgfxRenderer/Frame/FrameAllocator.h"
using namespace grove;
using namespace grove::rhi;
// ============================================================================
// Test Helpers
// ============================================================================
static int g_testsPassed = 0;
static int g_testsFailed = 0;
#define TEST(name) \
std::cout << " Testing: " << #name << "... "; \
try { test_##name(); g_testsPassed++; std::cout << "PASS\n"; } \
catch (const std::exception& e) { g_testsFailed++; std::cout << "FAIL: " << e.what() << "\n"; } \
catch (...) { g_testsFailed++; std::cout << "FAIL: Unknown exception\n"; }
#define ASSERT(cond) \
if (!(cond)) { throw std::runtime_error("Assertion failed: " #cond); }
// ============================================================================
// RHI Types Tests
// ============================================================================
void test_handle_validity() {
TextureHandle tex;
ASSERT(!tex.isValid());
tex.id = 42;
ASSERT(tex.isValid());
BufferHandle buf;
ASSERT(!buf.isValid());
ShaderHandle shader;
ASSERT(!shader.isValid());
UniformHandle uniform;
ASSERT(!uniform.isValid());
}
void test_render_state_defaults() {
RenderState state;
ASSERT(state.blend == BlendMode::Alpha);
ASSERT(state.cull == CullMode::None);
ASSERT(state.depthTest == false);
ASSERT(state.depthWrite == false);
}
void test_texture_desc() {
TextureDesc desc;
ASSERT(desc.width == 0);
ASSERT(desc.height == 0);
ASSERT(desc.mipLevels == 1);
ASSERT(desc.format == TextureDesc::RGBA8);
ASSERT(desc.data == nullptr);
}
void test_buffer_desc() {
BufferDesc desc;
ASSERT(desc.size == 0);
ASSERT(desc.data == nullptr);
ASSERT(desc.dynamic == false);
ASSERT(desc.type == BufferDesc::Vertex);
}
// ============================================================================
// Command Buffer Tests
// ============================================================================
void test_command_buffer_empty() {
RHICommandBuffer cmd;
ASSERT(cmd.size() == 0);
ASSERT(cmd.getCommands().empty());
}
void test_command_buffer_set_state() {
RHICommandBuffer cmd;
RenderState state;
state.blend = BlendMode::Additive;
state.cull = CullMode::CW;
state.depthTest = true;
state.depthWrite = true;
cmd.setState(state);
ASSERT(cmd.size() == 1);
ASSERT(cmd.getCommands()[0].type == CommandType::SetState);
ASSERT(cmd.getCommands()[0].setState.state.blend == BlendMode::Additive);
ASSERT(cmd.getCommands()[0].setState.state.cull == CullMode::CW);
ASSERT(cmd.getCommands()[0].setState.state.depthTest == true);
}
void test_command_buffer_set_texture() {
RHICommandBuffer cmd;
TextureHandle tex;
tex.id = 123;
UniformHandle sampler;
sampler.id = 456;
cmd.setTexture(0, tex, sampler);
ASSERT(cmd.size() == 1);
ASSERT(cmd.getCommands()[0].type == CommandType::SetTexture);
ASSERT(cmd.getCommands()[0].setTexture.slot == 0);
ASSERT(cmd.getCommands()[0].setTexture.texture.id == 123);
ASSERT(cmd.getCommands()[0].setTexture.sampler.id == 456);
}
void test_command_buffer_set_uniform() {
RHICommandBuffer cmd;
UniformHandle uniform;
uniform.id = 42;
float data[4] = {1.0f, 2.0f, 3.0f, 4.0f};
cmd.setUniform(uniform, data, 1);
ASSERT(cmd.size() == 1);
ASSERT(cmd.getCommands()[0].type == CommandType::SetUniform);
ASSERT(cmd.getCommands()[0].setUniform.uniform.id == 42);
ASSERT(cmd.getCommands()[0].setUniform.numVec4s == 1);
ASSERT(cmd.getCommands()[0].setUniform.data[0] == 1.0f);
ASSERT(cmd.getCommands()[0].setUniform.data[3] == 4.0f);
}
void test_command_buffer_set_buffers() {
RHICommandBuffer cmd;
BufferHandle vb, ib, inst;
vb.id = 1;
ib.id = 2;
inst.id = 3;
cmd.setVertexBuffer(vb, 100);
cmd.setIndexBuffer(ib, 200, true);
cmd.setInstanceBuffer(inst, 10, 50);
ASSERT(cmd.size() == 3);
ASSERT(cmd.getCommands()[0].type == CommandType::SetVertexBuffer);
ASSERT(cmd.getCommands()[0].setVertexBuffer.buffer.id == 1);
ASSERT(cmd.getCommands()[0].setVertexBuffer.offset == 100);
ASSERT(cmd.getCommands()[1].type == CommandType::SetIndexBuffer);
ASSERT(cmd.getCommands()[1].setIndexBuffer.buffer.id == 2);
ASSERT(cmd.getCommands()[1].setIndexBuffer.offset == 200);
ASSERT(cmd.getCommands()[1].setIndexBuffer.is32Bit == true);
ASSERT(cmd.getCommands()[2].type == CommandType::SetInstanceBuffer);
ASSERT(cmd.getCommands()[2].setInstanceBuffer.buffer.id == 3);
ASSERT(cmd.getCommands()[2].setInstanceBuffer.start == 10);
ASSERT(cmd.getCommands()[2].setInstanceBuffer.count == 50);
}
void test_command_buffer_draw() {
RHICommandBuffer cmd;
cmd.draw(100, 10);
cmd.drawIndexed(200, 20);
cmd.drawInstanced(300, 30);
ASSERT(cmd.size() == 3);
ASSERT(cmd.getCommands()[0].type == CommandType::Draw);
ASSERT(cmd.getCommands()[0].draw.vertexCount == 100);
ASSERT(cmd.getCommands()[0].draw.startVertex == 10);
ASSERT(cmd.getCommands()[1].type == CommandType::DrawIndexed);
ASSERT(cmd.getCommands()[1].drawIndexed.indexCount == 200);
ASSERT(cmd.getCommands()[1].drawIndexed.startIndex == 20);
ASSERT(cmd.getCommands()[2].type == CommandType::DrawInstanced);
ASSERT(cmd.getCommands()[2].drawInstanced.indexCount == 300);
ASSERT(cmd.getCommands()[2].drawInstanced.instanceCount == 30);
}
void test_command_buffer_submit() {
RHICommandBuffer cmd;
ShaderHandle shader;
shader.id = 999;
cmd.submit(0, shader, 42);
ASSERT(cmd.size() == 1);
ASSERT(cmd.getCommands()[0].type == CommandType::Submit);
ASSERT(cmd.getCommands()[0].submit.view == 0);
ASSERT(cmd.getCommands()[0].submit.shader.id == 999);
ASSERT(cmd.getCommands()[0].submit.depth == 42);
}
void test_command_buffer_clear() {
RHICommandBuffer cmd;
cmd.draw(100);
cmd.draw(200);
ASSERT(cmd.size() == 2);
cmd.clear();
ASSERT(cmd.size() == 0);
}
void test_command_buffer_complex_sequence() {
RHICommandBuffer cmd;
// Typical draw call sequence
RenderState state;
state.blend = BlendMode::Alpha;
cmd.setState(state);
BufferHandle vb, ib;
vb.id = 1;
ib.id = 2;
cmd.setVertexBuffer(vb);
cmd.setIndexBuffer(ib);
TextureHandle tex;
tex.id = 10;
UniformHandle sampler;
sampler.id = 20;
cmd.setTexture(0, tex, sampler);
cmd.drawIndexed(6);
ShaderHandle shader;
shader.id = 100;
cmd.submit(0, shader);
ASSERT(cmd.size() == 6);
}
// ============================================================================
// Frame Allocator Tests
// ============================================================================
void test_frame_allocator_basic() {
FrameAllocator allocator(1024);
ASSERT(allocator.getCapacity() == 1024);
ASSERT(allocator.getUsed() == 0);
}
void test_frame_allocator_allocate() {
FrameAllocator allocator(1024);
void* ptr1 = allocator.allocate(64);
ASSERT(ptr1 != nullptr);
ASSERT(allocator.getUsed() >= 64);
void* ptr2 = allocator.allocate(128);
ASSERT(ptr2 != nullptr);
ASSERT(ptr2 != ptr1);
ASSERT(allocator.getUsed() >= 192);
}
void test_frame_allocator_alignment() {
FrameAllocator allocator(1024);
// Allocate with 16-byte alignment (typical for SIMD)
// Note: new[] in FrameAllocator may not align the base buffer itself,
// so we test relative alignment between consecutive allocations
void* ptr1 = allocator.allocate(1, 16);
void* ptr2 = allocator.allocate(1, 16);
// Both should be 16-byte aligned relative to buffer start
uintptr_t addr1 = reinterpret_cast<uintptr_t>(ptr1);
uintptr_t addr2 = reinterpret_cast<uintptr_t>(ptr2);
// The allocator aligns within its buffer, so difference should be aligned
ASSERT((addr2 - addr1) % 16 == 0 || addr2 % 16 == 0);
// Test that alignment spacing is respected
void* ptr3 = allocator.allocate(4, 8);
void* ptr4 = allocator.allocate(4, 8);
ASSERT(ptr3 != ptr4);
}
void test_frame_allocator_reset() {
FrameAllocator allocator(1024);
allocator.allocate(256);
size_t usedBefore = allocator.getUsed();
ASSERT(usedBefore >= 256);
allocator.reset();
ASSERT(allocator.getUsed() == 0);
}
void test_frame_allocator_typed() {
FrameAllocator allocator(1024);
struct TestStruct {
int a;
float b;
TestStruct() : a(42), b(3.14f) {}
};
TestStruct* ptr = allocator.allocate<TestStruct>();
ASSERT(ptr != nullptr);
ASSERT(ptr->a == 42);
ASSERT(ptr->b == 3.14f);
}
void test_frame_allocator_array() {
FrameAllocator allocator(1024);
SpriteInstance* sprites = allocator.allocateArray<SpriteInstance>(10);
ASSERT(sprites != nullptr);
// Check all are default initialized
for (int i = 0; i < 10; ++i) {
sprites[i].x = static_cast<float>(i);
sprites[i].y = static_cast<float>(i * 2);
}
ASSERT(sprites[5].x == 5.0f);
ASSERT(sprites[5].y == 10.0f);
}
void test_frame_allocator_out_of_memory() {
FrameAllocator allocator(64);
void* ptr = allocator.allocate(128);
ASSERT(ptr == nullptr); // Should fail gracefully
}
// ============================================================================
// Frame Packet Tests
// ============================================================================
void test_frame_packet_struct() {
FramePacket packet;
packet.frameNumber = 100;
packet.deltaTime = 0.016f;
packet.clearColor = 0xFF0000FF;
packet.sprites = nullptr;
packet.spriteCount = 0;
ASSERT(packet.frameNumber == 100);
ASSERT(packet.deltaTime == 0.016f);
ASSERT(packet.clearColor == 0xFF0000FF);
}
void test_view_info_struct() {
ViewInfo view;
view.positionX = 100.0f;
view.positionY = 200.0f;
view.zoom = 2.0f;
view.viewportX = 0;
view.viewportY = 0;
view.viewportW = 1280;
view.viewportH = 720;
ASSERT(view.positionX == 100.0f);
ASSERT(view.zoom == 2.0f);
ASSERT(view.viewportW == 1280);
}
void test_sprite_instance_struct() {
SpriteInstance sprite;
sprite.x = 50.0f;
sprite.y = 100.0f;
sprite.scaleX = 2.0f;
sprite.scaleY = 2.0f;
sprite.rotation = 3.14159f;
sprite.u0 = 0.0f;
sprite.v0 = 0.0f;
sprite.u1 = 1.0f;
sprite.v1 = 1.0f;
sprite.color = 0xFFFFFFFF;
sprite.textureId = 5;
sprite.layer = 10;
ASSERT(sprite.x == 50.0f);
ASSERT(sprite.scaleX == 2.0f);
ASSERT(sprite.textureId == 5);
ASSERT(sprite.layer == 10);
}
// ============================================================================
// Main
// ============================================================================
int main() {
std::cout << "========================================\n";
std::cout << "BgfxRenderer RHI Unit Tests\n";
std::cout << "========================================\n\n";
std::cout << "[RHI Types]\n";
TEST(handle_validity);
TEST(render_state_defaults);
TEST(texture_desc);
TEST(buffer_desc);
std::cout << "\n[Command Buffer]\n";
TEST(command_buffer_empty);
TEST(command_buffer_set_state);
TEST(command_buffer_set_texture);
TEST(command_buffer_set_uniform);
TEST(command_buffer_set_buffers);
TEST(command_buffer_draw);
TEST(command_buffer_submit);
TEST(command_buffer_clear);
TEST(command_buffer_complex_sequence);
std::cout << "\n[Frame Allocator]\n";
TEST(frame_allocator_basic);
TEST(frame_allocator_allocate);
TEST(frame_allocator_alignment);
TEST(frame_allocator_reset);
TEST(frame_allocator_typed);
TEST(frame_allocator_array);
TEST(frame_allocator_out_of_memory);
std::cout << "\n[Frame Packet]\n";
TEST(frame_packet_struct);
TEST(view_info_struct);
TEST(sprite_instance_struct);
std::cout << "\n========================================\n";
std::cout << "Results: " << g_testsPassed << " passed, " << g_testsFailed << " failed\n";
std::cout << "========================================\n";
return g_testsFailed > 0 ? 1 : 0;
}

View File

@ -0,0 +1,332 @@
/**
* Test: BgfxRenderer Visual Triangle Test
*
* Renders a colored triangle using bgfx with SDL2 windowing.
* This validates the full rendering pipeline including shaders.
*/
#include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
#include <bgfx/bgfx.h>
#include <bgfx/platform.h>
#include <bx/math.h>
#include <iostream>
#include <cstdint>
// ============================================================================
// Embedded Shaders (from bgfx examples - drawstress)
// ============================================================================
// Include pre-compiled shader bytecode for all platforms
#include "../../modules/BgfxRenderer/Shaders/vs_color.bin.h"
#include "../../modules/BgfxRenderer/Shaders/fs_color.bin.h"
// ============================================================================
// Shader loading helper
// ============================================================================
static const bgfx::Memory* loadShaderMem(const uint8_t* data, uint32_t size) {
return bgfx::copy(data, size);
}
bgfx::ShaderHandle loadShader(bgfx::RendererType::Enum type, const char* name) {
const uint8_t* data = nullptr;
uint32_t size = 0;
// Select shader based on renderer type
bool isVertex = (name[0] == 'v');
switch (type) {
case bgfx::RendererType::OpenGL:
if (isVertex) {
data = vs_drawstress_glsl;
size = sizeof(vs_drawstress_glsl);
} else {
data = fs_drawstress_glsl;
size = sizeof(fs_drawstress_glsl);
}
break;
case bgfx::RendererType::OpenGLES:
if (isVertex) {
data = vs_drawstress_essl;
size = sizeof(vs_drawstress_essl);
} else {
data = fs_drawstress_essl;
size = sizeof(fs_drawstress_essl);
}
break;
case bgfx::RendererType::Vulkan:
if (isVertex) {
data = vs_drawstress_spv;
size = sizeof(vs_drawstress_spv);
} else {
data = fs_drawstress_spv;
size = sizeof(fs_drawstress_spv);
}
break;
case bgfx::RendererType::Direct3D11:
case bgfx::RendererType::Direct3D12:
if (isVertex) {
data = vs_drawstress_dx11;
size = sizeof(vs_drawstress_dx11);
} else {
data = fs_drawstress_dx11;
size = sizeof(fs_drawstress_dx11);
}
break;
case bgfx::RendererType::Metal:
if (isVertex) {
data = vs_drawstress_mtl;
size = sizeof(vs_drawstress_mtl);
} else {
data = fs_drawstress_mtl;
size = sizeof(fs_drawstress_mtl);
}
break;
default:
std::cerr << "Unsupported renderer type for shaders\n";
return BGFX_INVALID_HANDLE;
}
return bgfx::createShader(loadShaderMem(data, size));
}
// ============================================================================
// Vertex Data
// ============================================================================
struct PosColorVertex {
float x, y, z;
uint32_t abgr;
static bgfx::VertexLayout layout;
static void init() {
layout
.begin()
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
.add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
.end();
}
};
bgfx::VertexLayout PosColorVertex::layout;
// Triangle vertices (colored) - centered at origin
static PosColorVertex s_triangleVertices[] = {
{ -0.5f, -0.5f, 0.0f, 0xff0000ff }, // Red (ABGR format)
{ 0.5f, -0.5f, 0.0f, 0xff00ff00 }, // Green
{ 0.0f, 0.5f, 0.0f, 0xffff0000 }, // Blue
};
static const uint16_t s_triangleIndices[] = {
0, 1, 2,
};
// ============================================================================
// Main
// ============================================================================
int main(int argc, char* argv[]) {
std::cout << "========================================\n";
std::cout << "BgfxRenderer Visual Triangle Test\n";
std::cout << "========================================\n\n";
// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << "SDL_Init failed: " << SDL_GetError() << "\n";
return 1;
}
// Create window
const int width = 800;
const int height = 600;
SDL_Window* window = SDL_CreateWindow(
"BgfxRenderer Triangle Test - Press ESC to exit",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
width, height,
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
);
if (!window) {
std::cerr << "SDL_CreateWindow failed: " << SDL_GetError() << "\n";
SDL_Quit();
return 1;
}
// Get native window handle
SDL_SysWMinfo wmi;
SDL_VERSION(&wmi.version);
if (!SDL_GetWindowWMInfo(window, &wmi)) {
std::cerr << "SDL_GetWindowWMInfo failed: " << SDL_GetError() << "\n";
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// Setup bgfx platform data
bgfx::PlatformData pd;
pd.ndt = wmi.info.x11.display;
pd.nwh = (void*)(uintptr_t)wmi.info.x11.window;
pd.context = nullptr;
pd.backBuffer = nullptr;
pd.backBufferDS = nullptr;
bgfx::setPlatformData(pd);
// Initialize bgfx
bgfx::Init init;
init.type = bgfx::RendererType::Count; // Auto-select
init.resolution.width = width;
init.resolution.height = height;
init.resolution.reset = BGFX_RESET_VSYNC;
init.platformData = pd;
std::cout << "Initializing bgfx...\n";
if (!bgfx::init(init)) {
std::cerr << "bgfx::init failed\n";
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// Print renderer info
const bgfx::Caps* caps = bgfx::getCaps();
std::cout << "Renderer: " << bgfx::getRendererName(caps->rendererType) << "\n";
std::cout << "Resolution: " << width << "x" << height << "\n";
// Setup view
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x303030ff, 1.0f, 0);
bgfx::setViewRect(0, 0, 0, width, height);
// Initialize vertex layout
PosColorVertex::init();
// Create vertex buffer
bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(
bgfx::makeRef(s_triangleVertices, sizeof(s_triangleVertices)),
PosColorVertex::layout
);
// Create index buffer
bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(
bgfx::makeRef(s_triangleIndices, sizeof(s_triangleIndices))
);
// Load shaders
std::cout << "Loading shaders for " << bgfx::getRendererName(caps->rendererType) << "...\n";
bgfx::ShaderHandle vsh = loadShader(caps->rendererType, "vs_color");
bgfx::ShaderHandle fsh = loadShader(caps->rendererType, "fs_color");
if (!bgfx::isValid(vsh) || !bgfx::isValid(fsh)) {
std::cerr << "Failed to load shaders\n";
bgfx::shutdown();
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// Create program
bgfx::ProgramHandle program = bgfx::createProgram(vsh, fsh, true);
if (!bgfx::isValid(program)) {
std::cerr << "Failed to create shader program\n";
bgfx::shutdown();
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
std::cout << "\n*** Rendering colored triangle ***\n";
std::cout << "Press ESC to exit or wait 5 seconds\n\n";
// Main loop
bool running = true;
uint32_t frameCount = 0;
Uint32 startTime = SDL_GetTicks();
const Uint32 testDuration = 5000; // 5 seconds
while (running) {
// Process events
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
running = false;
}
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
running = false;
}
}
// Check timeout
if (SDL_GetTicks() - startTime > testDuration) {
running = false;
}
// Set view transform (identity for 2D)
float view[16];
float proj[16];
bx::mtxIdentity(view);
bx::mtxOrtho(proj, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 0.0f, caps->homogeneousDepth);
bgfx::setViewTransform(0, view, proj);
// Touch view 0 to ensure clear
bgfx::touch(0);
// Set model transform (identity)
float model[16];
bx::mtxIdentity(model);
bgfx::setTransform(model);
// Set vertex and index buffers
bgfx::setVertexBuffer(0, vbh);
bgfx::setIndexBuffer(ibh);
// Set render state
uint64_t state = BGFX_STATE_WRITE_RGB
| BGFX_STATE_WRITE_A
| BGFX_STATE_WRITE_Z
| BGFX_STATE_DEPTH_TEST_LESS
| BGFX_STATE_MSAA;
bgfx::setState(state);
// Submit draw call
bgfx::submit(0, program);
// Submit frame
bgfx::frame();
frameCount++;
}
float elapsed = (SDL_GetTicks() - startTime) / 1000.0f;
float fps = frameCount / elapsed;
std::cout << "Test completed!\n";
std::cout << " Frames: " << frameCount << "\n";
std::cout << " Time: " << elapsed << "s\n";
std::cout << " FPS: " << fps << "\n";
// Cleanup
bgfx::destroy(program);
bgfx::destroy(vbh);
bgfx::destroy(ibh);
bgfx::shutdown();
SDL_DestroyWindow(window);
SDL_Quit();
std::cout << "\n========================================\n";
std::cout << "PASS: Colored triangle rendered!\n";
std::cout << "========================================\n";
return 0;
}