Basic metal backend
This commit is contained in:
@@ -48,12 +48,6 @@ int main()
|
||||
#endif
|
||||
GraphicsInitializer initializer;
|
||||
graphics->init(initializer);
|
||||
graphics->createVertexShader(ShaderCreateInfo {
|
||||
.entryPoint = "fragmentMain",
|
||||
.mainModule = "TextPass",
|
||||
.additionalModules = {"TextPass"},
|
||||
.name = "Test",
|
||||
});
|
||||
StaticMeshVertexData* vd = StaticMeshVertexData::getInstance();
|
||||
vd->init(graphics);
|
||||
OWindowManager windowManager = new WindowManager();
|
||||
|
||||
@@ -24,7 +24,7 @@ DescriptorLayout& DescriptorLayout::operator=(const DescriptorLayout& other) {
|
||||
|
||||
DescriptorLayout::~DescriptorLayout() {}
|
||||
|
||||
void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorType type, uint32 arrayCount,
|
||||
void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorType type, SeImageViewType textureType, uint32 arrayCount,
|
||||
SeDescriptorBindingFlags bindingFlags, SeShaderStageFlags shaderStages) {
|
||||
if (descriptorBindings.size() <= bindingIndex) {
|
||||
descriptorBindings.resize(bindingIndex + 1);
|
||||
@@ -32,6 +32,7 @@ void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorTyp
|
||||
descriptorBindings[bindingIndex] = DescriptorBinding{
|
||||
.binding = bindingIndex,
|
||||
.descriptorType = type,
|
||||
.textureType = textureType,
|
||||
.descriptorCount = arrayCount,
|
||||
.bindingFlags = bindingFlags,
|
||||
.shaderStages = shaderStages,
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Gfx {
|
||||
struct DescriptorBinding {
|
||||
uint32 binding = 0;
|
||||
SeDescriptorType descriptorType = SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
||||
SeImageViewType textureType;
|
||||
uint32 descriptorCount = 0x7fff;
|
||||
SeDescriptorBindingFlags bindingFlags = 0;
|
||||
SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL;
|
||||
@@ -22,7 +23,8 @@ public:
|
||||
DescriptorLayout(const DescriptorLayout& other);
|
||||
DescriptorLayout& operator=(const DescriptorLayout& other);
|
||||
virtual ~DescriptorLayout();
|
||||
void addDescriptorBinding(uint32 binding, SeDescriptorType type, uint32 arrayCount = 1,
|
||||
void addDescriptorBinding(uint32 binding, SeDescriptorType type,
|
||||
SeImageViewType textureType = Gfx::SE_IMAGE_VIEW_TYPE_2D, uint32 arrayCount = 1,
|
||||
SeDescriptorBindingFlags bindingFlags = 0,
|
||||
SeShaderStageFlags shaderStages = SeShaderStageFlagBits::SE_SHADER_STAGE_ALL);
|
||||
void reset();
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
|
||||
protected:
|
||||
PGraphics graphics;
|
||||
uint32 currentBuffer;
|
||||
uint32 currentBuffer = 0;
|
||||
uint64 size;
|
||||
MTL::Buffer *buffers[Gfx::numFramesBuffered];
|
||||
uint32 numBuffers;
|
||||
|
||||
@@ -94,6 +94,7 @@ private:
|
||||
PGraphics graphics;
|
||||
MTL::CommandQueue* queue;
|
||||
OCommand activeCommand;
|
||||
Array<OCommand> pendingCommands;
|
||||
};
|
||||
class IOCommandQueue
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Enums.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Metal/MTLCommandBuffer.hpp"
|
||||
#include "Pipeline.h"
|
||||
#include "Resources.h"
|
||||
#include "Window.h"
|
||||
@@ -135,7 +136,9 @@ void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
|
||||
}
|
||||
|
||||
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
|
||||
encoder->setBuffer(set.cast<DescriptorSet>()->getBuffer(), 0, set->getSetIndex());
|
||||
auto metalSet = set.cast<DescriptorSet>();
|
||||
metalSet->bind();
|
||||
encoder->setBuffer(metalSet->getBuffer(), 0, set->getSetIndex());
|
||||
}
|
||||
|
||||
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) {
|
||||
@@ -144,8 +147,8 @@ void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) {
|
||||
}
|
||||
}
|
||||
|
||||
void ComputeCommand::pushConstants(Gfx::PPipelineLayout, Gfx::SeShaderStageFlags, uint32 offset,
|
||||
uint32 size, const void* data) {
|
||||
void ComputeCommand::pushConstants(Gfx::PPipelineLayout, Gfx::SeShaderStageFlags, uint32 offset, uint32 size,
|
||||
const void* data) {
|
||||
encoder->setBytes((char*)data + offset, size, 0);
|
||||
}
|
||||
|
||||
@@ -170,8 +173,19 @@ OComputeCommand CommandQueue::getComputeCommand(const std::string& name) {
|
||||
}
|
||||
|
||||
void CommandQueue::submitCommands(PEvent signalSemaphore) {
|
||||
activeCommand->getHandle()->addCompletedHandler(MTL::CommandBufferHandler([&](MTL::CommandBuffer* cmdBuffer) {
|
||||
for(auto it = pendingCommands.begin(); it != pendingCommands.end(); it++)
|
||||
{
|
||||
if((*it)->getHandle() == cmdBuffer)
|
||||
{
|
||||
pendingCommands.remove(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}));
|
||||
activeCommand->end(signalSemaphore);
|
||||
PEvent prevCmdEvent = activeCommand->getCompletedEvent();
|
||||
pendingCommands.add(std::move(activeCommand));
|
||||
activeCommand = new Command(graphics, queue->commandBuffer());
|
||||
activeCommand->waitForEvent(prevCmdEvent);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
#include "Descriptor.h"
|
||||
#include "Buffer.h"
|
||||
#include "Enums.h"
|
||||
#include "Graphics/Descriptor.h"
|
||||
#include "Graphics/Initializer.h"
|
||||
#include "Metal/MTLArgument.hpp"
|
||||
#include "Metal/MTLDevice.hpp"
|
||||
#include "Metal/MTLResource.hpp"
|
||||
#include "Metal/MTLTexture.hpp"
|
||||
#include "Texture.h"
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Metal;
|
||||
|
||||
DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string& name)
|
||||
: Gfx::DescriptorLayout(name), graphics(graphics) {}
|
||||
: Gfx::DescriptorLayout(name), graphics(graphics), arguments(nullptr) {}
|
||||
|
||||
DescriptorLayout::~DescriptorLayout() {}
|
||||
|
||||
void DescriptorLayout::create() {
|
||||
if (arguments != nullptr) {
|
||||
return;
|
||||
}
|
||||
Array<NS::Object*> descriptors;
|
||||
for (size_t i = 0; i < descriptorBindings.size(); ++i) {
|
||||
const auto& binding = descriptorBindings[i];
|
||||
@@ -35,7 +45,7 @@ void DescriptorLayout::create() {
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT:
|
||||
dataType = MTL::DataTypeStruct;
|
||||
dataType = MTL::DataTypePointer;
|
||||
break;
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV:
|
||||
dataType = MTL::DataTypePrimitiveAccelerationStructure;
|
||||
@@ -44,10 +54,38 @@ void DescriptorLayout::create() {
|
||||
throw std::logic_error("Nooo");
|
||||
}
|
||||
desc->setDataType(dataType);
|
||||
desc->setIndex(i);
|
||||
if (dataType == MTL::DataTypeTexture) {
|
||||
switch (binding.textureType) {
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_1D:
|
||||
desc->setTextureType(MTL::TextureType1D);
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_2D:
|
||||
desc->setTextureType(MTL::TextureType2D);
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_3D:
|
||||
desc->setTextureType(MTL::TextureType3D);
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_CUBE:
|
||||
desc->setTextureType(MTL::TextureTypeCube);
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_1D_ARRAY:
|
||||
desc->setTextureType(MTL::TextureType1DArray);
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY:
|
||||
desc->setTextureType(MTL::TextureType2DArray);
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_CUBE_ARRAY:
|
||||
desc->setTextureType(MTL::TextureTypeCubeArray);
|
||||
break;
|
||||
}
|
||||
}
|
||||
descriptors.add(desc);
|
||||
}
|
||||
arguments = NS::Array::array(descriptors.data(), descriptors.size());
|
||||
pool = new DescriptorPool(graphics, this);
|
||||
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(),
|
||||
CRC::CRC_32());
|
||||
}
|
||||
|
||||
DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {}
|
||||
@@ -66,6 +104,7 @@ Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
|
||||
return PDescriptorSet(allocatedSets[setIndex]);
|
||||
}
|
||||
allocatedSets.add(new DescriptorSet(graphics, this));
|
||||
allocatedSets.back()->allocate();
|
||||
return PDescriptorSet(allocatedSets.back());
|
||||
}
|
||||
|
||||
@@ -77,10 +116,17 @@ void DescriptorPool::reset() {
|
||||
|
||||
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
|
||||
: Gfx::DescriptorSet(owner->getLayout()), graphics(graphics), owner(owner), bindCount(0), currentlyInUse(false) {
|
||||
// auto desc = (MTL::ArgumentDescriptor*)owner->getArguments()->object(0);
|
||||
// std::cout << desc->access() << " " << desc->arrayLength() << " " << desc->index() << " " << desc->textureType() <<
|
||||
// " " << desc->dataType() << std::endl;
|
||||
if (owner->getArguments()->count() == 0) {
|
||||
buffer = graphics->getDevice()->newBuffer(0, MTL::ResourceOptionCPUCacheModeDefault);
|
||||
} else {
|
||||
encoder = graphics->getDevice()->newArgumentEncoder(owner->getArguments());
|
||||
buffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), MTL::ResourceOptionCPUCacheModeDefault);
|
||||
encoder->setArgumentBuffer(buffer, 0);
|
||||
}
|
||||
}
|
||||
|
||||
DescriptorSet::~DescriptorSet() {}
|
||||
|
||||
@@ -100,10 +146,12 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState)
|
||||
}
|
||||
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
|
||||
PTextureBase base = texture.cast<TextureBase>();
|
||||
PSampler sampler = samplerState.cast<Sampler>();
|
||||
encoder->setTexture(base->getTexture(), binding);
|
||||
if (samplerState != nullptr) {
|
||||
PSampler sampler = samplerState.cast<Sampler>();
|
||||
encoder->setSamplerState(sampler->getHandle(), binding);
|
||||
}
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> array) {
|
||||
for (auto& t : array) {
|
||||
@@ -119,10 +167,9 @@ PipelineLayout::PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayo
|
||||
|
||||
PipelineLayout::~PipelineLayout() {}
|
||||
|
||||
void PipelineLayout::create()
|
||||
{
|
||||
for(auto& set : descriptorSetLayouts)
|
||||
{
|
||||
void PipelineLayout::create() {
|
||||
for (auto& set : descriptorSetLayouts) {
|
||||
set->create();
|
||||
uint32 setHash = set->getHash();
|
||||
layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ Graphics::~Graphics()
|
||||
|
||||
void Graphics::init(GraphicsInitializer)
|
||||
{
|
||||
glfwInit();
|
||||
device = MTL::CreateSystemDefaultDevice();
|
||||
queue = new CommandQueue(this);
|
||||
ioQueue = new IOCommandQueue(this);
|
||||
|
||||
@@ -28,6 +28,8 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr
|
||||
|
||||
MTL::VertexDescriptor* vertexDescriptor = MTL::VertexDescriptor::alloc()->init();
|
||||
MTL::VertexAttributeDescriptorArray* attributes = vertexDescriptor->attributes();
|
||||
if(createInfo.vertexInput != nullptr)
|
||||
{
|
||||
const auto& vertexInfo = createInfo.vertexInput->getInfo();
|
||||
for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) {
|
||||
MTL::VertexAttributeDescriptor* attribute = MTL::VertexAttributeDescriptor::alloc()->init();
|
||||
@@ -58,6 +60,7 @@ PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo cr
|
||||
}
|
||||
bufferLayout->setObject(buffer, binding);
|
||||
}
|
||||
}
|
||||
pipelineDescriptor->setVertexDescriptor(vertexDescriptor);
|
||||
|
||||
pipelineDescriptor->setVertexFunction(createInfo.vertexShader.cast<VertexShader>()->getFunction());
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "Graphics/slang-compile.h"
|
||||
#include "Metal/MTLDevice.hpp"
|
||||
#include "Metal/MTLLibrary.hpp"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <slang.h>
|
||||
#include <spirv_cross.hpp>
|
||||
@@ -42,7 +43,14 @@ void Shader::create(const ShaderCreateInfo& createInfo) {
|
||||
std::cout << error->debugDescription() << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
function = library->newFunction(NS::String::string("main", NS::ASCIIStringEncoding));
|
||||
function = library->newFunction(NS::String::string("main0", NS::ASCIIStringEncoding));
|
||||
if(!function)
|
||||
{
|
||||
std::ofstream shaderFile("error.metal");
|
||||
shaderFile << metalCode;
|
||||
shaderFile.close();
|
||||
assert(!function);
|
||||
}
|
||||
mtlOptions->release();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,12 +13,9 @@
|
||||
#include <QuartzCore/CAMetalLayer.hpp>
|
||||
#include <QuartzCore/QuartzCore.hpp>
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
namespace Metal
|
||||
{
|
||||
class Window : public Gfx::Window
|
||||
{
|
||||
namespace Seele {
|
||||
namespace Metal {
|
||||
class Window : public Gfx::Window {
|
||||
public:
|
||||
Window(PGraphics graphics, const WindowCreateInfo& createInfo);
|
||||
virtual ~Window();
|
||||
@@ -42,7 +39,10 @@ public:
|
||||
void fileDrop(int num, const char** files);
|
||||
void close();
|
||||
void resize(int width, int height);
|
||||
|
||||
private:
|
||||
void createBackBuffer();
|
||||
|
||||
PGraphics graphics;
|
||||
WindowCreateInfo preferences;
|
||||
GLFWwindow* windowHandle;
|
||||
@@ -60,17 +60,14 @@ private:
|
||||
std::function<void(uint32, uint32)> resizeCallback;
|
||||
};
|
||||
DEFINE_REF(Window);
|
||||
class Viewport : public Gfx::Viewport
|
||||
{
|
||||
class Viewport : public Gfx::Viewport {
|
||||
public:
|
||||
Viewport(PWindow owner, const ViewportCreateInfo& createInfo);
|
||||
virtual ~Viewport();
|
||||
constexpr MTL::Viewport getHandle() const
|
||||
{
|
||||
return viewport;
|
||||
}
|
||||
constexpr MTL::Viewport getHandle() const { return viewport; }
|
||||
virtual void resize(uint32 newX, uint32 newY);
|
||||
virtual void move(uint32 newOffset, uint32 newOffsetY);
|
||||
|
||||
private:
|
||||
MTL::Viewport viewport;
|
||||
};
|
||||
|
||||
+101
-146
@@ -1,72 +1,63 @@
|
||||
#include "Window.h"
|
||||
#include "Command.h"
|
||||
#include "Graphics/Initializer.h"
|
||||
#include "Graphics/Metal/Enums.h"
|
||||
#include "Graphics/Texture.h"
|
||||
#include "Command.h"
|
||||
#include "Metal/MTLTexture.hpp"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Metal;
|
||||
|
||||
double currentFrameDelta = 0;
|
||||
double Gfx::getCurrentFrameDelta()
|
||||
{
|
||||
return currentFrameDelta;
|
||||
}
|
||||
double Gfx::getCurrentFrameDelta() { return currentFrameDelta; }
|
||||
|
||||
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier)
|
||||
{
|
||||
if (key == -1)
|
||||
{
|
||||
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier) {
|
||||
if (key == -1) {
|
||||
return;
|
||||
}
|
||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||
window->keyPress((KeyCode)key, (InputAction)action, (KeyModifier)modifier);
|
||||
}
|
||||
|
||||
void glfwMouseMoveCallback(GLFWwindow* handle, double xpos, double ypos)
|
||||
{
|
||||
void glfwMouseMoveCallback(GLFWwindow* handle, double xpos, double ypos) {
|
||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||
window->mouseMove(xpos, ypos);
|
||||
}
|
||||
|
||||
void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int modifier)
|
||||
{
|
||||
void glfwMouseButtonCallback(GLFWwindow* handle, int button, int action, int modifier) {
|
||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||
window->mouseButton((MouseButton)button, (InputAction)action, (KeyModifier)modifier);
|
||||
}
|
||||
|
||||
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset)
|
||||
{
|
||||
void glfwScrollCallback(GLFWwindow* handle, double xoffset, double yoffset) {
|
||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||
window->scroll(xoffset, yoffset);
|
||||
}
|
||||
|
||||
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths)
|
||||
{
|
||||
void glfwFileCallback(GLFWwindow* handle, int count, const char** paths) {
|
||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||
window->fileDrop(count, paths);
|
||||
}
|
||||
|
||||
void glfwCloseCallback(GLFWwindow* handle)
|
||||
{
|
||||
void glfwCloseCallback(GLFWwindow* handle) {
|
||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||
window->close();
|
||||
}
|
||||
|
||||
void glfwFramebufferResizeCallback(GLFWwindow* handle, int width, int height)
|
||||
{
|
||||
void glfwFramebufferResizeCallback(GLFWwindow* handle, int width, int height) {
|
||||
Window* window = (Window*)glfwGetWindowUserPointer(handle);
|
||||
window->resize(width, height);
|
||||
}
|
||||
|
||||
Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo)
|
||||
: graphics(graphics)
|
||||
, preferences(createInfo)
|
||||
{
|
||||
float xscale, yscale;
|
||||
Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphics(graphics), preferences(createInfo) {
|
||||
glfwSetErrorCallback([](int, const char* description) { std::cout << description << std::endl; });
|
||||
float xscale = 1, yscale = 1;
|
||||
glfwGetMonitorContentScale(glfwGetPrimaryMonitor(), &xscale, &yscale);
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
GLFWwindow *handle = glfwCreateWindow(createInfo.width / xscale, createInfo.height / yscale, createInfo.title, nullptr, nullptr);
|
||||
GLFWwindow* handle =
|
||||
glfwCreateWindow(createInfo.width / xscale, createInfo.height / yscale, createInfo.title, nullptr, nullptr);
|
||||
windowHandle = handle;
|
||||
glfwSetWindowUserPointer(handle, this);
|
||||
|
||||
@@ -77,6 +68,10 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo)
|
||||
glfwSetDropCallback(handle, &glfwFileCallback);
|
||||
glfwSetWindowCloseCallback(handle, &glfwCloseCallback);
|
||||
glfwSetFramebufferSizeCallback(handle, &glfwFramebufferResizeCallback);
|
||||
int width, height;
|
||||
glfwGetFramebufferSize(handle, &width, &height);
|
||||
framebufferWidth = width;
|
||||
framebufferHeight = height;
|
||||
|
||||
metalWindow = glfwGetCocoaWindow(handle);
|
||||
metalLayer = [CAMetalLayer layer];
|
||||
@@ -85,24 +80,81 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo)
|
||||
metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height);
|
||||
metalWindow.contentView.layer = metalLayer;
|
||||
metalWindow.contentView.wantsLayer = YES;
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
glfwDestroyWindow(static_cast<GLFWwindow *>(windowHandle));
|
||||
}
|
||||
|
||||
void Window::pollInput()
|
||||
{
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void Window::beginFrame()
|
||||
{
|
||||
@autoreleasepool {
|
||||
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||
createBackBuffer();
|
||||
}
|
||||
|
||||
Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
|
||||
|
||||
void Window::pollInput() { glfwPollEvents(); }
|
||||
|
||||
void Window::beginFrame() {
|
||||
if (drawable) {
|
||||
drawable->release();
|
||||
}
|
||||
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||
createBackBuffer();
|
||||
}
|
||||
|
||||
void Window::endFrame() {
|
||||
graphics->getQueue()->getCommands()->present(drawable);
|
||||
graphics->getQueue()->submitCommands();
|
||||
}
|
||||
|
||||
void Window::onWindowCloseEvent() {}
|
||||
|
||||
Gfx::PTexture2D Window::getBackBuffer() const { return PTexture2D(backBuffer); }
|
||||
|
||||
void Window::setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) { keyCallback = callback; }
|
||||
|
||||
void Window::setMouseMoveCallback(std::function<void(double, double)> callback) { mouseMoveCallback = callback; }
|
||||
|
||||
void Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) {
|
||||
mouseButtonCallback = callback;
|
||||
}
|
||||
|
||||
void Window::setScrollCallback(std::function<void(double, double)> callback) { scrollCallback = callback; }
|
||||
|
||||
void Window::setFileCallback(std::function<void(int, const char**)> callback) { fileCallback = callback; }
|
||||
|
||||
void Window::setCloseCallback(std::function<void()> callback) { closeCallback = callback; }
|
||||
|
||||
void Window::setResizeCallback(std::function<void(uint32, uint32)> callback) { resizeCallback = callback; }
|
||||
|
||||
void Window::keyPress(KeyCode code, InputAction action, KeyModifier modifier) { keyCallback(code, action, modifier); }
|
||||
|
||||
void Window::mouseMove(double x, double y) { mouseMoveCallback(x, y); }
|
||||
|
||||
void Window::mouseButton(MouseButton button, InputAction action, KeyModifier modifier) {
|
||||
mouseButtonCallback(button, action, modifier);
|
||||
}
|
||||
|
||||
void Window::scroll(double x, double y) { scrollCallback(x, y); }
|
||||
|
||||
void Window::fileDrop(int num, const char** files) { fileCallback(num, files); }
|
||||
|
||||
void Window::close() { closeCallback(); }
|
||||
|
||||
void Window::resize(int width, int height) {
|
||||
if (width == 0 || height == 0) {
|
||||
paused = true;
|
||||
return;
|
||||
}
|
||||
paused = true;
|
||||
metalLayer.drawableSize = CGSizeMake(width, height);
|
||||
drawable->release();
|
||||
framebufferWidth = width;
|
||||
framebufferHeight = height;
|
||||
// Deallocate the textures if they have been created
|
||||
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||
createBackBuffer();
|
||||
resizeCallback(width, height);
|
||||
}
|
||||
|
||||
void Window::createBackBuffer() {
|
||||
MTL::Texture* buf = drawable->texture();
|
||||
backBuffer = new Texture2D(graphics, TextureCreateInfo {
|
||||
backBuffer = new Texture2D(graphics,
|
||||
TextureCreateInfo{
|
||||
.width = static_cast<uint32>(buf->width()),
|
||||
.height = static_cast<uint32>(buf->height()),
|
||||
.depth = static_cast<uint32>(buf->depth()),
|
||||
@@ -111,103 +163,11 @@ void Window::beginFrame()
|
||||
.format = cast(buf->pixelFormat()),
|
||||
.usage = MTL::TextureUsageRenderTarget,
|
||||
.samples = static_cast<uint32>(buf->sampleCount()),
|
||||
}, buf);
|
||||
}
|
||||
},
|
||||
buf);
|
||||
}
|
||||
|
||||
void Window::endFrame()
|
||||
{
|
||||
graphics->getQueue()->getCommands()->present(drawable);
|
||||
}
|
||||
|
||||
void Window::onWindowCloseEvent()
|
||||
{
|
||||
}
|
||||
|
||||
Gfx::PTexture2D Window::getBackBuffer() const
|
||||
{
|
||||
return PTexture2D(backBuffer);
|
||||
}
|
||||
|
||||
void Window::setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback)
|
||||
{
|
||||
keyCallback = callback;
|
||||
}
|
||||
|
||||
void Window::setMouseMoveCallback(std::function<void(double, double)> callback)
|
||||
{
|
||||
mouseMoveCallback = callback;
|
||||
}
|
||||
|
||||
void Window::setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback)
|
||||
{
|
||||
mouseButtonCallback = callback;
|
||||
}
|
||||
|
||||
void Window::setScrollCallback(std::function<void(double, double)> callback)
|
||||
{
|
||||
scrollCallback = callback;
|
||||
}
|
||||
|
||||
void Window::setFileCallback(std::function<void(int, const char**)> callback)
|
||||
{
|
||||
fileCallback = callback;
|
||||
}
|
||||
|
||||
void Window::setCloseCallback(std::function<void()> callback)
|
||||
{
|
||||
closeCallback = callback;
|
||||
}
|
||||
|
||||
void Window::setResizeCallback(std::function<void(uint32, uint32)> callback)
|
||||
{
|
||||
resizeCallback = callback;
|
||||
}
|
||||
|
||||
void Window::keyPress(KeyCode code, InputAction action, KeyModifier modifier)
|
||||
{
|
||||
keyCallback(code, action, modifier);
|
||||
}
|
||||
|
||||
void Window::mouseMove(double x, double y)
|
||||
{
|
||||
mouseMoveCallback(x, y);
|
||||
}
|
||||
|
||||
void Window::mouseButton(MouseButton button, InputAction action, KeyModifier modifier)
|
||||
{
|
||||
mouseButtonCallback(button, action, modifier);
|
||||
}
|
||||
|
||||
void Window::scroll(double x, double y)
|
||||
{
|
||||
scrollCallback(x, y);
|
||||
}
|
||||
|
||||
void Window::fileDrop(int num, const char** files)
|
||||
{
|
||||
fileCallback(num, files);
|
||||
}
|
||||
|
||||
void Window::close()
|
||||
{
|
||||
closeCallback();
|
||||
}
|
||||
|
||||
void Window::resize(int width, int height)
|
||||
{
|
||||
if(width == 0 || height == 0)
|
||||
{
|
||||
paused = true;
|
||||
return;
|
||||
}
|
||||
paused = true;
|
||||
resizeCallback(width, height);
|
||||
}
|
||||
|
||||
Viewport::Viewport(PWindow owner, const ViewportCreateInfo& createInfo)
|
||||
: Gfx::Viewport(owner, createInfo)
|
||||
{
|
||||
Viewport::Viewport(PWindow owner, const ViewportCreateInfo& createInfo) : Gfx::Viewport(owner, createInfo) {
|
||||
viewport.width = sizeX;
|
||||
viewport.height = sizeY;
|
||||
viewport.originX = offsetX;
|
||||
@@ -216,19 +176,14 @@ Viewport::Viewport(PWindow owner, const ViewportCreateInfo& createInfo)
|
||||
viewport.zfar = 1.0f;
|
||||
}
|
||||
|
||||
Viewport::~Viewport()
|
||||
{
|
||||
Viewport::~Viewport() {}
|
||||
|
||||
}
|
||||
|
||||
void Viewport::resize(uint32 newX, uint32 newY)
|
||||
{
|
||||
void Viewport::resize(uint32 newX, uint32 newY) {
|
||||
viewport.width = newX;
|
||||
viewport.height = newY;
|
||||
}
|
||||
|
||||
void Viewport::move(uint32 newOffset, uint32 newOffsetY)
|
||||
{
|
||||
void Viewport::move(uint32 newOffset, uint32 newOffsetY) {
|
||||
viewport.originX = newOffset;
|
||||
viewport.originY = newOffsetY;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "TextPass.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "RenderGraph.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/RenderTarget.h"
|
||||
@@ -125,7 +126,7 @@ void TextPass::createRenderPass()
|
||||
generalLayout->create();
|
||||
|
||||
textureArrayLayout = graphics->createDescriptorLayout("TextTextureArray");
|
||||
textureArrayLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT);
|
||||
textureArrayLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT);
|
||||
textureArrayLayout->create();
|
||||
|
||||
projectionBuffer = graphics->createUniformBuffer({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "UIPass.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "RenderGraph.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/RenderTarget.h"
|
||||
@@ -109,7 +110,7 @@ void UIPass::createRenderPass()
|
||||
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
||||
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
descriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT | Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT);
|
||||
descriptorLayout->addDescriptorBinding(3, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT | Gfx::SE_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT);
|
||||
descriptorLayout->create();
|
||||
|
||||
Matrix4 projectionMatrix = glm::ortho(0, 1, 1, 0);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "Material.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Serialization/Serialization.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include "MaterialInstance.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
@@ -61,9 +63,10 @@ void Material::save(ArchiveBuffer& buffer) const
|
||||
for (const auto& binding : bindings)
|
||||
{
|
||||
Serialization::save(buffer, binding.binding);
|
||||
Serialization::save(buffer, binding.bindingFlags);
|
||||
Serialization::save(buffer, binding.descriptorCount);
|
||||
Serialization::save(buffer, binding.descriptorType);
|
||||
Serialization::save(buffer, binding.textureType);
|
||||
Serialization::save(buffer, binding.descriptorCount);
|
||||
Serialization::save(buffer, binding.bindingFlags);
|
||||
Serialization::save(buffer, binding.shaderStages);
|
||||
}
|
||||
}
|
||||
@@ -88,19 +91,22 @@ void Material::load(ArchiveBuffer& buffer)
|
||||
uint32 binding;
|
||||
Serialization::load(buffer, binding);
|
||||
|
||||
Gfx::SeDescriptorBindingFlags bindingFlags;
|
||||
Serialization::load(buffer, bindingFlags);
|
||||
Gfx::SeDescriptorType descriptorType;
|
||||
Serialization::load(buffer, descriptorType);
|
||||
|
||||
Gfx::SeImageViewType textureType;
|
||||
Serialization::load(buffer, textureType);
|
||||
|
||||
uint32 descriptorCount;
|
||||
Serialization::load(buffer, descriptorCount);
|
||||
|
||||
Gfx::SeDescriptorType descriptorType;
|
||||
Serialization::load(buffer, descriptorType);
|
||||
Gfx::SeDescriptorBindingFlags bindingFlags;
|
||||
Serialization::load(buffer, bindingFlags);
|
||||
|
||||
Gfx::SeShaderStageFlags shaderStages;
|
||||
Serialization::load(buffer, shaderStages);
|
||||
|
||||
layout->addDescriptorBinding(binding, descriptorType, descriptorCount, bindingFlags, shaderStages);
|
||||
layout->addDescriptorBinding(binding, descriptorType, textureType, descriptorCount, bindingFlags, shaderStages);
|
||||
}
|
||||
layout->create();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user