Removed bgfx::setPlatformData usage from entry example harness.

This commit is contained in:
Бранимир Караџић 2022-08-25 20:07:03 -07:00
parent 85910e9778
commit 72cbe83275
65 changed files with 2503 additions and 2589 deletions

View File

@ -32,6 +32,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -147,6 +147,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -506,6 +506,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -119,6 +119,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -30,6 +30,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -82,6 +82,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -102,6 +102,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -329,6 +329,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -245,6 +245,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -157,6 +157,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -71,6 +71,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -54,6 +54,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -46,6 +46,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -812,6 +812,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_viewState.m_width;
init.resolution.height = m_viewState.m_height;
init.resolution.reset = m_reset;

View File

@ -1784,6 +1784,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_viewState.m_width;
init.resolution.height = m_viewState.m_height;
init.resolution.reset = m_reset;

View File

@ -78,6 +78,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -1157,6 +1157,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_viewState.m_width;
init.resolution.height = m_viewState.m_height;
init.resolution.reset = m_reset;

View File

@ -129,6 +129,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -418,6 +418,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -169,6 +169,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -1402,6 +1402,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -211,6 +211,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -86,6 +86,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -53,6 +53,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -130,6 +130,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -7,6 +7,8 @@
#include "../00-helloworld/logo.h"
extern bool entry_process_events(uint32_t* _width, uint32_t* _height, uint32_t* _debug, uint32_t* _reset);
extern void* entry_get_default_native_window_handle();
extern void* entry_get_native_display_handle();
uint16_t uint16_max(uint16_t _a, uint16_t _b)
{
@ -25,6 +27,9 @@ int32_t _main_(int32_t _argc, char** _argv)
bgfx_init_t init;
bgfx_init_ctor(&init);
init.platformData.nwh = entry_get_default_native_window_handle();
init.platformData.ndt = entry_get_native_display_handle();
bgfx_init(&init);
bgfx_reset(width, height, reset, init.resolution.format);

View File

@ -82,6 +82,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -78,6 +78,8 @@ ExampleTerrain(const char* _name, const char* _description, const char* _url)
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -291,6 +291,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -778,6 +778,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -38,6 +38,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -211,6 +211,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -246,6 +246,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -128,6 +128,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -124,6 +124,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -102,6 +102,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

File diff suppressed because it is too large Load Diff

View File

@ -328,6 +328,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -196,9 +196,10 @@ public:
m_reset = BGFX_RESET_VSYNC;
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -267,12 +267,13 @@ namespace
m_reset = BGFX_RESET_VSYNC;
bgfx::Init init;
init.type = args.m_type;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.resolution.width = m_width;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;
init.resolution.reset = m_reset;
bgfx::init(init);
// Enable debug text.

View File

@ -78,12 +78,13 @@ public:
m_reset = BGFX_RESET_VSYNC;
bgfx::Init init;
init.type = args.m_type;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.resolution.width = m_width;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;
init.resolution.reset = m_reset;
bgfx::init(init);
// Enable m_debug text.

File diff suppressed because it is too large Load Diff

View File

@ -262,6 +262,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -249,9 +249,10 @@ public:
m_reset = BGFX_RESET_VSYNC;
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;

View File

@ -261,12 +261,13 @@ public:
m_reset = BGFX_RESET_VSYNC;
bgfx::Init init;
init.type = args.m_type;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.resolution.width = m_width;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;
init.resolution.reset = m_reset;
bgfx::init(init);
// Enable debug text.
@ -276,10 +277,10 @@ public:
m_uniforms.init();
// Create texture sampler uniforms (used when we bind textures)
s_albedo = bgfx::createUniform("s_albedo", bgfx::UniformType::Sampler); // Model's source albedo
s_color = bgfx::createUniform("s_color", bgfx::UniformType::Sampler); // Color (albedo) gbuffer, default color input
s_normal = bgfx::createUniform("s_normal", bgfx::UniformType::Sampler); // Normal gbuffer, Model's source normal
s_depth = bgfx::createUniform("s_depth", bgfx::UniformType::Sampler); // Depth gbuffer
s_albedo = bgfx::createUniform("s_albedo", bgfx::UniformType::Sampler); // Model's source albedo
s_color = bgfx::createUniform("s_color", bgfx::UniformType::Sampler); // Color (albedo) gbuffer, default color input
s_normal = bgfx::createUniform("s_normal", bgfx::UniformType::Sampler); // Normal gbuffer, Model's source normal
s_depth = bgfx::createUniform("s_depth", bgfx::UniformType::Sampler); // Depth gbuffer
s_shadows = bgfx::createUniform("s_shadows", bgfx::UniformType::Sampler);
// Create program from shaders.
@ -382,7 +383,8 @@ public:
if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState))
{
// skip processing when minimized, otherwise crashing
if (0 == m_width || 0 == m_height)
if (0 == m_width
|| 0 == m_height)
{
return true;
}

View File

@ -243,12 +243,13 @@ public:
m_reset = BGFX_RESET_VSYNC;
bgfx::Init init;
init.type = args.m_type;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.resolution.width = m_width;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;
init.resolution.reset = m_reset;
bgfx::init(init);
// Enable debug text.

File diff suppressed because it is too large Load Diff

View File

@ -19,12 +19,12 @@ namespace stl = tinystl;
namespace
{
constexpr int32_t kCheckerboardSize = 128;
constexpr int32_t kCheckerboardSize = 128;
constexpr int32_t kFirstUncompressedFormatIndex = bgfx::TextureFormat::Unknown + 1;
constexpr int32_t kNumCompressedFormats = bgfx::TextureFormat::Unknown;
constexpr int32_t kNumUncompressedFormats = bgfx::TextureFormat::UnknownDepth - kFirstUncompressedFormatIndex;
constexpr int32_t kNumFormats = kNumCompressedFormats + kNumUncompressedFormats;
const int32_t kNumFormatsInRow = (int32_t)bx::ceil(1.2f * bx::sqrt(kNumFormats) );
constexpr int32_t kNumCompressedFormats = bgfx::TextureFormat::Unknown;
constexpr int32_t kNumUncompressedFormats = bgfx::TextureFormat::UnknownDepth - kFirstUncompressedFormatIndex;
constexpr int32_t kNumFormats = kNumCompressedFormats + kNumUncompressedFormats;
const int32_t kNumFormatsInRow = (int32_t)bx::ceil(1.2f * bx::sqrt(kNumFormats) );
inline int32_t formatToIndex(bimg::TextureFormat::Enum format)
{
@ -428,6 +428,8 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;
@ -574,7 +576,10 @@ public:
if (bgfx::isValid(m_checkerboard) )
{
static int64_t timeOffset = bx::getHPCounter();
const float time = m_animateCheckerboard ? float( (bx::getHPCounter()-timeOffset)/double(bx::getHPFrequency() ) ) : 0.0f;
const float time = m_animate
? float( (bx::getHPCounter()-timeOffset)/double(bx::getHPFrequency() ) )
: 0.0f
;
const float xx = bx::sin(time * 0.17f);
const float yy = bx::cos(time * 0.13f);
const float uTile = bx::max(1.0f, previewSize.x / kCheckerboardSize);
@ -655,7 +660,7 @@ public:
ImGui::SameLine();
ImGui::Checkbox("Alpha", &m_useAlpha);
ImGui::SameLine();
ImGui::Checkbox("Animate Checkerboard", &m_animateCheckerboard);
ImGui::Checkbox("Animate", &m_animate);
ImGui::BeginTable("Formats", kNumFormatsInRow, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit);
for (int32_t i = m_currentTextureSet->m_hasCompressedTextures ? 0 : kNumCompressedFormats; i < kNumFormats; ++i)
@ -797,7 +802,7 @@ public:
float m_largestTextureSize = 256.0f;
float m_previewSize = 50.0f;
bool m_useAlpha = true;
bool m_animateCheckerboard = true;
bool m_animate = true;
bimg::TextureFormat::Enum m_selectedFormat = bimg::TextureFormat::RGBA8;
bgfx::TextureHandle m_checkerboard = BGFX_INVALID_HANDLE;

View File

@ -443,12 +443,27 @@ BX_PRAGMA_DIAGNOSTIC_POP();
return bx::kExitFailure;
}
struct AppInternal
{
AppI* m_next;
const char* m_name;
const char* m_description;
const char* m_url;
};
static ptrdiff_t s_offset = 0;
AppI::AppI(const char* _name, const char* _description, const char* _url)
{
m_name = _name;
m_description = _description;
m_url = _url;
m_next = s_apps;
BX_STATIC_ASSERT(sizeof(AppInternal) <= sizeof(m_internal) );
s_offset = BX_OFFSETOF(AppI, m_internal);
AppInternal* ai = (AppInternal*)m_internal;
ai->m_name = _name;
ai->m_description = _description;
ai->m_url = _url;
ai->m_next = s_apps;
s_apps = this;
s_numApps++;
@ -464,7 +479,8 @@ BX_PRAGMA_DIAGNOSTIC_POP();
{
if (NULL != prev)
{
prev->m_next = next;
AppInternal* ai = bx::addressOf<AppInternal>(prev, s_offset);
ai->m_next = next;
}
else
{
@ -480,22 +496,26 @@ BX_PRAGMA_DIAGNOSTIC_POP();
const char* AppI::getName() const
{
return m_name;
AppInternal* ai = (AppInternal*)m_internal;
return ai->m_name;
}
const char* AppI::getDescription() const
{
return m_description;
AppInternal* ai = (AppInternal*)m_internal;
return ai->m_description;
}
const char* AppI::getUrl() const
{
return m_url;
AppInternal* ai = (AppInternal*)m_internal;
return ai->m_url;
}
AppI* AppI::getNext()
{
return m_next;
AppInternal* ai = (AppInternal*)m_internal;
return ai->m_next;
}
AppI* getFirstApp()
@ -513,8 +533,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
_app->init(_argc, _argv, s_width, s_height);
bgfx::frame();
WindowHandle defaultWindow = { 0 };
setWindowSize(defaultWindow, s_width, s_height);
setWindowSize(kDefaultWindowHandle, s_width, s_height);
#if BX_PLATFORM_EMSCRIPTEN
s_app = _app;
@ -560,9 +579,15 @@ BX_PRAGMA_DIAGNOSTIC_POP();
for (ii = 1; ii < s_numApps; ++ii)
{
AppI* app = apps[ii-1];
app->m_next = apps[ii];
AppInternal* ai = bx::addressOf<AppInternal>(app, s_offset);
ai->m_next = apps[ii];
}
{
AppInternal* ai = bx::addressOf<AppInternal>(apps[s_numApps-1], s_offset);
ai->m_next = NULL;
}
apps[s_numApps-1]->m_next = NULL;
BX_FREE(g_allocator, apps);
}
@ -583,14 +608,12 @@ BX_PRAGMA_DIAGNOSTIC_POP();
inputInit();
inputAddBindings("bindings", s_bindings);
entry::WindowHandle defaultWindow = { 0 };
bx::FilePath fp(_argv[0]);
char title[bx::kMaxFilePath];
bx::strCopy(title, BX_COUNTOF(title), fp.getBaseName() );
entry::setWindowTitle(defaultWindow, title);
setWindowSize(defaultWindow, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
entry::setWindowTitle(kDefaultWindowHandle, title);
setWindowSize(kDefaultWindowHandle, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
sortApps();
@ -1004,3 +1027,13 @@ extern "C" bool entry_process_events(uint32_t* _width, uint32_t* _height, uint32
{
return entry::processEvents(*_width, *_height, *_debug, *_reset, NULL);
}
extern "C" void* entry_get_default_native_window_handle()
{
return entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
}
extern "C" void* entry_get_native_display_handle()
{
return entry::getNativeDisplayHandle();
}

View File

@ -35,14 +35,20 @@ extern "C" int _main_(int _argc, char** _argv);
_app s_ ## _app ## App(__VA_ARGS__)
#endif // ENTRY_CONFIG_IMPLEMENT_MAIN
///
#define ENTRY_HANDLE(_name) \
struct _name { uint16_t idx; }; \
inline bool isValid(_name _handle) { return UINT16_MAX != _handle.idx; }
namespace entry
{
struct WindowHandle { uint16_t idx; };
inline bool isValid(WindowHandle _handle) { return UINT16_MAX != _handle.idx; }
ENTRY_HANDLE(WindowHandle);
ENTRY_HANDLE(GamepadHandle);
struct GamepadHandle { uint16_t idx; };
inline bool isValid(GamepadHandle _handle) { return UINT16_MAX != _handle.idx; }
///
constexpr WindowHandle kDefaultWindowHandle = { 0 };
///
struct MouseButton
{
enum Enum
@ -56,6 +62,7 @@ namespace entry
};
};
///
struct GamepadAxis
{
enum Enum
@ -71,6 +78,7 @@ namespace entry
};
};
///
struct Modifier
{
enum Enum
@ -87,6 +95,7 @@ namespace entry
};
};
///
struct Key
{
enum Enum
@ -198,6 +207,7 @@ namespace entry
};
};
///
struct Suspend
{
enum Enum
@ -211,8 +221,10 @@ namespace entry
};
};
///
const char* getName(Key::Enum _key);
///
struct MouseState
{
MouseState()
@ -232,6 +244,7 @@ namespace entry
uint8_t m_buttons[entry::MouseButton::Count];
};
///
struct GamepadState
{
GamepadState()
@ -242,22 +255,52 @@ namespace entry
int32_t m_axis[entry::GamepadAxis::Count];
};
///
bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse = NULL);
///
bx::FileReaderI* getFileReader();
///
bx::FileWriterI* getFileWriter();
///
bx::AllocatorI* getAllocator();
///
WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags = ENTRY_WINDOW_FLAG_NONE, const char* _title = "");
///
void destroyWindow(WindowHandle _handle);
///
void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y);
///
void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height);
///
void setWindowTitle(WindowHandle _handle, const char* _title);
///
void setWindowFlags(WindowHandle _handle, uint32_t _flags, bool _enabled);
///
void toggleFullscreen(WindowHandle _handle);
///
void setMouseLock(WindowHandle _handle, bool _lock);
///
void* getNativeWindowHandle(WindowHandle _handle);
///
void* getNativeDisplayHandle();
///
void setCurrentDir(const char* _dir);
///
struct WindowState
{
WindowState()
@ -276,8 +319,10 @@ namespace entry
bx::FilePath m_dropFile;
};
///
bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset);
///
class BX_NO_VTABLE AppI
{
public:
@ -308,12 +353,8 @@ namespace entry
///
AppI* getNext();
AppI* m_next;
private:
const char* m_name;
const char* m_description;
const char* m_url;
BX_ALIGN_DECL(16, uintptr_t) m_internal[4];
};
///

