Kore Update
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
#ifdef KORE_METAL
|
||||
#ifdef KINC_METAL
|
||||
#import <MetalKit/MTKView.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@ -9,7 +9,7 @@
|
||||
#import <OpenGL/glu.h>
|
||||
#endif
|
||||
|
||||
#ifdef KORE_METAL
|
||||
#ifdef KINC_METAL
|
||||
|
||||
struct kinc_g5_render_target;
|
||||
|
||||
@ -32,7 +32,7 @@ struct kinc_g5_render_target;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef KORE_METAL
|
||||
#ifdef KINC_METAL
|
||||
- (CAMetalLayer *)metalLayer;
|
||||
- (id<MTLDevice>)metalDevice;
|
||||
- (id<MTLLibrary>)metalLibrary;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
#include <kinc/input/pen.h>
|
||||
#include <kinc/system.h>
|
||||
|
||||
#ifdef KORE_METAL
|
||||
#ifdef KINC_METAL
|
||||
#include <kinc/graphics5/graphics.h>
|
||||
#endif
|
||||
|
||||
@ -16,7 +16,7 @@ static bool ctrl = false;
|
||||
static bool alt = false;
|
||||
static bool cmd = false;
|
||||
|
||||
#ifndef KORE_METAL
|
||||
#ifndef KINC_METAL
|
||||
+ (NSOpenGLPixelFormat *)basicPixelFormat {
|
||||
// TODO (DK) pass via argument in
|
||||
int aa = 1; // Kore::Application::the()->antialiasing();
|
||||
@ -62,19 +62,19 @@ static bool cmd = false;
|
||||
cmd = false;
|
||||
}
|
||||
|
||||
if ([theEvent modifierFlags] & NSShiftKeyMask) {
|
||||
if ([theEvent modifierFlags] & NSEventModifierFlagShift) {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_SHIFT);
|
||||
shift = true;
|
||||
}
|
||||
if ([theEvent modifierFlags] & NSControlKeyMask) {
|
||||
if ([theEvent modifierFlags] & NSEventModifierFlagControl) {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_CONTROL);
|
||||
ctrl = true;
|
||||
}
|
||||
if ([theEvent modifierFlags] & NSAlternateKeyMask) {
|
||||
if ([theEvent modifierFlags] & NSEventModifierFlagOption) {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_ALT);
|
||||
alt = true;
|
||||
}
|
||||
if ([theEvent modifierFlags] & NSCommandKeyMask) {
|
||||
if ([theEvent modifierFlags] & NSEventModifierFlagCommand) {
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_META);
|
||||
cmd = true;
|
||||
}
|
||||
@ -144,15 +144,18 @@ static bool cmd = false;
|
||||
case NSNewlineCharacter:
|
||||
case NSCarriageReturnCharacter:
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_RETURN);
|
||||
kinc_internal_keyboard_trigger_key_press('\n');
|
||||
break;
|
||||
case 0x7f:
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_BACKSPACE);
|
||||
kinc_internal_keyboard_trigger_key_press('\x08');
|
||||
break;
|
||||
case 9:
|
||||
kinc_internal_keyboard_trigger_key_down(KINC_KEY_TAB);
|
||||
kinc_internal_keyboard_trigger_key_press('\t');
|
||||
break;
|
||||
default:
|
||||
if (ch == 'x' && [theEvent modifierFlags] & NSCommandKeyMask) {
|
||||
if (ch == 'x' && [theEvent modifierFlags] & NSEventModifierFlagCommand) {
|
||||
char *text = kinc_internal_cut_callback();
|
||||
if (text != NULL) {
|
||||
NSPasteboard *board = [NSPasteboard generalPasteboard];
|
||||
@ -160,7 +163,7 @@ static bool cmd = false;
|
||||
[board setString:[NSString stringWithUTF8String:text] forType:NSStringPboardType];
|
||||
}
|
||||
}
|
||||
if (ch == 'c' && [theEvent modifierFlags] & NSCommandKeyMask) {
|
||||
if (ch == 'c' && [theEvent modifierFlags] & NSEventModifierFlagCommand) {
|
||||
char *text = kinc_internal_copy_callback();
|
||||
if (text != NULL) {
|
||||
NSPasteboard *board = [NSPasteboard generalPasteboard];
|
||||
@ -168,7 +171,7 @@ static bool cmd = false;
|
||||
[board setString:[NSString stringWithUTF8String:text] forType:NSStringPboardType];
|
||||
}
|
||||
}
|
||||
if (ch == 'v' && [theEvent modifierFlags] & NSCommandKeyMask) {
|
||||
if (ch == 'v' && [theEvent modifierFlags] & NSEventModifierFlagCommand) {
|
||||
NSPasteboard *board = [NSPasteboard generalPasteboard];
|
||||
NSString *data = [board stringForType:NSStringPboardType];
|
||||
if (data != nil) {
|
||||
@ -292,7 +295,7 @@ static bool controlKeyMouseButton = false;
|
||||
|
||||
- (void)mouseDown:(NSEvent *)theEvent {
|
||||
// TODO (DK) map [theEvent window] to window id instead of 0
|
||||
if ([theEvent modifierFlags] & NSControlKeyMask) {
|
||||
if ([theEvent modifierFlags] & NSEventModifierFlagControl) {
|
||||
controlKeyMouseButton = true;
|
||||
kinc_internal_mouse_trigger_press(0, 1, getMouseX(theEvent), getMouseY(theEvent));
|
||||
}
|
||||
@ -301,7 +304,7 @@ static bool controlKeyMouseButton = false;
|
||||
kinc_internal_mouse_trigger_press(0, 0, getMouseX(theEvent), getMouseY(theEvent));
|
||||
}
|
||||
|
||||
if ([theEvent subtype] == NSTabletPointEventSubtype) {
|
||||
if ([theEvent subtype] == NSEventSubtypeTabletPoint) {
|
||||
kinc_internal_pen_trigger_press(0, getMouseX(theEvent), getMouseY(theEvent), theEvent.pressure);
|
||||
}
|
||||
}
|
||||
@ -316,7 +319,7 @@ static bool controlKeyMouseButton = false;
|
||||
}
|
||||
controlKeyMouseButton = false;
|
||||
|
||||
if ([theEvent subtype] == NSTabletPointEventSubtype) {
|
||||
if ([theEvent subtype] == NSEventSubtypeTabletPoint) {
|
||||
kinc_internal_pen_trigger_release(0, getMouseX(theEvent), getMouseY(theEvent), theEvent.pressure);
|
||||
}
|
||||
}
|
||||
@ -330,7 +333,7 @@ static bool controlKeyMouseButton = false;
|
||||
// TODO (DK) map [theEvent window] to window id instead of 0
|
||||
kinc_internal_mouse_trigger_move(0, getMouseX(theEvent), getMouseY(theEvent));
|
||||
|
||||
if ([theEvent subtype] == NSTabletPointEventSubtype) {
|
||||
if ([theEvent subtype] == NSEventSubtypeTabletPoint) {
|
||||
kinc_internal_pen_trigger_move(0, getMouseX(theEvent), getMouseY(theEvent), theEvent.pressure);
|
||||
}
|
||||
}
|
||||
@ -390,7 +393,7 @@ static bool controlKeyMouseButton = false;
|
||||
return YES;
|
||||
}
|
||||
|
||||
#ifndef KORE_METAL
|
||||
#ifndef KINC_METAL
|
||||
- (void)prepareOpenGL {
|
||||
const GLint swapInt = 1;
|
||||
[[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
|
||||
@ -399,12 +402,12 @@ static bool controlKeyMouseButton = false;
|
||||
#endif
|
||||
|
||||
- (void)update { // window resizes, moves and display changes (resize, depth and display config change)
|
||||
#ifdef KORE_OPENGL
|
||||
#ifdef KINC_OPENGL
|
||||
[super update];
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef KORE_METAL
|
||||
#ifndef KINC_METAL
|
||||
- (id)initWithFrame:(NSRect)frameRect {
|
||||
NSOpenGLPixelFormat *pf = [BasicOpenGLView basicPixelFormat];
|
||||
self = [super initWithFrame:frameRect pixelFormat:pf];
|
||||
@ -416,7 +419,7 @@ static bool controlKeyMouseButton = false;
|
||||
}
|
||||
#else
|
||||
|
||||
void initMetalCompute(id<MTLDevice> device, id<MTLCommandQueue> commandBuffer);
|
||||
static CAMetalLayer *metalLayer = NULL;
|
||||
|
||||
- (id)initWithFrame:(NSRect)frameRect {
|
||||
self = [super initWithFrame:frameRect];
|
||||
@ -424,9 +427,8 @@ void initMetalCompute(id<MTLDevice> device, id<MTLCommandQueue> commandBuffer);
|
||||
device = MTLCreateSystemDefaultDevice();
|
||||
commandQueue = [device newCommandQueue];
|
||||
library = [device newDefaultLibrary];
|
||||
initMetalCompute(device, commandQueue);
|
||||
|
||||
CAMetalLayer *metalLayer = (CAMetalLayer *)self.layer;
|
||||
metalLayer = (CAMetalLayer *)self.layer;
|
||||
|
||||
metalLayer.device = device;
|
||||
metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
|
||||
@ -456,7 +458,7 @@ void initMetalCompute(id<MTLDevice> device, id<MTLCommandQueue> commandBuffer);
|
||||
[self setFrameSize:size];
|
||||
}
|
||||
|
||||
#ifdef KORE_METAL
|
||||
#ifdef KINC_METAL
|
||||
- (CAMetalLayer *)metalLayer {
|
||||
return (CAMetalLayer *)self.layer;
|
||||
}
|
||||
|
||||
@ -17,15 +17,13 @@ void macStopVideoSoundStream(void) {
|
||||
video = NULL;
|
||||
}
|
||||
|
||||
// const int samplesPerSecond = 44100;
|
||||
|
||||
static void affirm(OSStatus err) {
|
||||
if (err != kAudioHardwareNoError) {
|
||||
kinc_log(KINC_LOG_LEVEL_ERROR, "Error: %i\n", err);
|
||||
}
|
||||
}
|
||||
|
||||
static bool initialized;
|
||||
static bool initialized = false;
|
||||
static bool soundPlaying;
|
||||
static AudioDeviceID device;
|
||||
static UInt32 deviceBufferSize;
|
||||
@ -35,50 +33,56 @@ static AudioObjectPropertyAddress address;
|
||||
|
||||
static AudioDeviceIOProcID theIOProcID = NULL;
|
||||
|
||||
static void (*a2_callback)(kinc_a2_buffer_t *buffer, int samples) = NULL;
|
||||
static void (*a2_sample_rate_callback)(void) = NULL;
|
||||
static kinc_a2_buffer_t a2_buffer;
|
||||
|
||||
static uint32_t samples_per_second = 44100;
|
||||
|
||||
uint32_t kinc_a2_samples_per_second(void) {
|
||||
return samples_per_second;
|
||||
}
|
||||
|
||||
static void copySample(void *buffer) {
|
||||
float value = *(float *)&a2_buffer.data[a2_buffer.read_location];
|
||||
a2_buffer.read_location += 4;
|
||||
if (a2_buffer.read_location >= a2_buffer.data_size)
|
||||
float left_value = *(float *)&a2_buffer.channels[0][a2_buffer.read_location];
|
||||
float right_value = *(float *)&a2_buffer.channels[1][a2_buffer.read_location];
|
||||
a2_buffer.read_location += 1;
|
||||
if (a2_buffer.read_location >= a2_buffer.data_size) {
|
||||
a2_buffer.read_location = 0;
|
||||
*(float *)buffer = value;
|
||||
}
|
||||
((float *)buffer)[0] = left_value;
|
||||
((float *)buffer)[1] = right_value;
|
||||
}
|
||||
|
||||
static OSStatus appIOProc(AudioDeviceID inDevice, const AudioTimeStamp *inNow, const AudioBufferList *inInputData, const AudioTimeStamp *inInputTime,
|
||||
AudioBufferList *outOutputData, const AudioTimeStamp *inOutputTime, void *userdata) {
|
||||
affirm(AudioObjectGetPropertyData(device, &address, 0, NULL, &size, &deviceFormat));
|
||||
if (kinc_a2_samples_per_second != (int)deviceFormat.mSampleRate) {
|
||||
kinc_a2_samples_per_second = (int)deviceFormat.mSampleRate;
|
||||
if (a2_sample_rate_callback != NULL) {
|
||||
a2_sample_rate_callback();
|
||||
}
|
||||
if (samples_per_second != (int)deviceFormat.mSampleRate) {
|
||||
samples_per_second = (int)deviceFormat.mSampleRate;
|
||||
kinc_a2_internal_sample_rate_callback();
|
||||
}
|
||||
int numSamples = deviceBufferSize / deviceFormat.mBytesPerFrame;
|
||||
a2_callback(&a2_buffer, numSamples * 2);
|
||||
float *out = (float *)outOutputData->mBuffers[0].mData;
|
||||
for (int i = 0; i < numSamples; ++i) {
|
||||
copySample(out++); // left
|
||||
copySample(out++); // right
|
||||
int num_frames = deviceBufferSize / deviceFormat.mBytesPerFrame;
|
||||
kinc_a2_internal_callback(&a2_buffer, num_frames);
|
||||
float *output = (float *)outOutputData->mBuffers[0].mData;
|
||||
for (int i = 0; i < num_frames; ++i) {
|
||||
copySample(output);
|
||||
output += 2;
|
||||
}
|
||||
return kAudioHardwareNoError;
|
||||
}
|
||||
|
||||
static bool initialized = false;
|
||||
|
||||
void kinc_a2_init(void) {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
kinc_a2_internal_init();
|
||||
initialized = true;
|
||||
|
||||
a2_buffer.read_location = 0;
|
||||
a2_buffer.write_location = 0;
|
||||
a2_buffer.data_size = 128 * 1024;
|
||||
a2_buffer.data = (uint8_t *)malloc(a2_buffer.data_size);
|
||||
a2_buffer.channel_count = 2;
|
||||
a2_buffer.channels[0] = (float *)malloc(a2_buffer.data_size * sizeof(float));
|
||||
a2_buffer.channels[1] = (float *)malloc(a2_buffer.data_size * sizeof(float));
|
||||
|
||||
device = kAudioDeviceUnknown;
|
||||
|
||||
@ -113,10 +117,10 @@ void kinc_a2_init(void) {
|
||||
return;
|
||||
}
|
||||
|
||||
kinc_a2_samples_per_second = (int)deviceFormat.mSampleRate;
|
||||
a2_buffer.format.samples_per_second = kinc_a2_samples_per_second;
|
||||
a2_buffer.format.bits_per_sample = 32;
|
||||
a2_buffer.format.channels = 2;
|
||||
if (samples_per_second != (int)deviceFormat.mSampleRate) {
|
||||
samples_per_second = (int)deviceFormat.mSampleRate;
|
||||
kinc_a2_internal_sample_rate_callback();
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
|
||||
@ -150,11 +154,3 @@ void kinc_a2_shutdown(void) {
|
||||
|
||||
soundPlaying = false;
|
||||
}
|
||||
|
||||
void kinc_a2_set_callback(void (*kinc_a2_audio_callback)(kinc_a2_buffer_t *buffer, int samples)) {
|
||||
a2_callback = kinc_a2_audio_callback;
|
||||
}
|
||||
|
||||
void kinc_a2_set_sample_rate_callback(void (*kinc_a2_sample_rate_callback)(void)) {
|
||||
a2_sample_rate_callback = kinc_a2_sample_rate_callback;
|
||||
}
|
||||
|
||||
@ -13,17 +13,21 @@
|
||||
|
||||
#include <kinc/backend/windowdata.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
bool withAutoreleasepool(bool (*f)(void)) {
|
||||
@autoreleasepool {
|
||||
return f();
|
||||
}
|
||||
}
|
||||
|
||||
extern const char *macgetresourcepath(void);
|
||||
|
||||
const char *macgetresourcepath(void) {
|
||||
return [[[NSBundle mainBundle] resourcePath] cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@interface KincApplication : NSApplication {
|
||||
}
|
||||
@ -56,7 +60,7 @@ static struct HIDManager *hidManager;
|
||||
}
|
||||
};*/
|
||||
|
||||
#ifdef KORE_METAL
|
||||
#ifdef KINC_METAL
|
||||
CAMetalLayer *getMetalLayer(void) {
|
||||
return [view metalLayer];
|
||||
}
|
||||
@ -75,7 +79,7 @@ id getMetalQueue(void) {
|
||||
#endif
|
||||
|
||||
bool kinc_internal_handle_messages(void) {
|
||||
NSEvent *event = [myapp nextEventMatchingMask:NSAnyEventMask
|
||||
NSEvent *event = [myapp nextEventMatchingMask:NSEventMaskAny
|
||||
untilDate:[NSDate distantPast]
|
||||
inMode:NSDefaultRunLoopMode
|
||||
dequeue:YES]; // distantPast: non-blocking
|
||||
@ -91,11 +95,17 @@ bool kinc_internal_handle_messages(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void swapBuffersMac(int windowId) {
|
||||
#ifndef KORE_METAL
|
||||
#ifndef KINC_METAL
|
||||
[windows[windowId].view switchBuffers];
|
||||
#endif
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
static int createWindow(kinc_window_options_t *options) {
|
||||
int width = options->width / [[NSScreen mainScreen] backingScaleFactor];
|
||||
@ -174,10 +184,6 @@ static void addMenubar(void) {
|
||||
[NSApp setMainMenu:menubar];
|
||||
}
|
||||
|
||||
#ifdef KINC_KONG
|
||||
void kong_init(void);
|
||||
#endif
|
||||
|
||||
int kinc_init(const char *name, int width, int height, kinc_window_options_t *win, kinc_framebuffer_options_t *frame) {
|
||||
@autoreleasepool {
|
||||
myapp = [KincApplication sharedApplication];
|
||||
@ -212,11 +218,7 @@ int kinc_init(const char *name, int width, int height, kinc_window_options_t *wi
|
||||
int windowId = createWindow(win);
|
||||
kinc_g4_internal_init();
|
||||
kinc_g4_internal_init_window(windowId, frame->depth_bits, frame->stencil_bits, true);
|
||||
|
||||
#ifdef KINC_KONG
|
||||
kong_init();
|
||||
#endif
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -14,14 +14,26 @@ void kinc_window_resize(int window, int width, int height) {}
|
||||
|
||||
void kinc_window_move(int window, int x, int y) {}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void kinc_internal_change_framebuffer(int window, struct kinc_framebuffer_options *frame);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
void kinc_window_change_framebuffer(int window, struct kinc_framebuffer_options *frame) {
|
||||
kinc_internal_change_framebuffer(0, frame);
|
||||
}
|
||||
|
||||
#ifdef KORE_METAL
|
||||
#ifdef KINC_METAL
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void kinc_internal_change_framebuffer(int window, struct kinc_framebuffer_options *frame) {}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void kinc_window_change_features(int window, int features) {}
|
||||
|
||||
Reference in New Issue
Block a user