Skip to content

Commit

Permalink
Formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcourteaux committed Oct 5, 2024
1 parent 9a077da commit 5700556
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 49 deletions.
10 changes: 7 additions & 3 deletions examples/42-bunnylod/bunnylod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ class ExampleBunnyLOD : public entry::AppI
static void remapIndices(uint32_t* _indices, uint32_t _num)
{
uint32_t target = 0;
for (uint32_t i = 0; i < _num; i++) {
for (uint32_t i = 0; i < _num; i++)
{
uint32_t map = _indices[i];
if (i != map) {
if (i != map)
{
_indices[i] = _indices[map];
} else {
}
else
{
_indices[i] = target;
++target;
}
Expand Down
9 changes: 6 additions & 3 deletions examples/common/entry/entry_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ namespace entry
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND)
{
return glfwGetWaylandWindow(_window);
} else
}
else
{
return (void*)(uintptr_t)glfwGetX11Window(_window);
}
Expand Down Expand Up @@ -838,7 +839,8 @@ namespace entry
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND)
{
return glfwGetWaylandDisplay();
} else
}
else
{
return glfwGetX11Display();
}
Expand All @@ -853,7 +855,8 @@ namespace entry
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND)
{
return bgfx::NativeWindowHandleType::Wayland;
} else
}
else
{
return bgfx::NativeWindowHandleType::Default;
}
Expand Down
4 changes: 4 additions & 0 deletions examples/common/entry/entry_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ namespace entry

# if BX_PLATFORM_LINUX
if (wmi.subsystem == SDL_SYSWM_WAYLAND)
{
return (void*)wmi.info.wl.surface;
}
else
{
return (void*)wmi.info.x11.window;
}
# elif BX_PLATFORM_OSX || BX_PLATFORM_IOS || BX_PLATFORM_VISIONOS
return wmi.info.cocoa.window;
# elif BX_PLATFORM_WINDOWS
Expand Down
8 changes: 6 additions & 2 deletions examples/common/entry/entry_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,14 +851,18 @@ namespace entry