View File

@ -7,8 +7,6 @@
#if ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_ANDROID
#include <bgfx/platform.h>
#include <bx/thread.h>
#include <bx/file.h>
@ -29,18 +27,6 @@ extern "C"
namespace entry
{
///
inline void androidSetWindow(::ANativeWindow* _window)
{
bgfx::PlatformData pd;
pd.ndt = NULL;
pd.nwh = _window;
pd.context = NULL;
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
bgfx::setPlatformData(pd);
}
struct GamepadRemap
{
uint16_t m_keyCode;
@ -233,7 +219,6 @@ namespace entry
if (m_window != m_app->window)
{
m_window = m_app->window;
androidSetWindow(m_window);
int32_t width = ANativeWindow_getWidth(m_window);
int32_t height = ANativeWindow_getHeight(m_window);
@ -550,6 +535,21 @@ namespace entry
BX_UNUSED(_handle, _lock);
}
void* getNativeWindowHandle(WindowHandle _handle)
{
if (kDefaultWindowHandle.idx == _handle.idx)
{
return s_ctx.m_window;
}
return NULL;
}
void* getNativeDisplayHandle()
{
return NULL;
}
int32_t MainThreadEntry::threadFunc(bx::Thread* _thread, void* _userData)
{
BX_UNUSED(_thread);

View File

@ -85,27 +85,6 @@ namespace entry
glfwDestroyWindow(_window);
}
static void glfwSetWindow(GLFWwindow* _window)
{
bgfx::PlatformData pd;
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
# if ENTRY_CONFIG_USE_WAYLAND
pd.ndt = glfwGetWaylandDisplay();
# else
pd.ndt = glfwGetX11Display();
#endif
# elif BX_PLATFORM_OSX
pd.ndt = NULL;
# elif BX_PLATFORM_WINDOWS
pd.ndt = NULL;
# endif // BX_PLATFORM_WINDOWS
pd.nwh = glfwNativeWindowHandle(_window);
pd.context = NULL;
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
bgfx::setPlatformData(pd);
}
static uint8_t translateKeyModifiers(int _glfw)
{
uint8_t modifiers = 0;
@ -453,29 +432,28 @@ namespace entry
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
WindowHandle handle = { m_windowAlloc.alloc() };
m_windows[0] = glfwCreateWindow(ENTRY_DEFAULT_WIDTH
m_window[0] = glfwCreateWindow(ENTRY_DEFAULT_WIDTH
, ENTRY_DEFAULT_HEIGHT
, "bgfx"
, NULL
, NULL
);
if (!m_windows[0])
if (!m_window[0])
{
DBG("glfwCreateWindow failed!");
glfwTerminate();
return bx::kExitFailure;
}
glfwSetKeyCallback(m_windows[0], keyCb);
glfwSetCharCallback(m_windows[0], charCb);
glfwSetScrollCallback(m_windows[0], scrollCb);
glfwSetCursorPosCallback(m_windows[0], cursorPosCb);
glfwSetMouseButtonCallback(m_windows[0], mouseButtonCb);
glfwSetWindowSizeCallback(m_windows[0], windowSizeCb);
glfwSetDropCallback(m_windows[0], dropFileCb);
glfwSetKeyCallback(m_window[0], keyCb);
glfwSetCharCallback(m_window[0], charCb);
glfwSetScrollCallback(m_window[0], scrollCb);
glfwSetCursorPosCallback(m_window[0], cursorPosCb);
glfwSetMouseButtonCallback(m_window[0], mouseButtonCb);
glfwSetWindowSizeCallback(m_window[0], windowSizeCb);
glfwSetDropCallback(m_window[0], dropFileCb);
glfwSetWindow(m_windows[0]);
m_eventQueue.postSizeEvent(handle, ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT);
for (uint32_t ii = 0; ii < ENTRY_CONFIG_MAX_GAMEPADS; ++ii)
@ -492,8 +470,8 @@ namespace entry
m_thread.init(MainThreadEntry::threadFunc, &m_mte);
while (NULL != m_windows[0]
&& !glfwWindowShouldClose(m_windows[0]))
while (NULL != m_window[0]
&& !glfwWindowShouldClose(m_window[0]))
{
glfwWaitEventsTimeout(0.016);
@ -535,7 +513,7 @@ namespace entry
glfwSetWindowSizeCallback(window, windowSizeCb);
glfwSetDropCallback(window, dropFileCb);
m_windows[msg->m_handle.idx] = window;
m_window[msg->m_handle.idx] = window;
m_eventQueue.postSizeEvent(msg->m_handle, msg->m_width, msg->m_height);
m_eventQueue.postWindowEvent(msg->m_handle, glfwNativeWindowHandle(window));
}
@ -545,31 +523,31 @@ namespace entry
{
if (isValid(msg->m_handle) )
{
GLFWwindow* window = m_windows[msg->m_handle.idx];
GLFWwindow* window = m_window[msg->m_handle.idx];
m_eventQueue.postWindowEvent(msg->m_handle);
glfwDestroyWindowImpl(window);
m_windows[msg->m_handle.idx] = NULL;
m_window[msg->m_handle.idx] = NULL;
}
}
break;
case GLFW_WINDOW_SET_TITLE:
{
GLFWwindow* window = m_windows[msg->m_handle.idx];
GLFWwindow* window = m_window[msg->m_handle.idx];
glfwSetWindowTitle(window, msg->m_title.c_str());
}
break;
case GLFW_WINDOW_SET_POS:
{
GLFWwindow* window = m_windows[msg->m_handle.idx];
GLFWwindow* window = m_window[msg->m_handle.idx];
glfwSetWindowPos(window, msg->m_x, msg->m_y);
}
break;
case GLFW_WINDOW_SET_SIZE:
{
GLFWwindow* window = m_windows[msg->m_handle.idx];
GLFWwindow* window = m_window[msg->m_handle.idx];
glfwSetWindowSize(window, msg->m_width, msg->m_height);
}
break;
@ -582,7 +560,7 @@ namespace entry
case GLFW_WINDOW_TOGGLE_FULL_SCREEN:
{
GLFWwindow* window = m_windows[msg->m_handle.idx];
GLFWwindow* window = m_window[msg->m_handle.idx];
if (glfwGetWindowMonitor(window) )
{
glfwSetWindowMonitor(window
@ -619,7 +597,7 @@ namespace entry
case GLFW_WINDOW_MOUSE_LOCK:
{
GLFWwindow* window = m_windows[msg->m_handle.idx];
GLFWwindow* window = m_window[msg->m_handle.idx];
if (msg->m_value)
{
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
@ -639,7 +617,7 @@ namespace entry
m_eventQueue.postExitEvent();
m_thread.shutdown();
glfwDestroyWindowImpl(m_windows[0]);
glfwDestroyWindowImpl(m_window[0]);
glfwTerminate();
return m_thread.getExitCode();
@ -651,7 +629,7 @@ namespace entry
for (uint32_t ii = 0, num = m_windowAlloc.getNumHandles(); ii < num; ++ii)
{
uint16_t idx = m_windowAlloc.getHandleAt(ii);
if (_window == m_windows[idx])
if (_window == m_window[idx])
{
WindowHandle handle = { idx };
return handle;
@ -676,7 +654,7 @@ namespace entry
EventQueue m_eventQueue;
bx::Mutex m_lock;
GLFWwindow* m_windows[ENTRY_CONFIG_MAX_WINDOWS];
GLFWwindow* m_window[ENTRY_CONFIG_MAX_WINDOWS];
bx::HandleAllocT<ENTRY_CONFIG_MAX_WINDOWS> m_windowAlloc;
GamepadGLFW m_gamepad[ENTRY_CONFIG_MAX_GAMEPADS];
@ -879,6 +857,24 @@ namespace entry
s_ctx.m_msgs.push(msg);
}
void* getNativeWindowHandle(WindowHandle _handle)
{
return glfwNativeWindowHandle(s_ctx.m_window[_handle.idx]);
}
void* getNativeDisplayHandle()
{
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
# if ENTRY_CONFIG_USE_WAYLAND
return glfwGetWaylandDisplay();
# else
return glfwGetX11Display();
# endif // ENTRY_CONFIG_USE_WAYLAND
# else
return NULL;
# endif // BX_PLATFORM_*
}
int32_t MainThreadEntry::threadFunc(bx::Thread* _thread, void* _userData)
{
BX_UNUSED(_thread);

View File

@ -28,8 +28,6 @@ extern "C" void entry_emscripten_yield()
namespace entry
{
static WindowHandle s_defaultWindow = { 0 };
static uint8_t s_translateKey[256];
struct Context
@ -126,11 +124,6 @@ namespace entry
EMSCRIPTEN_CHECK(emscripten_set_focusin_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, this, true, focusCb) );
EMSCRIPTEN_CHECK(emscripten_set_focusout_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, this, true, focusCb) );
bgfx::PlatformData pd;
bx::memSet(&pd, 0, sizeof(pd) );
pd.nwh = (void*)canvas;
bgfx::setPlatformData(pd);
int32_t result = main(_argc, _argv);
return result;
}
@ -163,7 +156,7 @@ namespace entry
case EMSCRIPTEN_EVENT_MOUSEMOVE:
s_ctx.m_mx = _event->targetX;
s_ctx.m_my = _event->targetY;
s_ctx.m_eventQueue.postMouseEvent(s_defaultWindow, s_ctx.m_mx, s_ctx.m_my, s_ctx.m_scroll);
s_ctx.m_eventQueue.postMouseEvent(kDefaultWindowHandle, s_ctx.m_mx, s_ctx.m_my, s_ctx.m_scroll);
return true;
case EMSCRIPTEN_EVENT_MOUSEDOWN:
@ -176,7 +169,7 @@ namespace entry
? MouseButton::Middle : MouseButton::Left)
;
s_ctx.m_eventQueue.postMouseEvent(
s_defaultWindow
kDefaultWindowHandle
, s_ctx.m_mx
, s_ctx.m_my
, s_ctx.m_scroll
@ -203,7 +196,7 @@ namespace entry
s_ctx.m_scrollf += _event->deltaY;
s_ctx.m_scroll = (int32_t)s_ctx.m_scrollf;
s_ctx.m_eventQueue.postMouseEvent(s_defaultWindow, s_ctx.m_mx, s_ctx.m_my, s_ctx.m_scroll);
s_ctx.m_eventQueue.postMouseEvent(kDefaultWindowHandle, s_ctx.m_mx, s_ctx.m_my, s_ctx.m_scroll);
return true;
}
}
@ -303,14 +296,14 @@ namespace entry
else
{
enum { ShiftMask = Modifier::LeftShift|Modifier::RightShift };
s_ctx.m_eventQueue.postCharEvent(s_defaultWindow, 1, pressedChar);
s_ctx.m_eventQueue.postKeyEvent(s_defaultWindow, key, modifiers, true);
s_ctx.m_eventQueue.postCharEvent(kDefaultWindowHandle, 1, pressedChar);
s_ctx.m_eventQueue.postKeyEvent(kDefaultWindowHandle, key, modifiers, true);
return true;
}
break;
case EMSCRIPTEN_EVENT_KEYUP:
s_ctx.m_eventQueue.postKeyEvent(s_defaultWindow, key, modifiers, false);
s_ctx.m_eventQueue.postKeyEvent(kDefaultWindowHandle, key, modifiers, false);
return true;
}
}
@ -340,19 +333,19 @@ namespace entry
switch (_eventType)
{
case EMSCRIPTEN_EVENT_BLUR:
s_ctx.m_eventQueue.postSuspendEvent(s_defaultWindow, Suspend::DidSuspend);
s_ctx.m_eventQueue.postSuspendEvent(kDefaultWindowHandle, Suspend::DidSuspend);
return true;
case EMSCRIPTEN_EVENT_FOCUS:
s_ctx.m_eventQueue.postSuspendEvent(s_defaultWindow, Suspend::DidResume);
s_ctx.m_eventQueue.postSuspendEvent(kDefaultWindowHandle, Suspend::DidResume);
return true;
case EMSCRIPTEN_EVENT_FOCUSIN:
s_ctx.m_eventQueue.postSuspendEvent(s_defaultWindow, Suspend::WillResume);
s_ctx.m_eventQueue.postSuspendEvent(kDefaultWindowHandle, Suspend::WillResume);
return true;
case EMSCRIPTEN_EVENT_FOCUSOUT:
s_ctx.m_eventQueue.postSuspendEvent(s_defaultWindow, Suspend::WillSuspend);
s_ctx.m_eventQueue.postSuspendEvent(kDefaultWindowHandle, Suspend::WillSuspend);
return true;
}
}
@ -419,6 +412,21 @@ namespace entry
{
BX_UNUSED(_handle, _lock);
}
void* getNativeWindowHandle(WindowHandle _handle)
{
if (kDefaultWindowHandle.idx == _handle.idx)
{
return (void*)"#canvas";
}
return NULL;
}
void* getNativeDisplayHandle()
{
return NULL;
}
}
int main(int _argc, const char* const* _argv)

View File

@ -57,6 +57,7 @@ namespace entry
MainThreadEntry m_mte;
bx::Thread m_thread;
void* m_window;
EventQueue m_eventQueue;
};
@ -145,16 +146,25 @@ namespace entry
BX_UNUSED(_handle, _lock);
}
void* getNativeWindowHandle(WindowHandle _handle)
{
if (kDefaultWindowHandle.idx == _handle.idx)
{
return s_ctx.m_window;
}
return NULL;
}
void* getNativeDisplayHandle()
{
return NULL;
}
} // namespace entry
using namespace entry;
#ifdef HAS_METAL_SDK
static id<MTLDevice> m_device = NULL;
#else
static void* m_device = NULL;
#endif
@interface ViewController : UIViewController
@end
@implementation ViewController
@ -177,13 +187,14 @@ static void* m_device = NULL;
+ (Class)layerClass
{
#ifdef HAS_METAL_SDK
static id<MTLDevice> device = NULL;
Class metalClass = NSClassFromString(@"CAMetalLayer"); //is metal runtime sdk available
if ( metalClass != nil)
{
m_device = MTLCreateSystemDefaultDevice(); // is metal supported on this device (is there a better way to do this - without creating device ?)
if (m_device)
device = MTLCreateSystemDefaultDevice(); // is metal supported on this device (is there a better way to do this - without creating device ?)
if (NULL != device)
{
[m_device retain];
[device retain];
return metalClass;
}
}
@ -201,13 +212,7 @@ static void* m_device = NULL;
return nil;
}
bgfx::PlatformData pd;
pd.ndt = NULL;
pd.nwh = self.layer;
pd.context = m_device;
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
bgfx::setPlatformData(pd);
s_ctx->m_window = self.layer;
return self;
}
@ -226,7 +231,7 @@ static void* m_device = NULL;
m_displayLink = [self.window.screen displayLinkWithTarget:self selector:@selector(renderFrame)];
//[m_displayLink setFrameInterval:1];
//[m_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
// [m_displayLink addToRunLoop:[NSRunLoop currentRunLoop]];
//[m_displayLink addToRunLoop:[NSRunLoop currentRunLoop]];
[m_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}
}

