2D Graphics

RSS for tag

Discuss integrating two-dimensional graphics into your app.

Posts under 2D Graphics tag

30 Posts

Post

Replies

Boosts

Views

Activity

Choosing the best framework for a vector image app. SwiftUI, UIKit or CoreGraphics?
I'm wondering which way I should go in my current app project. It is an app where the user can take a photo and place multiple 2D vector images on that photo. Some vector images are showing angles between lines. The user can interact with the vectors to change the angels to make some measurements on the photo. So you have multiple layers of vector images upon a photo. You can also pinch to zoom to have better control to set accurate vectors/angles. The user can choose the layer to interact with so I need to have control of all gesture recognizers and for example deactivate the pinch gestures on the scroll view. I'm wondering which technology I should use 🤔 SwiftUI, UIKit or CoreGraphics? Does somebody have some recommendations?
2
0
1.3k
Jan ’22
MTLDebugCommandBuffer lockPurgeableObjects
I'm using Xcode 13 after recently updating to MacOS Monterey, and only after updating am I getting this error: [MTLDebugCommandBuffer lockPurgeableObjects]:2103: failed assertion `MTLResource 0x14a8a8cc0 (label: null), referenced in cmd buffer 0x149091400 (label: null) is in volatile or empty purgeable state at commit' I haven't changed my code at all between updating to the latest OS, and it worked perfectly before. How can I fix this? I don't think there should be any reason that I can't use a command buffer on a texture resource with a volatile/empty purgeable state.
4
0
3.5k
Jan ’22
Error while converting MTLTexture to CVPixelBuffer
I am getting an error from the graphics driver while converting the EnvironmentTexture(from ARKIT.AREnvironmentProbeAnchor) to CVPixelBuffer. The EnvironmentTexture is an IMTLTexture. I am using Xamarin.iOS. This is the code that I use to convert the IMTLTexture to CVPixelBuffer. buffers[i] = new CVPixelBuffer((nint)epAnchor.EnvironmentTexture.Width, (nint)epAnchor.EnvironmentTexture.Height, CVPixelFormatType.CV32RGBA); GetEnvironmentTextureSlice(buffers[i], epAnchor.EnvironmentTexture, i); public void GetEnvironmentTextureSlice(CVPixelBuffer pixelBuffer, Metal.IMTLTexture texture, int id) { Metal.MTLRegion mtlRegion = Metal.MTLRegion.Create2D((nuint)0, 0, 256, 256); nuint bytesPerPixel = 4; nuint bytesPerRow = bytesPerPixel * (nuint)mtlRegion.Size.Width; // (nuint)pixelBuffer.BytesPerRow; nuint bytesPerImage = bytesPerRow * (nuint)mtlRegion.Size.Height; pixelBuffer.Lock(CVPixelBufferLock.None); texture.GetBytes(pixelBuffer.BaseAddress, (nuint)pixelBuffer.BytesPerRow, mtlRegion, 0); pixelBuffer.Unlock(CVPixelBufferLock.None); } The error I am getting from the driver is AGX: Texture read/write assertion failed: bytes_per_row = used_bytes_per_row I tried with different values of pixelBuffer.BytesPerRow but still getting the error. Can someone help me?
1
0
2.1k
Dec ’21
Can someone walk me through the app launch sequence at a low level?
Sorry if this is a bad question or if this is asked so much it's like a routine to copy-and-paste this sort of stuff whenever someone else asks but I've been trying to get into Xcode and Swift app development for a while now and I do it on and off in a cycle. I try to get into it and start working with Xcode directly and doing stuff the proper way but I get frustrated by the amount of stuff that seems to go over my head and try to find a different way to make my coding projects / experiments a reality. When I make a new project, there's tons of stuff going on and I feel like I'm just expected to work around it with no idea how any of it works. I guess my head works very much from the ground up, needing to know how things work down to the most basic level for me to incorporate any knowledge into my understanding of a subject. When I try to create a new project from the game template (I use game because it seems closest to my graphing experiment ideas,) there's all sorts of stuff created; AppDelegate, GameScene, ViewControler, Main.storyboard etc and when I launch all this stuff just works. I look at the dev documentation and start to figure stuff out like ok when the app launches it finds the storyboard but how? Where's the option that tells the app the name of the file to launch as the storyboard? How does the viewControler represented in the storyboard know which file represents it? Ok so the dev doc says that the first step in the app launch sequence is UIApplicationMain() but where does it actually get executed from? The app? The OS? There are arguments passed to it so that's where the app delegate comes in but where are the actual args specified? I guess what I'm looking for is the answers to "how would I create all this from scratch? How would I create this without Xcode, go from empty folder with a .app extension to minimal working 2d graphing app and how does all of it work? How does the macOS interpret and properly execute an app?" I'm used to working with building apps in Java and whatnot from scratch, building windows with methods and one main method specified for debug by the compiler / fed to the jar file to first be executed when the file is opened and stuff like that. Ever since reading the Swift guide I found at the official Swift website I've absolutely fallen in love with the language; never before have I thought a language was 'my kind of language' or whose syntax is just perfectly logical to me. I suppose one of the things I really want is to be able to use Swift like Java when it comes to apps and have everything in the code and be able to trace it for myself and work with things through objects and methods and such I hope this makes sense to someone and they can point me in the right direction and get me started reading at the right spot to click on links and branch out my reading from there. Can't wait to get into actual app development the right way instead of using hack solutions like working through Java, C, C++ or whatever and sometimes having to use the app stuff anyways and also using Swift outside of playing around in playgrounds and thinking 'I really wish I could just create an app that just compiles and launches this like the playground'
2
0
927
Nov ’21
low-level graphic programming in C++
Requirements : I need to draw 2D lines, circles, boxes. Fast. That's it. I don't want to learn objC, Swift, Xcode. I'm using C++ and Jetbrains' CLion. OpenGL is deprecated (or soon to be) on Mac I don't even care about Apple (as you probably guessed), but the M1 processor is just too good. (and fanless <3) I'll be happy as long as it runs on my MacBook Air Text would be a useful feature but totally optional I won't even use sprites, or any kind of assets, sound, keyboard, mouse, IO, GUI. I need pure non-interactive visualisation of science-ish stuff. fast FPS, refreshing the visualization as fast as possible. Even if it's a pure framebuffer (an array of pixels), I'll manage. If it's a full fledged 3D accelerated graphic library (eg : openGL, Vulkan, Metal), it also works for me. "as long as it works" What kind of options are available to me with the aforementioned requirements ? use openGL anyway and cry when it will no longer works ? (meh) hack my way to Metal in C++ ? I'm fine if a suggested library isn't Object Oriented (eg : openGL) Vulkan ? I still need to open a graphic window context somehow SDL2 appears to have a some kind of Metal backend/port/whatever but all the exemples I find are in ObjC. honestly, my post feel like I'm crying for a documented c++ metal wrapper of some kind I suppose ? EDIT : I read mixed message and confusion on the Future of OpenGL on Mac. Mostly about "no longer supported" vs "Deprecated". Will OpenGL be removed and no longer works. Or it will works but won't be updated anymore ? (considering my requirements, an outdated version of OpenGL is perfectly fine to me) Thank you <3
4
0
6.3k
Oct ’21
Draw Call vs Tile Shader
While developing my Metal application I noticed that making a draw call is a lot slower than using a tile shader. In particular, when operating on a 4k resolution texture it takes about 3ms to complete a draw call while the tile shader takes about 150ns. I was wondering, is a tile shader the preferred approach for drawing with Metal now? Or is there any particular reason why a typical draw call should be used.
1
0
1.5k
Sep ’21
Access Parent Render Pass
I have two render passes, one that is nested within another, and I'd like for the inner pass to have access to the color attachments of the outer pass. Is it possible for render pass 2 to have knowledge of render pass 1's color at any given moment? Here is the logic: 1.) Start render pass 1 with texture 1 2.) Draw objects 3.) Start render pass 2 with texture 2 4.) Draw objects using color from render pass 1 5.) End render pass 2 6.) Draw output of render pass 2 into render pass 1 7.) End render pass 1
1
0
1.5k
Sep ’21
Override traitCollection of UIView
I am using a UIView with a nib as a template for a UIImage that I am generating, and I want to handle the output of the iPad in landscape differently than portrait. The best way I have figured I can do that is by setting up my landscape view for horizontal Regular, vertical Compact traits in the nib and assigning those traits before generating the image. I have tried using the performAsCurrent method which successfully changes the UITraitCollection.current value but does not affect my UIView traitCollection property, and I have tried overriding the traitCollection getter in the UIView class which returns the error: Class overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API. Is there a way to do this for a UIView that is never drawn to the screen?
1
0
3.9k
Jul ’21
How to get a correct CIImage/CVPixelBuffer from a ProRaw?
I need to process the ProRaw photo as soon as it is captured. Our flow for the Bayer Raw includes creating an MTLTexture from a CVPixelBuffer. But with ProRaw looks like the problem is even before this step. We need a linear image so I've tried the following sample (adjusted to work on iOS 14): var options: [CIRAWFilterOption: Any] = [     .baselineExposure: 0.0,     .boostAmount: 0.0,     .boostShadowAmount: 0.0,     .disableGamutMap: true ] if #available(iOS 14.3, *) {     options[.ciInputLocalToneMapAmountKey] = 0.0 } let pxFilter = CIFilter(cvPixelBuffer: photo.pixelBuffer!, properties: photo.metadata, options: options)! let pxImage = pxFilter.outputImage! (ignore all the force unwrappings, it is just a proof of concept) And the output image is always overexposed here: How can I get a linear image with proper exposure?
2
0
1.5k
Jul ’21
Choosing the best framework for a vector image app. SwiftUI, UIKit or CoreGraphics?
I'm wondering which way I should go in my current app project. It is an app where the user can take a photo and place multiple 2D vector images on that photo. Some vector images are showing angles between lines. The user can interact with the vectors to change the angels to make some measurements on the photo. So you have multiple layers of vector images upon a photo. You can also pinch to zoom to have better control to set accurate vectors/angles. The user can choose the layer to interact with so I need to have control of all gesture recognizers and for example deactivate the pinch gestures on the scroll view. I'm wondering which technology I should use 🤔 SwiftUI, UIKit or CoreGraphics? Does somebody have some recommendations?
Replies
2
Boosts
0
Views
1.3k
Activity
Jan ’22
MTLDebugCommandBuffer lockPurgeableObjects
I'm using Xcode 13 after recently updating to MacOS Monterey, and only after updating am I getting this error: [MTLDebugCommandBuffer lockPurgeableObjects]:2103: failed assertion `MTLResource 0x14a8a8cc0 (label: null), referenced in cmd buffer 0x149091400 (label: null) is in volatile or empty purgeable state at commit' I haven't changed my code at all between updating to the latest OS, and it worked perfectly before. How can I fix this? I don't think there should be any reason that I can't use a command buffer on a texture resource with a volatile/empty purgeable state.
Replies
4
Boosts
0
Views
3.5k
Activity
Jan ’22
Error while converting MTLTexture to CVPixelBuffer
I am getting an error from the graphics driver while converting the EnvironmentTexture(from ARKIT.AREnvironmentProbeAnchor) to CVPixelBuffer. The EnvironmentTexture is an IMTLTexture. I am using Xamarin.iOS. This is the code that I use to convert the IMTLTexture to CVPixelBuffer. buffers[i] = new CVPixelBuffer((nint)epAnchor.EnvironmentTexture.Width, (nint)epAnchor.EnvironmentTexture.Height, CVPixelFormatType.CV32RGBA); GetEnvironmentTextureSlice(buffers[i], epAnchor.EnvironmentTexture, i); public void GetEnvironmentTextureSlice(CVPixelBuffer pixelBuffer, Metal.IMTLTexture texture, int id) { Metal.MTLRegion mtlRegion = Metal.MTLRegion.Create2D((nuint)0, 0, 256, 256); nuint bytesPerPixel = 4; nuint bytesPerRow = bytesPerPixel * (nuint)mtlRegion.Size.Width; // (nuint)pixelBuffer.BytesPerRow; nuint bytesPerImage = bytesPerRow * (nuint)mtlRegion.Size.Height; pixelBuffer.Lock(CVPixelBufferLock.None); texture.GetBytes(pixelBuffer.BaseAddress, (nuint)pixelBuffer.BytesPerRow, mtlRegion, 0); pixelBuffer.Unlock(CVPixelBufferLock.None); } The error I am getting from the driver is AGX: Texture read/write assertion failed: bytes_per_row = used_bytes_per_row I tried with different values of pixelBuffer.BytesPerRow but still getting the error. Can someone help me?
Replies
1
Boosts
0
Views
2.1k
Activity
Dec ’21
Can someone walk me through the app launch sequence at a low level?
Sorry if this is a bad question or if this is asked so much it's like a routine to copy-and-paste this sort of stuff whenever someone else asks but I've been trying to get into Xcode and Swift app development for a while now and I do it on and off in a cycle. I try to get into it and start working with Xcode directly and doing stuff the proper way but I get frustrated by the amount of stuff that seems to go over my head and try to find a different way to make my coding projects / experiments a reality. When I make a new project, there's tons of stuff going on and I feel like I'm just expected to work around it with no idea how any of it works. I guess my head works very much from the ground up, needing to know how things work down to the most basic level for me to incorporate any knowledge into my understanding of a subject. When I try to create a new project from the game template (I use game because it seems closest to my graphing experiment ideas,) there's all sorts of stuff created; AppDelegate, GameScene, ViewControler, Main.storyboard etc and when I launch all this stuff just works. I look at the dev documentation and start to figure stuff out like ok when the app launches it finds the storyboard but how? Where's the option that tells the app the name of the file to launch as the storyboard? How does the viewControler represented in the storyboard know which file represents it? Ok so the dev doc says that the first step in the app launch sequence is UIApplicationMain() but where does it actually get executed from? The app? The OS? There are arguments passed to it so that's where the app delegate comes in but where are the actual args specified? I guess what I'm looking for is the answers to "how would I create all this from scratch? How would I create this without Xcode, go from empty folder with a .app extension to minimal working 2d graphing app and how does all of it work? How does the macOS interpret and properly execute an app?" I'm used to working with building apps in Java and whatnot from scratch, building windows with methods and one main method specified for debug by the compiler / fed to the jar file to first be executed when the file is opened and stuff like that. Ever since reading the Swift guide I found at the official Swift website I've absolutely fallen in love with the language; never before have I thought a language was 'my kind of language' or whose syntax is just perfectly logical to me. I suppose one of the things I really want is to be able to use Swift like Java when it comes to apps and have everything in the code and be able to trace it for myself and work with things through objects and methods and such I hope this makes sense to someone and they can point me in the right direction and get me started reading at the right spot to click on links and branch out my reading from there. Can't wait to get into actual app development the right way instead of using hack solutions like working through Java, C, C++ or whatever and sometimes having to use the app stuff anyways and also using Swift outside of playing around in playgrounds and thinking 'I really wish I could just create an app that just compiles and launches this like the playground'
Replies
2
Boosts
0
Views
927
Activity
Nov ’21
low-level graphic programming in C++
Requirements : I need to draw 2D lines, circles, boxes. Fast. That's it. I don't want to learn objC, Swift, Xcode. I'm using C++ and Jetbrains' CLion. OpenGL is deprecated (or soon to be) on Mac I don't even care about Apple (as you probably guessed), but the M1 processor is just too good. (and fanless <3) I'll be happy as long as it runs on my MacBook Air Text would be a useful feature but totally optional I won't even use sprites, or any kind of assets, sound, keyboard, mouse, IO, GUI. I need pure non-interactive visualisation of science-ish stuff. fast FPS, refreshing the visualization as fast as possible. Even if it's a pure framebuffer (an array of pixels), I'll manage. If it's a full fledged 3D accelerated graphic library (eg : openGL, Vulkan, Metal), it also works for me. "as long as it works" What kind of options are available to me with the aforementioned requirements ? use openGL anyway and cry when it will no longer works ? (meh) hack my way to Metal in C++ ? I'm fine if a suggested library isn't Object Oriented (eg : openGL) Vulkan ? I still need to open a graphic window context somehow SDL2 appears to have a some kind of Metal backend/port/whatever but all the exemples I find are in ObjC. honestly, my post feel like I'm crying for a documented c++ metal wrapper of some kind I suppose ? EDIT : I read mixed message and confusion on the Future of OpenGL on Mac. Mostly about "no longer supported" vs "Deprecated". Will OpenGL be removed and no longer works. Or it will works but won't be updated anymore ? (considering my requirements, an outdated version of OpenGL is perfectly fine to me) Thank you <3
Replies
4
Boosts
0
Views
6.3k
Activity
Oct ’21
Draw Call vs Tile Shader
While developing my Metal application I noticed that making a draw call is a lot slower than using a tile shader. In particular, when operating on a 4k resolution texture it takes about 3ms to complete a draw call while the tile shader takes about 150ns. I was wondering, is a tile shader the preferred approach for drawing with Metal now? Or is there any particular reason why a typical draw call should be used.
Replies
1
Boosts
0
Views
1.5k
Activity
Sep ’21
Access Parent Render Pass
I have two render passes, one that is nested within another, and I'd like for the inner pass to have access to the color attachments of the outer pass. Is it possible for render pass 2 to have knowledge of render pass 1's color at any given moment? Here is the logic: 1.) Start render pass 1 with texture 1 2.) Draw objects 3.) Start render pass 2 with texture 2 4.) Draw objects using color from render pass 1 5.) End render pass 2 6.) Draw output of render pass 2 into render pass 1 7.) End render pass 1
Replies
1
Boosts
0
Views
1.5k
Activity
Sep ’21
Initialize UIImage with SVG file
I know how to initialize a UIImage with an SVG from the assets catalog, is there not a way to do it with an SVG downloaded from an API? UIImage(data: ) fails. So does UIImage(contentsOfFile:) Why only do this halfway?
Replies
2
Boosts
2
Views
8.5k
Activity
Aug ’21
Override traitCollection of UIView
I am using a UIView with a nib as a template for a UIImage that I am generating, and I want to handle the output of the iPad in landscape differently than portrait. The best way I have figured I can do that is by setting up my landscape view for horizontal Regular, vertical Compact traits in the nib and assigning those traits before generating the image. I have tried using the performAsCurrent method which successfully changes the UITraitCollection.current value but does not affect my UIView traitCollection property, and I have tried overriding the traitCollection getter in the UIView class which returns the error: Class overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API. Is there a way to do this for a UIView that is never drawn to the screen?
Replies
1
Boosts
0
Views
3.9k
Activity
Jul ’21
How to get a correct CIImage/CVPixelBuffer from a ProRaw?
I need to process the ProRaw photo as soon as it is captured. Our flow for the Bayer Raw includes creating an MTLTexture from a CVPixelBuffer. But with ProRaw looks like the problem is even before this step. We need a linear image so I've tried the following sample (adjusted to work on iOS 14): var options: [CIRAWFilterOption: Any] = [     .baselineExposure: 0.0,     .boostAmount: 0.0,     .boostShadowAmount: 0.0,     .disableGamutMap: true ] if #available(iOS 14.3, *) {     options[.ciInputLocalToneMapAmountKey] = 0.0 } let pxFilter = CIFilter(cvPixelBuffer: photo.pixelBuffer!, properties: photo.metadata, options: options)! let pxImage = pxFilter.outputImage! (ignore all the force unwrappings, it is just a proof of concept) And the output image is always overexposed here: How can I get a linear image with proper exposure?
Replies
2
Boosts
0
Views
1.5k
Activity
Jul ’21