Skip to content

Commit 8e7368a

Browse files
committed
WIP metal tests
1 parent bf47b75 commit 8e7368a

File tree

7 files changed

+60
-18
lines changed

7 files changed

+60
-18
lines changed

Apps/UnitTests/Source/App_Apple.cpp

Lines changed: 0 additions & 10 deletions
This file was deleted.

Apps/UnitTests/Source/App_macOS.mm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "App.h"
2+
#include <Babylon/DebugTrace.h>
3+
#include <Metal/Metal.h>
4+
5+
int main()
6+
{
7+
Babylon::DebugTrace::EnableDebugTrace(true);
8+
Babylon::DebugTrace::SetTraceOutput([](const char* trace) { NSLog(@"%s", trace); });
9+
10+
id<MTLDevice> device = MTLCreateSystemDefaultDevice();
11+
12+
Babylon::Graphics::Configuration config{};
13+
config.Device = device;
14+
config.Width = 600;
15+
config.Height = 400;
16+
17+
return RunTests(config);
18+
}

Apps/UnitTests/Source/Utils_D3D11.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <gtest/gtest.h>
2-
#include <Babylon/Graphics/Device.h>
2+
#include "Utils.h"
33

44
Babylon::Graphics::TextureT CreateTestTexture(Babylon::Graphics::DeviceT device, uint32_t width, uint32_t height)
55
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <gtest/gtest.h>
2+
#include "Utils.h"
3+
#import <Metal/Metal.h>
4+
5+
Babylon::Graphics::TextureT CreateTestTexture(Babylon::Graphics::DeviceT device, uint32_t width, uint32_t height)
6+
{
7+
MTLTextureDescriptor* descriptor = [MTLTextureDescriptor
8+
texture2DDescriptorWithPixelFormat:MTLPixelFormatRGBA8Unorm
9+
width:width
10+
height:height
11+
mipmapped:NO];
12+
13+
id<MTLTexture> texture = [device newTextureWithDescriptor:descriptor];
14+
EXPECT_NE(texture, nil);
15+
16+
return texture;
17+
}
18+
19+
void DestroyTestTexture(Babylon::Graphics::TextureT texture)
20+
{
21+
// ARC will handle the release automatically
22+
(void)texture;
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <gtest/gtest.h>
2+
#include "Utils.h"
3+
4+
Babylon::Graphics::TextureT CreateTestTexture(Babylon::Graphics::DeviceT device, uint32_t width, uint32_t height)
5+
{
6+
throw std::runtime_error{"not implemented"};
7+
}
8+
9+
void DestroyTestTexture(Babylon::Graphics::TextureT texture)
10+
{
11+
throw std::runtime_error{"not implemented"};
12+
}

Core/Graphics/Include/RendererType/Metal/Babylon/Graphics/RendererType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Babylon::Graphics
1616

1717
struct PlatformInfo
1818
{
19-
struct MTLDevice* Device;
20-
struct MTLCommandQueue* CommandQueue;
19+
id<MTLDevice> Device;
20+
id<MTLCommandQueue> CommandQueue;
2121
};
2222
}

Core/Graphics/Source/DeviceImpl_Metal.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ namespace Babylon::Graphics
77

88
PlatformInfo DeviceImpl::GetPlatformInfo() const
99
{
10-
return
11-
{
12-
static_cast<struct MTLDevice*>(bgfx::getInternalData()->context),
13-
static_cast<struct MTLCommandQueue*>(bgfx::getInternalData()->commandQueue)
14-
};
10+
auto internalData = bgfx::getInternalData();
11+
id<MTLDevice> device = (id<MTLDevice>)internalData->context;
12+
id<MTLCommandQueue> commandQueue = (id<MTLCommandQueue>)internalData->commandQueue;
13+
return {std::move(device), std::move(commandQueue)};
1514
}
1615
}

0 commit comments

Comments
 (0)