This commit is contained in:
halx99 2022-11-01 16:02:13 +08:00
parent 7f77a5e9f4
commit e84982f86d
7 changed files with 45 additions and 9 deletions

View File

@ -175,6 +175,8 @@ public:
*/ */
virtual void endFrame() override; virtual void endFrame() override;
void endEncoding();
/** /**
* Fixed-function state * Fixed-function state
* @param lineWidth Specifies the width of rasterized lines. * @param lineWidth Specifies the width of rasterized lines.
@ -196,6 +198,10 @@ public:
* @param callback A callback to deal with pixel data read. * @param callback A callback to deal with pixel data read.
*/ */
virtual void readPixels(RenderTarget* rt, std::function<void(const PixelBufferDescriptor&)> callback) override; virtual void readPixels(RenderTarget* rt, std::function<void(const PixelBufferDescriptor&)> callback) override;
id<MTLRenderCommandEncoder> getRenderCommandEncoder() const { return _mtlRenderEncoder; }
id<MTLCommandBuffer> getMTLCommandBuffer() const { return _mtlCommandBuffer; }
protected: protected:
/** /**

View File

@ -347,6 +347,15 @@ void CommandBufferMTL::endFrame()
[_autoReleasePool drain]; [_autoReleasePool drain];
} }
void CommandBufferMTL::endEncoding()
{
if (_mtlRenderEncoder) {
[_mtlRenderEncoder endEncoding];
[_mtlRenderEncoder release];
}
_mtlRenderEncoder = nil;
}
void CommandBufferMTL::flush() void CommandBufferMTL::flush()
{ {
if (_mtlCommandBuffer) if (_mtlCommandBuffer)

View File

@ -58,6 +58,10 @@ struct UtilsMTL
static void updateDefaultColorAttachmentTexture(id<MTLTexture> texture); static void updateDefaultColorAttachmentTexture(id<MTLTexture> texture);
static void resizeDefaultAttachmentTexture(std::size_t width, std::size_t height); static void resizeDefaultAttachmentTexture(std::size_t width, std::size_t height);
static MTLPixelFormat getDefaultColorAttachmentPixelFormat();
static MTLPixelFormat getDefaultDepthStencilAttachmentPixelFormat();
/** /**
* Get the default combined depth and stencil texture. * Get the default combined depth and stencil texture.
* @return The default combined depth and stencil texture. * @return The default combined depth and stencil texture.

View File

@ -122,6 +122,16 @@ void UtilsMTL::initGPUTextureFormats()
info.fmt = getSupportedDepthStencilFormat(); info.fmt = getSupportedDepthStencilFormat();
} }
MTLPixelFormat UtilsMTL::getDefaultColorAttachmentPixelFormat()
{
return MTLPixelFormatBGRA8Unorm;
}
MTLPixelFormat UtilsMTL::getDefaultDepthStencilAttachmentPixelFormat()
{
return getSupportedDepthStencilFormat();
}
id<MTLTexture> UtilsMTL::getDefaultDepthStencilTexture() id<MTLTexture> UtilsMTL::getDefaultDepthStencilTexture()
{ {
if (!_defaultDepthStencilAttachmentTexture) if (!_defaultDepthStencilAttachmentTexture)

View File

@ -99,8 +99,10 @@ if (APPLE)
set_target_properties (LLGI PROPERTIES FOLDER Extensions/Effekseer) set_target_properties (LLGI PROPERTIES FOLDER Extensions/Effekseer)
endif() endif()
add_subdirectory(EffekseerRendererGL) if (NOT APPLE)
set_target_properties (EffekseerRendererGL PROPERTIES FOLDER Extensions/Effekseer) add_subdirectory(EffekseerRendererGL)
set_target_properties (EffekseerRendererGL PROPERTIES FOLDER Extensions/Effekseer)
endif()
add_subdirectory(EffekseerForCocos2d-x) add_subdirectory(EffekseerForCocos2d-x)

View File

@ -33,10 +33,12 @@ if (APPLE)
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
PUBLIC EffekseerRendererMetal PUBLIC EffekseerRendererMetal
PUBLIC EffekseerRendererGL) # PUBLIC EffekseerRendererGL
)
add_dependencies(${PROJECT_NAME} EffekseerRendererMetal) add_dependencies(${PROJECT_NAME} EffekseerRendererMetal)
add_dependencies(${PROJECT_NAME} EffekseerRendererGL)
# add_dependencies(${PROJECT_NAME} EffekseerRendererGL)
else() else()
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}
PUBLIC ../EffekseerRendererGL/) PUBLIC ../EffekseerRendererGL/)

View File

@ -20,11 +20,13 @@ void SetMTLObjectsFromCocos2d(Effekseer::RefPtr<EffekseerRenderer::CommandList>
auto bufferM = static_cast<cocos2d::backend::CommandBufferMTL*>(buffer); auto bufferM = static_cast<cocos2d::backend::CommandBufferMTL*>(buffer);
// use render pass descriptor from Cocos and add depth test // use render pass descriptor from Cocos and add depth test
auto descriptor = renderer->getRenderPassDescriptor(); // auto descriptor = d->getRenderPassDescriptor();
descriptor.depthTestEnabled = true; // ax::backend::RenderPassDescriptor descriptor;
// descriptor.flags.clear = true;
// using axmol render pass // using axmol render pass
auto target = renderer->getRenderTarget(); auto target = renderer->getRenderTarget();
bufferM->beginRenderPass(target, descriptor);
renderer->beginRenderPass();
auto v = renderer->getViewport(); auto v = renderer->getViewport();
// important for ensuring znear and zfar are in sync with Cocos // important for ensuring znear and zfar are in sync with Cocos
bufferM->setViewport(v.x, v.y, v.w, v.h); bufferM->setViewport(v.x, v.y, v.w, v.h);
@ -84,7 +86,8 @@ bool DistortingCallbackMetal::OnDistorting(EffekseerRenderer::Renderer* renderer
textureInternal_ = EffekseerRendererMetal::CreateTexture(renderer->GetGraphicsDevice(), texture); textureInternal_ = EffekseerRendererMetal::CreateTexture(renderer->GetGraphicsDevice(), texture);
} }
auto commandBuffer = static_cast<cocos2d::backend::CommandBufferMTL*>(cocos2d::Director::getInstance()->getCommandBuffer()); auto rendererAX = cocos2d::Director::getInstance()->getRenderer();
auto commandBuffer = static_cast<cocos2d::backend::CommandBufferMTL*>(rendererAX->getCommandBuffer());
commandBuffer->endEncoding(); commandBuffer->endEncoding();
EffekseerRendererMetal::EndCommandList(commandList_); EffekseerRendererMetal::EndCommandList(commandList_);
@ -172,7 +175,7 @@ void UpdateTextureData(::Effekseer::TextureRef textureData, cocos2d::Texture2D*
auto textureMTL = static_cast<cocos2d::backend::TextureMTL*>(texture->getBackendTexture()); auto textureMTL = static_cast<cocos2d::backend::TextureMTL*>(texture->getBackendTexture());
auto device = EffekseerGraphicsDevice::create().DownCast<::EffekseerRendererLLGI::Backend::GraphicsDevice>(); auto device = EffekseerGraphicsDevice::create().DownCast<::EffekseerRendererLLGI::Backend::GraphicsDevice>();
auto backend = device->CreateTexture(reinterpret_cast<uint64_t>(textureMTL->getMTLTexture()), []() -> void {}); auto backend = device->CreateTexture(textureMTL->getHandler(), []() -> void {});
textureData->SetBackend(backend); textureData->SetBackend(backend);
} }