View File

@ -67,6 +67,17 @@ namespace entry
BX_UNUSED(_handle, _lock);
}
void* getNativeWindowHandle(WindowHandle _handle)
{
BX_UNUSED(_handle);
return NULL;
}
void* getNativeDisplayHandle()
{
return NULL;
}
} // namespace entry
int main(int _argc, const char* const* _argv)

View File

@ -45,18 +45,6 @@
namespace entry
{
///
inline void osxSetNSWindow(void* _window, void* _nsgl = NULL)
{
bgfx::PlatformData pd;
pd.ndt = NULL;
pd.nwh = _window;
pd.context = _nsgl;
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
bgfx::setPlatformData(pd);
}
static uint8_t s_translateKey[256];
struct MainThreadEntry
@ -507,8 +495,6 @@ namespace entry
m_windowFrame = [m_window[0] frame];
osxSetNSWindow(m_window[0]);
MainThreadEntry mte;
mte.m_argc = _argc;
mte.m_argv = _argv;
@ -729,6 +715,16 @@ namespace entry
});
}
void* getNativeWindowHandle(WindowHandle _handle)
{
return s_ctx.m_window[_handle.idx];
}
void* getNativeDisplayHandle()
{
return NULL;
}
} // namespace entry
@implementation AppDelegate

