mirror of
https://github.com/TomHarte/CLK.git
synced 2024-07-07 23:29:06 +00:00
This is possibly at least dispatching an empty command buffer correctly.
This commit is contained in:
parent
e235a45abb
commit
72df6e52cd
@ -7,12 +7,13 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <MetalKit/MetalKit.h>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Provides a ScanTarget that uses Metal as its back-end.
|
Provides a ScanTarget that uses Metal as its back-end.
|
||||||
*/
|
*/
|
||||||
@interface CSScanTarget : NSObject
|
@interface CSScanTarget : NSObject <MTKViewDelegate>
|
||||||
|
|
||||||
- (nonnull instancetype)init;
|
- (nonnull instancetype)initWithView:(nonnull MTKView *)view;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -11,18 +11,47 @@
|
|||||||
#import <Metal/Metal.h>
|
#import <Metal/Metal.h>
|
||||||
|
|
||||||
@implementation CSScanTarget {
|
@implementation CSScanTarget {
|
||||||
id<MTLDevice> _device;
|
|
||||||
id<MTLCommandQueue> _commandQueue;
|
id<MTLCommandQueue> _commandQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (nonnull instancetype)init {
|
- (nonnull instancetype)initWithView:(nonnull MTKView *)view {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if(self) {
|
if(self) {
|
||||||
_device = MTLCreateSystemDefaultDevice();
|
_commandQueue = [view.device newCommandQueue];
|
||||||
_commandQueue = [_device newCommandQueue];
|
|
||||||
NSLog(@"%@; %@", _device, _commandQueue);
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@method mtkView:drawableSizeWillChange:
|
||||||
|
@abstract Called whenever the drawableSize of the view will change
|
||||||
|
@discussion Delegate can recompute view and projection matricies or regenerate any buffers to be compatible with the new view size or resolution
|
||||||
|
@param view MTKView which called this method
|
||||||
|
@param size New drawable size in pixels
|
||||||
|
*/
|
||||||
|
- (void)mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size {
|
||||||
|
NSLog(@"New size: %@", NSStringFromSize(size));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@method drawInMTKView:
|
||||||
|
@abstract Called on the delegate when it is asked to render into the view
|
||||||
|
@discussion Called on the delegate when it is asked to render into the view
|
||||||
|
*/
|
||||||
|
- (void)drawInMTKView:(nonnull MTKView *)view {
|
||||||
|
id <MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer];
|
||||||
|
MTLRenderPassDescriptor *const descriptor = view.currentRenderPassDescriptor;
|
||||||
|
id <MTLRenderCommandEncoder> encoder = [commandBuffer renderCommandEncoderWithDescriptor:descriptor];
|
||||||
|
|
||||||
|
// TODO: the drawing (!)
|
||||||
|
|
||||||
|
[encoder endEncoding];
|
||||||
|
|
||||||
|
// "Register the drawable's presentation".
|
||||||
|
[commandBuffer presentDrawable:view.currentDrawable];
|
||||||
|
|
||||||
|
// Finalise and commit.
|
||||||
|
[commandBuffer commit];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#import "CSScanTargetView.h"
|
#import "CSScanTargetView.h"
|
||||||
#import "CSApplication.h"
|
#import "CSApplication.h"
|
||||||
|
#import "CSScanTarget.h"
|
||||||
@import CoreVideo;
|
@import CoreVideo;
|
||||||
@import GLKit;
|
@import GLKit;
|
||||||
|
|
||||||
@ -27,6 +28,8 @@
|
|||||||
|
|
||||||
atomic_int _isDrawingFlag;
|
atomic_int _isDrawingFlag;
|
||||||
BOOL _isInvalid;
|
BOOL _isInvalid;
|
||||||
|
|
||||||
|
CSScanTarget *_scanTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- (void)prepareOpenGL {
|
//- (void)prepareOpenGL {
|
||||||
@ -120,9 +123,10 @@ static CVReturn DisplayLinkCallback(__unused CVDisplayLinkRef displayLink, const
|
|||||||
[self redrawWithEvent:CSScanTargetViewRedrawEventTimer];
|
[self redrawWithEvent:CSScanTargetViewRedrawEventTimer];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)drawRect:(NSRect)dirtyRect {
|
//- (void)drawRect:(NSRect)dirtyRect {
|
||||||
[self redrawWithEvent:CSScanTargetViewRedrawEventAppKit];
|
// [self redrawWithEvent:CSScanTargetViewRedrawEventAppKit];
|
||||||
}
|
// NSLog(@"...");
|
||||||
|
//}
|
||||||
|
|
||||||
- (void)redrawWithEvent:(CSScanTargetViewRedrawEvent)event {
|
- (void)redrawWithEvent:(CSScanTargetViewRedrawEvent)event {
|
||||||
[self performWithGLContext:^{
|
[self performWithGLContext:^{
|
||||||
@ -179,6 +183,13 @@ static CVReturn DisplayLinkCallback(__unused CVDisplayLinkRef displayLink, const
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
- (void)awakeFromNib {
|
- (void)awakeFromNib {
|
||||||
|
// Use the preferred device if available.
|
||||||
|
if(@available(macOS 10.15, *)) {
|
||||||
|
self.device = self.preferredDevice;
|
||||||
|
} else {
|
||||||
|
self.device = MTLCreateSystemDefaultDevice();
|
||||||
|
}
|
||||||
|
|
||||||
// NSOpenGLPixelFormatAttribute attributes[] = {
|
// NSOpenGLPixelFormatAttribute attributes[] = {
|
||||||
// NSOpenGLPFADoubleBuffer,
|
// NSOpenGLPFADoubleBuffer,
|
||||||
// NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
|
// NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
|
||||||
@ -203,6 +214,9 @@ static CVReturn DisplayLinkCallback(__unused CVDisplayLinkRef displayLink, const
|
|||||||
// self.pixelFormat = pixelFormat;
|
// self.pixelFormat = pixelFormat;
|
||||||
// self.openGLContext = context;
|
// self.openGLContext = context;
|
||||||
// self.wantsBestResolutionOpenGLSurface = YES;
|
// self.wantsBestResolutionOpenGLSurface = YES;
|
||||||
|
// Create the scan target.
|
||||||
|
_scanTarget = [[CSScanTarget alloc] initWithView:self];
|
||||||
|
self.delegate = _scanTarget;
|
||||||
|
|
||||||
// Register to receive dragged and dropped file URLs.
|
// Register to receive dragged and dropped file URLs.
|
||||||
[self registerForDraggedTypes:@[(__bridge NSString *)kUTTypeFileURL]];
|
[self registerForDraggedTypes:@[(__bridge NSString *)kUTTypeFileURL]];
|
||||||
|
Loading…
Reference in New Issue
Block a user