Post

Replies

Boosts

Views

Activity

Copying Metal Texture Of Previous Drawable to Current Drawable With Alpha Information
Hi everyone I am trying to take the texture from a previous draw call that renders some objects and copy them to the next draw call that renders different objects. So far I have tried the blit commander way and I tried to manually copy the textures, but both ways seem to completely overwrite the current texture while not taking into account alpha information. I am doing this after my initial command encoder that binds the buffers. I noticed that the previous texture's alpha information is not processed so it overwrites the current layer with the _view.clearColor value. I confirmed that both layers get presented as one layer is shown the majority of the time while the other layer flashes every now and then. Layer 1 completely overwrites layer 0 so all I see if layer 1 instead of the two layers being combined, the green is the view's clearColor and seems to be part of the texture which I think is the problem: Layer 1: Layer 0: The blit commander way, my data is split into layers and if the first layer is getting rendered in the batch then that one does not get copied over since it starts from the top to render the layers in the correct order on top of each other:     if(previousDrawable && currentDrawable && previousTexture != currentDrawable.texture){         [blitCommandEncoder copyFromTexture:previousTexture toTexture:currentDrawable.texture];     }     [blitCommandEncoder endEncoding]; if(currentDrawable && layerId > 0){         self.previousDrawable = currentDrawable;         self.previousTexture = currentDrawable.texture;     }else{         self.previousDrawable = nil;     } The manual texture copying way: if(previousDrawable && currentDrawable && previousTexture != currentDrawable.texture){ int textureSize = currentDrawable.texture.width * currentDrawable.texture.height * 4;         unsigned char* previousTextureData = new unsigned char[textureSize];         unsigned char* currentTextureData = new unsigned char[textureSize];         [previousDrawable.texture getBytes:previousTextureData bytesPerRow:previousDrawable.texture.width * 4 fromRegion:MTLRegionMake2D(0, 0, previousDrawable.texture.width, previousDrawable.texture.height) mipmapLevel:0];         [currentDrawable.texture getBytes:currentTextureData bytesPerRow:currentDrawable.texture.width * 4 fromRegion:MTLRegionMake2D(0, 0, currentDrawable.texture.width, currentDrawable.texture.height) mipmapLevel:0];         for(int i = 0; i < textureSize; i+=4){             if((int)previousTextureData[i + 3] > 0)             {                 currentTextureData[i] = previousTextureData[i];                 currentTextureData[i + 1] = previousTextureData[i + 1];                 currentTextureData[i + 2] = previousTextureData[i + 2];                 currentTextureData[i + 3] = previousTextureData[i + 3];             }         }         [currentDrawable.texture replaceRegion:MTLRegionMake2D(0, 0, currentDrawable.texture.width, currentDrawable.texture.height) mipmapLevel:0 withBytes:currentTextureData bytesPerRow:currentDrawable.texture.width * 4];         delete[] previousTextureData;         delete[] currentTextureData; } if(currentDrawable && layerId > 0){         self.previousDrawable = currentDrawable;         self.previousTexture = currentDrawable.texture;     }else{         self.previousDrawable = nil;     }
1
0
1k
Aug ’22
NSBundle Redeclaration Error for Multiple Functions In Metal CPP
Hi I am trying to get started using Metal CPP after viewing the documentation and defining the constants below: #ifndef MTL_PRIVATE_IMPLEMENTATION #define NS_PRIVATE_IMPLEMENTATION #define MTL_PRIVATE_IMPLEMENTATION //#define MTK_PRIVATE_IMPLEMENTATION #define CA_PRIVATE_IMPLEMENTATION #endif I commented out the MTK macro since it was not in the getting started video although it was in the fundamentals projects for metal cpp. I am defining this in a Objective C++ header along with including: #import <Foundation/Foundation.hpp> #import <Metal/Metal.hpp> #import <QuartzCore/QuartzCore.hpp> #import <MetalKit/MetalKit.h> #import <simd/simd.h> I get the error: redeclaration of 'NSPOSIXErrorDomain' with a different type: 'const NSErrorDomain  _Nonnull __strong' (aka 'NSString *const __strong') vs 'const NS::ErrorDomain' (aka 'NS::String *const') along with other errors similar to that one. These errors all seem to do with <Foundation/Foundation.h>. I can see that the NS prefix is being declared rather than the C++ version of NS:: but I am sure I implemented this correctly. I have a header set up in Objective C for this file along with things being @implementation rather than pure C++: #pragma once #include "../../../src/state/config.h" #ifdef __PEN_IOS__ //#import <cassert> #ifndef MTL_PRIVATE_IMPLEMENTATION #define NS_PRIVATE_IMPLEMENTATION #define MTL_PRIVATE_IMPLEMENTATION //#define MTK_PRIVATE_IMPLEMENTATION #define CA_PRIVATE_IMPLEMENTATION #endif #ifdef TARGET_IPHONE_SIMULATOR //#import <UIKit/UIKit.h> #elifdef TARGET_OS_IPHONE //#import <UIKit/UIKit.hpp> #elifdef TARGET_OS_IOS //#import <UIKit/UIKit.hpp> #elifdef TARGET_OS_MAC //#import <AppKit/AppKit.hpp> #endif #import <Foundation/Foundation.hpp> #import <Metal/Metal.hpp> //#import <CoreFoundation/CoreFoundation.h> #import <QuartzCore/QuartzCore.hpp> #import <MetalKit/MetalKit.h> #import <simd/simd.h> #import "ios_cpp_objective_c_mapping.h" @class IOSState; @interface IOSState : NSObject @property MTK::View* iosMtkView;     @property MTL::Device* iosDevice;     @property MTL::CommandQueue* iosCommandQueue;     @property MTL::RenderPipelineState* iosPipelineState;     @property NS::Notification* iosLaunchNotification;     @property MTL::ArgumentEncoder* iosArgEncoder;     @property MTL::DepthStencilState* iosDepthStencilState;     @property MTL::Texture* iosPixelBuffer;     @property MTL::Buffer* iosUniformBuffer;     @property MTL::Buffer* iosInstanceBuffer;     @property MTL::RenderCommandEncoder* iosCommandEncoder;     @property MTL::CommandBuffer* iosCommandBuffer;     @property NS::AutoreleasePool* iosAutoReleasePool;     @property dispatch_semaphore_t dispatchSemaphore; + (IOSState*) Get; + (void) Destroy; @end #endif I include this file in multiple places although the headers should be able to be included more than once.
3
0
1.3k
Aug ’22
Copying Metal Texture Of Previous Drawable to Current Drawable With Alpha Information
Hi everyone I am trying to take the texture from a previous draw call that renders some objects and copy them to the next draw call that renders different objects. So far I have tried the blit commander way and I tried to manually copy the textures, but both ways seem to completely overwrite the current texture while not taking into account alpha information. I am doing this after my initial command encoder that binds the buffers. I noticed that the previous texture's alpha information is not processed so it overwrites the current layer with the _view.clearColor value. I confirmed that both layers get presented as one layer is shown the majority of the time while the other layer flashes every now and then. Layer 1 completely overwrites layer 0 so all I see if layer 1 instead of the two layers being combined, the green is the view's clearColor and seems to be part of the texture which I think is the problem: Layer 1: Layer 0: The blit commander way, my data is split into layers and if the first layer is getting rendered in the batch then that one does not get copied over since it starts from the top to render the layers in the correct order on top of each other:     if(previousDrawable && currentDrawable && previousTexture != currentDrawable.texture){         [blitCommandEncoder copyFromTexture:previousTexture toTexture:currentDrawable.texture];     }     [blitCommandEncoder endEncoding]; if(currentDrawable && layerId > 0){         self.previousDrawable = currentDrawable;         self.previousTexture = currentDrawable.texture;     }else{         self.previousDrawable = nil;     } The manual texture copying way: if(previousDrawable && currentDrawable && previousTexture != currentDrawable.texture){ int textureSize = currentDrawable.texture.width * currentDrawable.texture.height * 4;         unsigned char* previousTextureData = new unsigned char[textureSize];         unsigned char* currentTextureData = new unsigned char[textureSize];         [previousDrawable.texture getBytes:previousTextureData bytesPerRow:previousDrawable.texture.width * 4 fromRegion:MTLRegionMake2D(0, 0, previousDrawable.texture.width, previousDrawable.texture.height) mipmapLevel:0];         [currentDrawable.texture getBytes:currentTextureData bytesPerRow:currentDrawable.texture.width * 4 fromRegion:MTLRegionMake2D(0, 0, currentDrawable.texture.width, currentDrawable.texture.height) mipmapLevel:0];         for(int i = 0; i < textureSize; i+=4){             if((int)previousTextureData[i + 3] > 0)             {                 currentTextureData[i] = previousTextureData[i];                 currentTextureData[i + 1] = previousTextureData[i + 1];                 currentTextureData[i + 2] = previousTextureData[i + 2];                 currentTextureData[i + 3] = previousTextureData[i + 3];             }         }         [currentDrawable.texture replaceRegion:MTLRegionMake2D(0, 0, currentDrawable.texture.width, currentDrawable.texture.height) mipmapLevel:0 withBytes:currentTextureData bytesPerRow:currentDrawable.texture.width * 4];         delete[] previousTextureData;         delete[] currentTextureData; } if(currentDrawable && layerId > 0){         self.previousDrawable = currentDrawable;         self.previousTexture = currentDrawable.texture;     }else{         self.previousDrawable = nil;     }
Replies
1
Boosts
0
Views
1k
Activity
Aug ’22
NSBundle Redeclaration Error for Multiple Functions In Metal CPP
Hi I am trying to get started using Metal CPP after viewing the documentation and defining the constants below: #ifndef MTL_PRIVATE_IMPLEMENTATION #define NS_PRIVATE_IMPLEMENTATION #define MTL_PRIVATE_IMPLEMENTATION //#define MTK_PRIVATE_IMPLEMENTATION #define CA_PRIVATE_IMPLEMENTATION #endif I commented out the MTK macro since it was not in the getting started video although it was in the fundamentals projects for metal cpp. I am defining this in a Objective C++ header along with including: #import <Foundation/Foundation.hpp> #import <Metal/Metal.hpp> #import <QuartzCore/QuartzCore.hpp> #import <MetalKit/MetalKit.h> #import <simd/simd.h> I get the error: redeclaration of 'NSPOSIXErrorDomain' with a different type: 'const NSErrorDomain  _Nonnull __strong' (aka 'NSString *const __strong') vs 'const NS::ErrorDomain' (aka 'NS::String *const') along with other errors similar to that one. These errors all seem to do with <Foundation/Foundation.h>. I can see that the NS prefix is being declared rather than the C++ version of NS:: but I am sure I implemented this correctly. I have a header set up in Objective C for this file along with things being @implementation rather than pure C++: #pragma once #include "../../../src/state/config.h" #ifdef __PEN_IOS__ //#import <cassert> #ifndef MTL_PRIVATE_IMPLEMENTATION #define NS_PRIVATE_IMPLEMENTATION #define MTL_PRIVATE_IMPLEMENTATION //#define MTK_PRIVATE_IMPLEMENTATION #define CA_PRIVATE_IMPLEMENTATION #endif #ifdef TARGET_IPHONE_SIMULATOR //#import <UIKit/UIKit.h> #elifdef TARGET_OS_IPHONE //#import <UIKit/UIKit.hpp> #elifdef TARGET_OS_IOS //#import <UIKit/UIKit.hpp> #elifdef TARGET_OS_MAC //#import <AppKit/AppKit.hpp> #endif #import <Foundation/Foundation.hpp> #import <Metal/Metal.hpp> //#import <CoreFoundation/CoreFoundation.h> #import <QuartzCore/QuartzCore.hpp> #import <MetalKit/MetalKit.h> #import <simd/simd.h> #import "ios_cpp_objective_c_mapping.h" @class IOSState; @interface IOSState : NSObject @property MTK::View* iosMtkView;     @property MTL::Device* iosDevice;     @property MTL::CommandQueue* iosCommandQueue;     @property MTL::RenderPipelineState* iosPipelineState;     @property NS::Notification* iosLaunchNotification;     @property MTL::ArgumentEncoder* iosArgEncoder;     @property MTL::DepthStencilState* iosDepthStencilState;     @property MTL::Texture* iosPixelBuffer;     @property MTL::Buffer* iosUniformBuffer;     @property MTL::Buffer* iosInstanceBuffer;     @property MTL::RenderCommandEncoder* iosCommandEncoder;     @property MTL::CommandBuffer* iosCommandBuffer;     @property NS::AutoreleasePool* iosAutoReleasePool;     @property dispatch_semaphore_t dispatchSemaphore; + (IOSState*) Get; + (void) Destroy; @end #endif I include this file in multiple places although the headers should be able to be included more than once.
Replies
3
Boosts
0
Views
1.3k
Activity
Aug ’22