View File

@ -74,35 +74,6 @@ namespace entry
# endif // BX_PLATFORM_
}
inline bool sdlSetWindow(SDL_Window* _window)
{
SDL_SysWMinfo wmi;
SDL_VERSION(&wmi.version);
if (!SDL_GetWindowWMInfo(_window, &wmi) )
{
return false;
}
bgfx::PlatformData pd;
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
# if ENTRY_CONFIG_USE_WAYLAND
pd.ndt = wmi.info.wl.display;
# else
pd.ndt = wmi.info.x11.display;
# endif
# else
pd.ndt = NULL;
# endif // BX_PLATFORM_
pd.nwh = sdlNativeWindowHandle(_window);
pd.context = NULL;
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
bgfx::setPlatformData(pd);
return true;
}
static void sdlDestroyWindow(SDL_Window* _window)
{
if(!_window)
@ -513,7 +484,6 @@ namespace entry
s_userEventStart = SDL_RegisterEvents(7);
sdlSetWindow(m_window[0]);
bgfx::renderFrame();
m_thread.init(MainThreadEntry::threadFunc, &m_mte);
@ -1162,6 +1132,31 @@ namespace entry
sdlPostEvent(SDL_USER_WINDOW_MOUSE_LOCK, _handle, NULL, _lock);
}
void* getNativeWindowHandle(WindowHandle _handle)
{
return sdlNativeWindowHandle(s_ctx.m_window[_handle.idx]);
}
void* getNativeDisplayHandle()
{
SDL_SysWMinfo wmi;
SDL_VERSION(&wmi.version);
if (!SDL_GetWindowWMInfo(s_ctx.m_window[0], &wmi) )
{
return NULL;
}
# if BX_PLATFORM_LINUX || BX_PLATFORM_BSD
# if ENTRY_CONFIG_USE_WAYLAND
return wmi.info.wl.display;
# else
return wmi.info.x11.display;
# endif // ENTRY_CONFIG_USE_WAYLAND
# else
return NULL;
# endif // BX_PLATFORM_*
}
int32_t MainThreadEntry::threadFunc(bx::Thread* _thread, void* _userData)
{
BX_UNUSED(_thread);

View File

@ -45,15 +45,6 @@ namespace entry
return utf16;
}
///
inline void winSetHwnd(::HWND _window)
{
bgfx::PlatformData pd;
bx::memSet(&pd, 0, sizeof(pd) );
pd.nwh = _window;
bgfx::setPlatformData(pd);
}
typedef DWORD (WINAPI* PFN_XINPUT_GET_STATE)(DWORD dwUserIndex, XINPUT_STATE* pState);
typedef void (WINAPI* PFN_XINPUT_ENABLE)(BOOL enable); // 1.4+
@ -502,8 +493,6 @@ namespace entry
| ENTRY_WINDOW_FLAG_FRAME
;
winSetHwnd(m_hwnd[0]);
adjust(m_hwnd[0], ENTRY_DEFAULT_WIDTH, ENTRY_DEFAULT_HEIGHT, true);
clear(m_hwnd[0]);
@ -1170,6 +1159,16 @@ namespace entry
PostMessage(s_ctx.m_hwnd[0], WM_USER_WINDOW_MOUSE_LOCK, _handle.idx, _lock);
}
void* getNativeWindowHandle(WindowHandle _handle)
{
return s_ctx.m_hwnd[_handle.idx];
}
void* getNativeDisplayHandle()
{
return NULL;
}
int32_t MainThreadEntry::threadFunc(bx::Thread* /*_thread*/, void* _userData)
{
MainThreadEntry* self = (MainThreadEntry*)_userData;

View File

@ -1,237 +0,0 @@
/*
* Copyright 2011-2016 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
#include "entry_p.h"
#if BX_PLATFORM_WINRT || BX_PLATFORM_XBOXONE
#include <bgfx/platform.h>
#include <bx/thread.h>
#include <bx/math.h>
#include <Unknwn.h>
#include <cmath>
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Core;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::UI::Core;
using namespace Windows::UI::Input;
using namespace Windows::System;
using namespace Windows::Foundation;
#if BX_PLATFORM_WINRT
using namespace Windows::Graphics::Display;
#endif // BX_PLATFORM_WINRT
using namespace Platform;
static const char* const g_emptyArgs[] = { "app.exe", "", "" };
static entry::WindowHandle g_defaultWindow = { 0 };
static entry::EventQueue g_eventQueue;
///
inline void winrtSetWindow(::IUnknown* _window)
{
bgfx::PlatformData pd;
pd.ndt = NULL;
pd.nwh = _window;
pd.context = NULL;
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
bgfx::setPlatformData(pd);
}
ref class App sealed : public IFrameworkView
{
public:
App()
: m_windowVisible(true)
, m_windowClosed(false)
{
}
// IFrameworkView Methods.
virtual void Initialize(CoreApplicationView^ applicationView)
{
applicationView->Activated += ref new
TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &App::OnActivated);
CoreApplication::Suspending += ref new
EventHandler<SuspendingEventArgs^>(this, &App::OnSuspending);
CoreApplication::Resuming += ref new
EventHandler<Platform::Object^>(this, &App::OnResuming);
}
virtual void SetWindow(CoreWindow^ window)
{
window->VisibilityChanged += ref new
TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &App::OnVisibilityChanged);
window->Closed += ref new
TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &App::OnWindowClosed);
winrtSetWindow(reinterpret_cast<IUnknown*>(window) );
}
virtual void Load(String^ entryPoint)
{
}
virtual void Run()
{
bgfx::renderFrame();
bx::Thread thread;
thread.init(MainThreadFunc, nullptr);
CoreWindow^ window = CoreWindow::GetForCurrentThread();
auto bounds = window->Bounds;
#if BX_PLATFORM_WINRT
auto dpi = DisplayInformation::GetForCurrentView()->LogicalDpi;
static const float dipsPerInch = 96.0f;
g_eventQueue.postSizeEvent(g_defaultWindow
, std::lround(bx::floor(bounds.Width * dpi / dipsPerInch + 0.5f) )
, std::lround(bx::floor(bounds.Height * dpi / dipsPerInch + 0.5f) )
);
#endif // BX_PLATFORM_WINRT
while (!m_windowClosed)
{
if (m_windowVisible)
{
window->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent);
}
else
{
window->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessOneAndAllPending);
}
bgfx::renderFrame();
}
g_eventQueue.postExitEvent();
while (bgfx::RenderFrame::NoContext != bgfx::renderFrame() ) {};
thread.shutdown();
}
virtual void Uninitialize()
{
}
private:
bool m_windowVisible;
bool m_windowClosed;
void OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args)
{
CoreWindow::GetForCurrentThread()->Activate();
}
void OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args)
{
m_windowVisible = args->Visible;
}
void OnSuspending(Platform::Object^ sender, SuspendingEventArgs^ args)
{
SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();
BX_UNUSED(deferral);
}
void OnResuming(Platform::Object^ sender, Platform::Object^ args)
{
}
void OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args)
{
m_windowClosed = true;
}
static int32_t MainThreadFunc(bx::Thread*, void*)
{
return entry::main(BX_COUNTOF(g_emptyArgs), g_emptyArgs);
}
};
ref class AppSource sealed : IFrameworkViewSource
{
public:
virtual IFrameworkView^ CreateView()
{
return ref new App();
}
};
namespace entry
{
const Event* poll()
{
return g_eventQueue.poll();
}
const Event* poll(WindowHandle _handle)
{
return g_eventQueue.poll(_handle);
}
void release(const Event* _event)
{
g_eventQueue.release(_event);
}
WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags, const char* _title)
{
BX_UNUSED(_x, _y, _width, _height, _flags, _title);
WindowHandle handle = { UINT16_MAX };
return handle;
}
void destroyWindow(WindowHandle _handle)
{
BX_UNUSED(_handle);
}
void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y)
{
BX_UNUSED(_handle, _x, _y);
}
void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
{
BX_UNUSED(_handle, _width, _height);
}
void setWindowTitle(WindowHandle _handle, const char* _title)
{
BX_UNUSED(_handle, _title);
}
void setWindowFlags(WindowHandle _handle, uint32_t _flags, bool _enabled)
{
BX_UNUSED(_handle, _flags, _enabled);
}
void toggleFullscreen(WindowHandle _handle)
{
BX_UNUSED(_handle);
}
void setMouseLock(WindowHandle _handle, bool _lock)
{
BX_UNUSED(_handle, _lock);
}
}
[MTAThread]
int main(Array<String^>^)
{
auto appSource = ref new AppSource();
CoreApplication::Run(appSource);
return 0;
}
#endif // BX_PLATFORM_WINRT || BX_PLATFORM_XBOXONE

View File

@ -12,8 +12,6 @@
#include <X11/keysymdef.h>
#include <X11/Xlib.h> // will include X11 which #defines None... Don't mess with order of includes.
#include <X11/Xutil.h>
#include <bgfx/platform.h>
#include <unistd.h> // syscall
#undef None
@ -31,18 +29,6 @@ namespace entry
static const char* s_applicationName = "BGFX";
static const char* s_applicationClass = "bgfx";
///
inline void x11SetDisplayWindow(void* _display, uint32_t _window, void* _glx = NULL)
{
bgfx::PlatformData pd;
pd.ndt = _display;
pd.nwh = (void*)(uintptr_t)_window;
pd.context = _glx;
pd.backBuffer = NULL;
pd.backBufferDS = NULL;
bgfx::setPlatformData(pd);
}
#define JS_EVENT_BUTTON 0x01 /* button pressed/released */
#define JS_EVENT_AXIS 0x02 /* joystick moved */
#define JS_EVENT_INIT 0x80 /* initial state of device */
@ -355,29 +341,29 @@ namespace entry
bx::memSet(&m_windowAttrs, 0, sizeof(m_windowAttrs) );
m_windowAttrs.background_pixel = 0;
m_windowAttrs.border_pixel = 0;
m_windowAttrs.border_pixel = 0;
m_windowAttrs.bit_gravity = StaticGravity;
m_windowAttrs.event_mask = 0
| ButtonPressMask
| ButtonReleaseMask
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
| StructureNotifyMask
;
m_windowAttrs.event_mask = 0
| ButtonPressMask
| ButtonReleaseMask
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| PointerMotionMask
| StructureNotifyMask
;
m_windowAlloc.alloc();
m_window[0] = XCreateWindow(m_display
, m_root
, 0, 0
, 1, 1, 0
, m_depth
, InputOutput
, m_visual
, CWBorderPixel|CWEventMask|CWBackPixel|CWBitGravity
, &m_windowAttrs
);
m_window[0] = XCreateWindow(
m_display
, m_root
, 0, 0, 1, 1, 0
, m_depth
, InputOutput
, m_visual
, CWBorderPixel|CWEventMask|CWBackPixel|CWBitGravity
, &m_windowAttrs
);
const char* wmDeleteWindowName = "WM_DELETE_WINDOW";
Atom wmDeleteWindow;
@ -397,18 +383,16 @@ namespace entry
im = XOpenIM(m_display, NULL, NULL, NULL);
XIC ic;
ic = XCreateIC(im
, XNInputStyle
, 0
| XIMPreeditNothing
| XIMStatusNothing
, XNClientWindow
, m_window[0]
, NULL
);
//
x11SetDisplayWindow(m_display, m_window[0]);
ic = XCreateIC(
im
, XNInputStyle
, 0
| XIMPreeditNothing
| XIMStatusNothing
, XNClientWindow
, m_window[0]
, NULL
);
MainThreadEntry mte;
mte.m_argc = _argc;
@ -585,19 +569,20 @@ namespace entry
void createWindow(WindowHandle _handle, Msg* msg)
{
Window window = XCreateWindow(m_display
, m_root
, msg->m_x
, msg->m_y
, msg->m_width
, msg->m_height
, 0
, m_depth
, InputOutput
, m_visual
, CWBorderPixel|CWEventMask|CWBackPixel|CWBitGravity
, &m_windowAttrs
);
Window window = XCreateWindow(
m_display
, m_root
, msg->m_x
, msg->m_y
, msg->m_width
, msg->m_height
, 0
, m_depth
, InputOutput
, m_visual
, CWBorderPixel|CWEventMask|CWBackPixel|CWBitGravity
, &m_windowAttrs
);
m_window[_handle.idx] = window;
const char* wmDeleteWindowName = "WM_DELETE_WINDOW";
@ -767,6 +752,16 @@ namespace entry
BX_UNUSED(_handle, _lock);
}
void* getNativeWindowHandle(WindowHandle _handle)
{
return (void*)(uintptr_t)s_ctx.m_window[_handle.idx];
}
void* getNativeDisplayHandle()
{
return s_ctx.m_display;
}
} // namespace entry
int main(int _argc, const char* const* _argv)