if (utf16[0] >= 0xD800 && utf16[0] <= 0xDBFF) {
m_surrogate = utf16[0];
} else {
}
else
{
int utf16_len;
if (utf16[0] >= 0xDC00 && utf16[0] <= 0xDFFF) {
utf16[1] = utf16[0];
utf16[0] = m_surrogate;
m_surrogate = 0;
utf16_len = 2;
} else {
}
else
{
utf16_len = 1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/renderer_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3399,10 +3399,10 @@ namespace bgfx { namespace d3d11
{
case UniformType::Mat3:
case UniformType::Mat3|kUniformFragmentBit:
{
{
float* value = (float*)data;
for (uint32_t ii = 0, count = num/3; ii < count; ++ii, loc += 3*16, value += 9)
{
{
Matrix4 mtx;
mtx.un.val[ 0] = value[0];
mtx.un.val[ 1] = value[1];
Expand Down
7 changes: 5 additions & 2 deletions src/renderer_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3060,7 +3060,8 @@ namespace bgfx { namespace gl
}

#if BGFX_CONFIG_RENDERER_OPENGLES && (BGFX_CONFIG_RENDERER_OPENGLES < 30)
if (!m_maxMsaa && s_extension[Extension::IMG_multisampled_render_to_texture].m_supported) {
if (!m_maxMsaa && s_extension[Extension::IMG_multisampled_render_to_texture].m_supported)
{
GL_CHECK(glGetIntegerv(GL_MAX_SAMPLES_IMG, &m_maxMsaa) );
}
#endif // BGFX_CONFIG_RENDERER_OPENGLES < 30
Expand Down Expand Up @@ -7121,7 +7122,9 @@ namespace bgfx { namespace gl
{
attachment = GL_DEPTH_ATTACHMENT;
}
} else {
}
else
{
attachment = GL_COLOR_ATTACHMENT0 + colorIdx;
++colorIdx;
}
Expand Down
80 changes: 46 additions & 34 deletions src/renderer_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ bool init(const Init& _init)
, TextureFormat::Unknown
, TextureFormat::UnknownDepth
);

#if BX_PLATFORM_VISIONOS
if (m_mainFrameBuffer.m_swapChain->m_useLayerRenderer)
{
Expand Down Expand Up @@ -923,7 +923,7 @@ void shutdown()
MTL_RELEASE(m_vertexDescriptor);
MTL_RELEASE(m_textureDescriptor);
MTL_RELEASE(m_samplerDescriptor);

#if BX_PLATFORM_VISIONOS
if (m_mainFrameBuffer.m_swapChain->m_useLayerRenderer)
{
Expand Down Expand Up @@ -1077,7 +1077,7 @@ MTLPixelFormat getSwapChainPixelFormat(SwapChainMtl *swapChain)
return cp_layer_renderer_configuration_get_color_format(layerConfiguration);
}
#endif // BX_PLATFORM_VISIONOS

return swapChain->m_metalLayer.pixelFormat;
}

Expand Down Expand Up @@ -1328,18 +1328,21 @@ void blitSetup(TextVideoMemBlitter& _blitter) override
{
BX_UNUSED(_blitter);
}

#if BX_PLATFORM_VISIONOS
void calculateViewPorts(MTLViewport (&viewports)[2]) {
void calculateViewPorts(MTLViewport (&viewports)[2])
{
const int viewCount = 2;
for (int i = 0; i < viewCount; i++) {
for (int i = 0; i < viewCount; i++)
{
cp_view_t view = cp_drawable_get_view(m_mainFrameBuffer.m_swapChain->m_layerRendererDrawable, i);
cp_view_texture_map_t texture_map = cp_view_get_view_texture_map(view);
viewports[i] = cp_view_texture_map_get_viewport(texture_map);
}
}

void setVertexAmplification(RenderCommandEncoder& _rce) {
void setVertexAmplification(RenderCommandEncoder& _rce)
{
MTLVertexAmplificationViewMapping mapping0;
MTLVertexAmplificationViewMapping mapping1;

Expand Down Expand Up @@ -1399,7 +1402,8 @@ void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) override
#if BX_PLATFORM_VISIONOS
if (m_mainFrameBuffer.m_swapChain->m_useLayerRenderer)
{
if (cp_layer_renderer_configuration_get_layout(m_mainFrameBuffer.m_swapChain->m_layerRendererConfiguration) == cp_layer_renderer_layout_layered) {
if (cp_layer_renderer_configuration_get_layout(m_mainFrameBuffer.m_swapChain->m_layerRendererConfiguration) == cp_layer_renderer_layout_layered)
{
MTLViewport viewports[2];
calculateViewPorts(viewports);
rce.setViewports(viewports, 2);
Expand All @@ -1411,7 +1415,7 @@ void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) override
{
MTLViewport viewport = { 0.0f, 0.0f, (float)width, (float)height, 0.0f, 1.0f };
rce.setViewport(viewport);

MTLScissorRect rc = { 0, 0, width, height };
rce.setScissorRect(rc);
}
Expand Down Expand Up @@ -1499,7 +1503,7 @@ void createPoseForTiming(cp_frame_timing_t timing, ar_world_tracking_provider_t
}
}
#endif // BX_PLATFORM_VISIONOS

void flip() override
{
if (NULL == m_commandBuffer)
Expand Down Expand Up @@ -1983,7 +1987,7 @@ void setFrameBuffer(RenderPassDescriptor _renderPassDescriptor, FrameBufferHandl
Texture texture = cp_drawable_get_depth_texture(swapChain->m_layerRendererDrawable, 0);
_renderPassDescriptor.depthAttachment.texture = texture;
_renderPassDescriptor.stencilAttachment.texture = swapChain->m_backBufferStencil;

cp_layer_renderer_configuration_t layerConfiguration = cp_layer_renderer_get_configuration(swapChain->m_layerRenderer);
cp_layer_renderer_layout layout = cp_layer_renderer_configuration_get_layout(layerConfiguration);
if (layout == cp_layer_renderer_layout_layered)
Expand Down Expand Up @@ -2530,7 +2534,8 @@ void processArguments(
}
}

if (streamUsed) {
if (streamUsed)
{
vertexDesc.layouts[stream+1].stride = layout.getStride();
vertexDesc.layouts[stream+1].stepFunction = MTLVertexStepFunctionPerVertex;
}
Expand Down Expand Up @@ -2574,9 +2579,12 @@ void processArguments(
BX_PRAGMA_DIAGNOSTIC_PUSH();
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunguarded-availability-new");
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wincompatible-pointer-types");
if (m_usesMTLBindings) {
if (m_usesMTLBindings)
{
processArguments(pso, reflection.vertexBindings, reflection.fragmentBindings);
} else {
}
else
{
processArguments(pso, reflection.vertexArguments, reflection.fragmentArguments);
}
BX_PRAGMA_DIAGNOSTIC_POP();
Expand Down Expand Up @@ -2630,9 +2638,12 @@ void processArguments(
BX_PRAGMA_DIAGNOSTIC_PUSH();
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunguarded-availability-new");
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wincompatible-pointer-types");
if (m_usesMTLBindings) {
if (m_usesMTLBindings)
{
processArguments(pso, reflection.bindings, NULL);
} else {
}
else
{
processArguments(pso, reflection.arguments, NULL);
}
BX_PRAGMA_DIAGNOSTIC_POP();
Expand Down Expand Up @@ -3486,11 +3497,12 @@ void writeString(bx::WriterI* _writer, const char* _str)
cp_layer_renderer_t layerRenderer = (cp_layer_renderer_t)_nwh;
m_layerRenderer = layerRenderer;
m_layerRendererConfiguration = cp_layer_renderer_get_configuration(m_layerRenderer);

if (cp_layer_renderer_configuration_get_layout(m_layerRendererConfiguration) == cp_layer_renderer_layout_dedicated) {

if (cp_layer_renderer_configuration_get_layout(m_layerRendererConfiguration) == cp_layer_renderer_layout_dedicated)
{
BX_WARN(false, "Dedicated layer renderer layout is not supported.");
}

retain(m_layerRendererConfiguration);
retain(m_layerRenderer);
}
Expand All @@ -3501,20 +3513,20 @@ void writeString(bx::WriterI* _writer, const char* _str)
{
release(m_metalLayer);
}

#if !BX_PLATFORM_VISIONOS
if (NULL != NSClassFromString(@"MTKView") )
{
MTKView *view = (MTKView *)_nwh;

if (NULL != view
&& [view isKindOfClass:NSClassFromString(@"MTKView")])
{
m_metalLayer = (CAMetalLayer *)view.layer;
}
}
#endif

if (NULL != NSClassFromString(@"CAMetalLayer") )
{
if (NULL == m_metalLayer)
Expand All @@ -3527,7 +3539,7 @@ void writeString(bx::WriterI* _writer, const char* _str)
BX_WARN(false, "Unable to create Metal device. Please set platform data window to a CAMetalLayer");
return;
}

m_metalLayer = metalLayer;
}
# elif BX_PLATFORM_OSX
Expand All @@ -3541,7 +3553,7 @@ void writeString(bx::WriterI* _writer, const char* _str)
else
{
NSView *contentView;

if ([nvh isKindOfClass:[NSView class]])
{
contentView = (NSView*)nvh;
Expand All @@ -3556,7 +3568,7 @@ void writeString(bx::WriterI* _writer, const char* _str)
BX_WARN(0, "Unable to create Metal device. Please set platform data window to an NSWindow, NSView, or CAMetalLayer");
return;
}

void (^setLayer)(void) = ^{
CALayer* layer = contentView.layer;
if(NULL != layer && [layer isKindOfClass:NSClassFromString(@"CAMetalLayer")])
Expand All @@ -3570,7 +3582,7 @@ void writeString(bx::WriterI* _writer, const char* _str)
[contentView setLayer:m_metalLayer];
}
};

if ([NSThread isMainThread])
{
setLayer();
Expand All @@ -3579,7 +3591,7 @@ void writeString(bx::WriterI* _writer, const char* _str)
{
bx::Semaphore semaphore;
bx::Semaphore* psemaphore = &semaphore;

CFRunLoopPerformBlock([[NSRunLoop mainRunLoop] getCFRunLoop],
kCFRunLoopCommonModes,
^{
Expand All @@ -3592,13 +3604,13 @@ void writeString(bx::WriterI* _writer, const char* _str)
}
# endif // BX_PLATFORM_*
}

if (NULL == m_metalLayer)
{
BX_WARN(NULL != s_renderMtl->m_device, "Unable to create Metal device.");
return;
}

m_metalLayer.device = s_renderMtl->m_device;
m_metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
m_metalLayer.magnificationFilter = kCAFilterNearest;
Expand Down Expand Up @@ -3750,11 +3762,11 @@ void writeString(bx::WriterI* _writer, const char* _str)
{
cp_frame_timing_t timing = cp_frame_predict_timing(m_frame);
if (timing == nullptr) { return nullptr; }

cp_frame_start_update(m_frame);

cp_frame_end_update(m_frame);

cp_time_wait_until(cp_frame_timing_get_optimal_input_time(timing));
cp_frame_start_submission(m_frame);
m_layerRendererDrawable = cp_frame_query_drawable(m_frame);
Expand Down Expand Up @@ -4616,7 +4628,7 @@ static void setTimestamp(void* _data)
vp.znear = 0.0f;
vp.zfar = 1.0f;
rce.setViewport(vp);

MTLScissorRect sciRect = {
viewState.m_rect.m_x,
viewState.m_rect.m_y,
Expand All @@ -4625,7 +4637,7 @@ static void setTimestamp(void* _data)
};
rce.setScissorRect(sciRect);
}

if (BGFX_CLEAR_NONE != (clr.m_flags & BGFX_CLEAR_MASK)
&& !clearWithRenderPass)
{
Expand Down
Loading

0 comments on commit 5700556

Please sign in to comment.