View File

@ -375,8 +375,8 @@ void inputSetMouseLock(bool _lock)
if (s_input->m_mouse.m_lock != _lock)
{
s_input->m_mouse.m_lock = _lock;
entry::WindowHandle defaultWindow = { 0 };
entry::setMouseLock(defaultWindow, _lock);
entry::setMouseLock(entry::kDefaultWindowHandle, _lock);
if (_lock)
{
s_input->m_mouse.m_norm[0] = 0.0f;

View File

@ -1878,21 +1878,7 @@ namespace bgfx
m_init.resolution.maxFrameLatency = bx::min<uint8_t>(_init.resolution.maxFrameLatency, BGFX_CONFIG_MAX_FRAME_LATENCY);
dump(m_init.resolution);
if (g_platformData.ndt == NULL
&& g_platformData.nwh == NULL
&& g_platformData.context == NULL
&& g_platformData.backBuffer == NULL
&& g_platformData.backBufferDS == NULL)
{
bx::memCopy(&g_platformData, &m_init.platformData, sizeof(PlatformData) );
}
else
{
bx::memCopy(&m_init.platformData, &g_platformData, sizeof(PlatformData) );
}
if (true
&& !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_PS4)
&& RendererType::Noop != m_init.type
&& NULL == m_init.platformData.ndt
&& NULL == m_init.platformData.nwh
@ -1904,6 +1890,8 @@ namespace bgfx
BX_TRACE("bgfx platform data like window handle or backbuffer is not set, creating headless device.");
}
bx::memCopy(&g_platformData, &m_init.platformData, sizeof(PlatformData) );
m_exit = false;
m_flipped = true;
m_frames = 0;

View File

@ -2384,7 +2384,7 @@ namespace bgfx { namespace gl
if (NULL != extensions)
{
bx::StringView ext(extensions);
uint32_t index = 0;
while (!ext.isEmpty() )
{
const bx::StringView space = bx::strFind(ext, ' ');
@ -2392,8 +2392,6 @@ namespace bgfx { namespace gl
updateExtension(token);
ext.set(space.getPtr() + (space.isEmpty() ? 0 : 1), ext.getTerm() );
++index;
}
}
else if (NULL != glGetStringi)
@ -5880,22 +5878,11 @@ namespace bgfx { namespace gl
if (s_renderGL->m_textureSwizzleSupport
&& (-1 != mapping[0] || -1 != mapping[1] || -1 != mapping[2] || -1 != mapping[3]) )
{
if (-1 == mapping[0])
{
mapping[0] = GL_RED;
}
if (-1 == mapping[1])
{
mapping[1] = GL_GREEN;
}
if (-1 == mapping[2])
{
mapping[2] = GL_BLUE;
}
if (-1 == mapping[3])
{
mapping[3] = GL_ALPHA;
}
mapping[0] = -1 == mapping[0] ? GL_RED : mapping[0];
mapping[1] = -1 == mapping[1] ? GL_GREEN : mapping[1];
mapping[2] = -1 == mapping[2] ? GL_BLUE : mapping[2];
mapping[3] = -1 == mapping[3] ? GL_ALPHA : mapping[3];
GL_CHECK(glTexParameteriv(m_target, GL_TEXTURE_SWIZZLE_RGBA, mapping));
}

View File

@ -715,10 +715,12 @@ int _main_(int _argc, char** _argv)
View view;
cmdAdd("view", cmdView, &view);
entry::setWindowFlags(entry::WindowHandle{0}, ENTRY_WINDOW_FLAG_ASPECT_RATIO, false);
entry::setWindowSize(entry::WindowHandle{0}, view.m_width, view.m_height);
entry::setWindowFlags(entry::kDefaultWindowHandle, ENTRY_WINDOW_FLAG_ASPECT_RATIO, false);
entry::setWindowSize(entry::kDefaultWindowHandle, view.m_width, view.m_height);
bgfx::Init init;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = view.m_width;
init.resolution.width = view.m_height;
init.resolution.reset = 0
@ -1248,8 +1250,7 @@ int _main_(int _argc, char** _argv)
bx::stringPrintf(title, "Failed to load %s!", filePath);
}
entry::WindowHandle handle = { 0 };
entry::setWindowTitle(handle, title.c_str() );
entry::setWindowTitle(entry::kDefaultWindowHandle, title.c_str() );
}
int64_t now = bx::getHPCounter();

View File

@ -1311,11 +1311,13 @@ int _main_(int _argc, char** _argv)
View view;
cmdAdd("view", cmdView, &view);
entry::setWindowFlags(entry::WindowHandle{0}, ENTRY_WINDOW_FLAG_ASPECT_RATIO, false);
entry::setWindowSize(entry::WindowHandle{0}, view.m_width, view.m_height);
entry::setWindowFlags(entry::kDefaultWindowHandle, ENTRY_WINDOW_FLAG_ASPECT_RATIO, false);
entry::setWindowSize(entry::kDefaultWindowHandle, view.m_width, view.m_height);
bgfx::Init init;
init.type = view.m_rendererType;
init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
init.platformData.ndt = entry::getNativeDisplayHandle();
init.resolution.width = view.m_width;
init.resolution.height = view.m_height;
init.resolution.reset = BGFX_RESET_VSYNC;
@ -2064,8 +2066,7 @@ int _main_(int _argc, char** _argv)
bx::stringPrintf(title, "Failed to load %s!", filePath);
}
entry::WindowHandle handle = { 0 };
entry::setWindowTitle(handle, title.c_str() );
entry::setWindowTitle(entry::kDefaultWindowHandle, title.c_str() );
}
int64_t now = bx::getHPCounter();