Merge branch 'master' into ios_tmp
* master: fix issue on macos x refactor # Conflicts: # src/macosx/MacMiniFB.m # src/macosx/OSXWindowFrameView.h # src/macosx/OSXWindowFrameView.m
This commit is contained in:
commit
6452ec1bfd
@ -6,10 +6,13 @@ project(${PROJECT_NAME})
|
|||||||
message("Processing " ${PROJECT_NAME})
|
message("Processing " ${PROJECT_NAME})
|
||||||
|
|
||||||
if(NOT DEFINED IOS)
|
if(NOT DEFINED IOS)
|
||||||
if(TOLOWER CMAKE_SYSTEM_NAME STREQUAL "ios")
|
if(DEFINED CMAKE_SYSTEM_NAME)
|
||||||
|
string(TOLOWER CMAKE_SYSTEM_NAME CMAKE_SYSTEM_NAME_LOWER)
|
||||||
|
if(CMAKE_SYSTEM_NAME_LOWER STREQUAL "ios")
|
||||||
set(IOS true)
|
set(IOS true)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
set(SrcLib
|
set(SrcLib
|
||||||
include/MiniFB.h
|
include/MiniFB.h
|
||||||
@ -133,21 +136,11 @@ elseif (APPLE)
|
|||||||
add_definitions(-DUSE_METAL_API)
|
add_definitions(-DUSE_METAL_API)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#link_libraries("-framework Cocoa")
|
|
||||||
#link_libraries("-framework QuartzCore")
|
|
||||||
#link_libraries("-framework Metal")
|
|
||||||
#link_libraries("-framework MetalKit")
|
|
||||||
|
|
||||||
list(APPEND SrcLib ${SrcMacOSX})
|
list(APPEND SrcLib ${SrcMacOSX})
|
||||||
elseif (UNIX)
|
elseif (UNIX)
|
||||||
if(USE_WAYLAND_API)
|
if(USE_WAYLAND_API)
|
||||||
#link_libraries("-lwayland-client")
|
|
||||||
#link_libraries("-lwayland-cursor")
|
|
||||||
|
|
||||||
list(APPEND SrcLib ${SrcWayland})
|
list(APPEND SrcLib ${SrcWayland})
|
||||||
else()
|
else()
|
||||||
#link_libraries("-lX11")
|
|
||||||
|
|
||||||
list(APPEND SrcLib ${SrcX11})
|
list(APPEND SrcLib ${SrcX11})
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
@ -161,18 +154,30 @@ add_library(minifb STATIC
|
|||||||
#--------------------------------------
|
#--------------------------------------
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
if(IOS)
|
if(IOS)
|
||||||
|
target_link_libraries(minifb
|
||||||
|
"-framework UIKit"
|
||||||
|
"-framework QuartzCore"
|
||||||
|
"-framework Metal"
|
||||||
|
"-framework MetalKit"
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(minifb "-framework Cocoa")
|
target_link_libraries(minifb
|
||||||
target_link_libraries(minifb "-framework QuartzCore")
|
"-framework Cocoa"
|
||||||
target_link_libraries(minifb "-framework Metal")
|
"-framework QuartzCore"
|
||||||
target_link_libraries(minifb "-framework MetalKit")
|
"-framework Metal"
|
||||||
|
"-framework MetalKit"
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
elseif (UNIX)
|
elseif (UNIX)
|
||||||
if(USE_WAYLAND_API)
|
if(USE_WAYLAND_API)
|
||||||
target_link_libraries(minifb "-lwayland-client")
|
target_link_libraries(minifb
|
||||||
target_link_libraries(minifb "-lwayland-cursor")
|
"-lwayland-client"
|
||||||
|
"-lwayland-cursor"
|
||||||
|
)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(minifb "-lX11")
|
target_link_libraries(minifb
|
||||||
|
"-lX11"
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -186,6 +191,7 @@ link_libraries(minifb)
|
|||||||
# Examples
|
# Examples
|
||||||
#--------------------------------------
|
#--------------------------------------
|
||||||
if(NOT IOS)
|
if(NOT IOS)
|
||||||
|
|
||||||
add_executable(noise
|
add_executable(noise
|
||||||
tests/noise.c
|
tests/noise.c
|
||||||
)
|
)
|
||||||
@ -201,7 +207,9 @@ if(NOT IOS)
|
|||||||
add_executable(multiple_windows
|
add_executable(multiple_windows
|
||||||
tests/multiple_windows.c
|
tests/multiple_windows.c
|
||||||
)
|
)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
|
|
||||||
add_executable(noise
|
add_executable(noise
|
||||||
tests/ios/main.m
|
tests/ios/main.m
|
||||||
tests/ios/AppDelegate.h
|
tests/ios/AppDelegate.h
|
||||||
@ -210,14 +218,11 @@ else()
|
|||||||
|
|
||||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Set CMake deployment target" ${FORCE_CACHE})
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Set CMake deployment target" ${FORCE_CACHE})
|
||||||
|
|
||||||
target_include_directories(minifb PRIVATE src)
|
target_include_directories(noise PRIVATE src)
|
||||||
|
target_include_directories(noise PRIVATE src/ios)
|
||||||
|
|
||||||
add_definitions(-DTVOS_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
|
add_definitions(-DTVOS_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET})
|
||||||
|
|
||||||
target_include_directories(noise PRIVATE src/ios)
|
|
||||||
|
|
||||||
target_link_libraries(noise "-framework UIKit")
|
|
||||||
target_link_libraries(noise "-framework Metal")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message("Done " ${PROJECT_NAME})
|
message("Done " ${PROJECT_NAME})
|
||||||
|
@ -200,14 +200,11 @@ mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
|
|||||||
|
|
||||||
// Create the texture from the device by using the descriptor
|
// Create the texture from the device by using the descriptor
|
||||||
for (size_t i = 0; i < MaxBuffersInFlight; ++i) {
|
for (size_t i = 0; i < MaxBuffersInFlight; ++i) {
|
||||||
viewController->m_texture_buffers[i] = [g_metal_device newTextureWithDescriptor:td];
|
viewController->texture_buffers[i] = [g_metal_device newTextureWithDescriptor:td];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used for syncing the CPU and GPU
|
// Used for syncing the CPU and GPU
|
||||||
viewController->m_semaphore = dispatch_semaphore_create(MaxBuffersInFlight);
|
viewController->semaphore = dispatch_semaphore_create(MaxBuffersInFlight);
|
||||||
viewController->m_draw_buffer = window_data->draw_buffer;
|
|
||||||
viewController->m_width = width;
|
|
||||||
viewController->m_height = height;
|
|
||||||
|
|
||||||
MTKView* view = [[MTKView alloc] initWithFrame:rectangle];
|
MTKView* view = [[MTKView alloc] initWithFrame:rectangle];
|
||||||
view.device = g_metal_device;
|
view.device = g_metal_device;
|
||||||
@ -313,10 +310,13 @@ mfb_update(struct mfb_window *window, void *buffer) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
update_events(window_data);
|
update_events(window_data);
|
||||||
if(window_data->close == false) {
|
if(window_data->close) {
|
||||||
|
destroy_window_data(window_data);
|
||||||
|
return STATE_EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
||||||
[[window_data_osx->window contentView] setNeedsDisplay:YES];
|
[[window_data_osx->window contentView] setNeedsDisplay:YES];
|
||||||
}
|
|
||||||
|
|
||||||
return STATE_OK;
|
return STATE_OK;
|
||||||
}
|
}
|
||||||
@ -336,10 +336,13 @@ mfb_update_events(struct mfb_window *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update_events(window_data);
|
update_events(window_data);
|
||||||
if(window_data->close == false) {
|
if(window_data->close) {
|
||||||
|
destroy_window_data(window_data);
|
||||||
|
return STATE_EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
||||||
[[window_data_osx->window contentView] setNeedsDisplay:YES];
|
[[window_data_osx->window contentView] setNeedsDisplay:YES];
|
||||||
}
|
|
||||||
|
|
||||||
return STATE_OK;
|
return STATE_OK;
|
||||||
}
|
}
|
||||||
@ -365,6 +368,10 @@ mfb_wait_sync(struct mfb_window *window) {
|
|||||||
//NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
//NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
||||||
|
if(window_data_osx == 0x0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
double current;
|
double current;
|
||||||
uint32_t millis = 1;
|
uint32_t millis = 1;
|
||||||
while(1) {
|
while(1) {
|
||||||
@ -400,6 +407,10 @@ mfb_wait_sync(struct mfb_window *window) {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y, unsigned width, unsigned height) {
|
||||||
|
if(window == 0x0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
SWindowData *window_data = (SWindowData *) window;
|
SWindowData *window_data = (SWindowData *) window;
|
||||||
|
|
||||||
if(offset_x + width > window_data->window_width) {
|
if(offset_x + width > window_data->window_width) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#include <WindowData.h>
|
#include <WindowData.h>
|
||||||
// @class OSXWindowFrameView;
|
|
||||||
|
|
||||||
@interface OSXWindow : NSWindow<NSWindowDelegate>
|
@interface OSXWindow : NSWindow<NSWindowDelegate>
|
||||||
{
|
{
|
||||||
|
@ -72,6 +72,9 @@
|
|||||||
|
|
||||||
- (void)flagsChanged:(NSEvent *)event
|
- (void)flagsChanged:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
if(window_data == 0x0)
|
||||||
|
return;
|
||||||
|
|
||||||
const uint32_t flags = [event modifierFlags];
|
const uint32_t flags = [event modifierFlags];
|
||||||
uint32_t mod_keys = 0, mod_keys_aux = 0;
|
uint32_t mod_keys = 0, mod_keys_aux = 0;
|
||||||
|
|
||||||
@ -135,29 +138,34 @@
|
|||||||
|
|
||||||
- (void)keyDown:(NSEvent *)event
|
- (void)keyDown:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
if(window_data != 0x0) {
|
||||||
short int key_code = g_keycodes[[event keyCode] & 0x1ff];
|
short int key_code = g_keycodes[[event keyCode] & 0x1ff];
|
||||||
window_data->key_status[key_code] = true;
|
window_data->key_status[key_code] = true;
|
||||||
kCall(keyboard_func, key_code, window_data->mod_keys, true);
|
kCall(keyboard_func, key_code, window_data->mod_keys, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
- (void)keyUp:(NSEvent *)event
|
- (void)keyUp:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
if(window_data != 0x0) {
|
||||||
short int key_code = g_keycodes[[event keyCode] & 0x1ff];
|
short int key_code = g_keycodes[[event keyCode] & 0x1ff];
|
||||||
window_data->key_status[key_code] = false;
|
window_data->key_status[key_code] = false;
|
||||||
kCall(keyboard_func, key_code, window_data->mod_keys, false);
|
kCall(keyboard_func, key_code, window_data->mod_keys, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
- (void)insertText:(id)string replacementRange:(NSRange)replacementRange
|
- (void)insertText:(id)string replacementRange:(NSRange)replacementRange
|
||||||
{
|
{
|
||||||
|
kUnused(replacementRange);
|
||||||
|
|
||||||
|
if(window_data != 0x0) {
|
||||||
NSString *characters;
|
NSString *characters;
|
||||||
NSUInteger length;
|
NSUInteger length;
|
||||||
|
|
||||||
kUnused(replacementRange);
|
|
||||||
|
|
||||||
if ([string isKindOfClass:[NSAttributedString class]])
|
if ([string isKindOfClass:[NSAttributedString class]])
|
||||||
characters = [string string];
|
characters = [string string];
|
||||||
else
|
else
|
||||||
@ -173,6 +181,7 @@
|
|||||||
kCall(char_input_func, code);
|
kCall(char_input_func, code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -180,20 +189,22 @@
|
|||||||
{
|
{
|
||||||
kUnused(notification);
|
kUnused(notification);
|
||||||
|
|
||||||
|
if(window_data != 0x0) {
|
||||||
if(window_data->is_active == true) {
|
if(window_data->is_active == true) {
|
||||||
window_data->is_active = false;
|
window_data->is_active = false;
|
||||||
kCall(active_func, false);
|
kCall(active_func, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
- (void)setContentView:(NSView *)aView
|
- (void)setContentView:(NSView *)aView
|
||||||
{
|
{
|
||||||
if ([childContentView isEqualTo:aView])
|
if ([childContentView isEqualTo:aView]) {
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSRect bounds = [self frame];
|
NSRect bounds = [self frame];
|
||||||
bounds.origin = NSZeroPoint;
|
bounds.origin = NSZeroPoint;
|
||||||
|
|
||||||
@ -232,16 +243,20 @@
|
|||||||
- (void)windowDidBecomeKey:(NSNotification *)notification
|
- (void)windowDidBecomeKey:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
kUnused(notification);
|
kUnused(notification);
|
||||||
|
if(window_data != 0x0) {
|
||||||
window_data->is_active = true;
|
window_data->is_active = true;
|
||||||
kCall(active_func, true);
|
kCall(active_func, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)windowDidResignKey:(NSNotification *)notification
|
- (void)windowDidResignKey:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
kUnused(notification);
|
kUnused(notification);
|
||||||
|
if(window_data) {
|
||||||
window_data->is_active = false;
|
window_data->is_active = false;
|
||||||
kCall(active_func, false);
|
kCall(active_func, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)windowWillClose:(NSNotification *)notification {
|
- (void)windowWillClose:(NSNotification *)notification {
|
||||||
kUnused(notification);
|
kUnused(notification);
|
||||||
@ -277,13 +292,16 @@
|
|||||||
|
|
||||||
- (void)willClose
|
- (void)willClose
|
||||||
{
|
{
|
||||||
|
if(window_data != 0x0) {
|
||||||
window_data->close = true;
|
window_data->close = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
- (void)windowDidResize:(NSNotification *)notification {
|
- (void)windowDidResize:(NSNotification *)notification {
|
||||||
kUnused(notification);
|
kUnused(notification);
|
||||||
|
if(window_data != 0x0) {
|
||||||
CGSize size = [self contentRectForFrameRect:[self frame]].size;
|
CGSize size = [self contentRectForFrameRect:[self frame]].size;
|
||||||
|
|
||||||
window_data->window_width = size.width;
|
window_data->window_width = size.width;
|
||||||
@ -291,5 +309,6 @@
|
|||||||
|
|
||||||
kCall(resize_func, size.width, size.height);
|
kCall(resize_func, size.width, size.height);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -16,12 +16,9 @@ enum { MaxBuffersInFlight = 3 };
|
|||||||
|
|
||||||
@interface WindowViewController : NSViewController<MTKViewDelegate>
|
@interface WindowViewController : NSViewController<MTKViewDelegate>
|
||||||
{
|
{
|
||||||
@public id<MTLTexture> m_texture_buffers[MaxBuffersInFlight];
|
@public id<MTLTexture> texture_buffers[MaxBuffersInFlight];
|
||||||
@public int m_current_buffer;
|
@public int current_buffer;
|
||||||
@public void *m_draw_buffer;
|
@public dispatch_semaphore_t semaphore; // Used for syncing with CPU/GPU
|
||||||
@public int m_width;
|
|
||||||
@public int m_height;
|
|
||||||
@public dispatch_semaphore_t m_semaphore; // Used for syncing with CPU/GPU
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@ -33,7 +30,7 @@ enum { MaxBuffersInFlight = 3 };
|
|||||||
{
|
{
|
||||||
@public SWindowData *window_data;
|
@public SWindowData *window_data;
|
||||||
#if defined(USE_METAL_API)
|
#if defined(USE_METAL_API)
|
||||||
@private NSTrackingArea* trackingArea;
|
@private NSTrackingArea *tracking_area;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,23 +21,23 @@ extern Vertex g_vertices[4];
|
|||||||
|
|
||||||
- (void) drawInMTKView:(nonnull MTKView *)view {
|
- (void) drawInMTKView:(nonnull MTKView *)view {
|
||||||
OSXWindow *window = (OSXWindow *) view.window;
|
OSXWindow *window = (OSXWindow *) view.window;
|
||||||
if(window->window_data == 0x0) {
|
SWindowData *window_data = window->window_data;
|
||||||
|
if(window_data == 0x0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait to ensure only MaxBuffersInFlight number of frames are getting proccessed
|
// Wait to ensure only MaxBuffersInFlight number of frames are getting proccessed
|
||||||
// by any stage in the Metal pipeline (App, Metal, Drivers, GPU, etc)
|
// by any stage in the Metal pipeline (App, Metal, Drivers, GPU, etc)
|
||||||
dispatch_semaphore_wait(m_semaphore, DISPATCH_TIME_FOREVER);
|
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
|
||||||
|
|
||||||
// Iterate through our Metal buffers, and cycle back to the first when we've written to MaxBuffersInFlight
|
// Iterate through our Metal buffers, and cycle back to the first when we've written to MaxBuffersInFlight
|
||||||
m_current_buffer = (m_current_buffer + 1) % MaxBuffersInFlight;
|
current_buffer = (current_buffer + 1) % MaxBuffersInFlight;
|
||||||
|
|
||||||
// Calculate the number of bytes per row of our image.
|
// Calculate the number of bytes per row of our image.
|
||||||
NSUInteger bytesPerRow = 4 * m_width;
|
MTLRegion region = { { 0, 0, 0 }, { window_data->buffer_width, window_data->buffer_height, 1 } };
|
||||||
MTLRegion region = { { 0, 0, 0 }, { m_width, m_height, 1 } };
|
|
||||||
|
|
||||||
// Copy the bytes from our data object into the texture
|
// Copy the bytes from our data object into the texture
|
||||||
[m_texture_buffers[m_current_buffer] replaceRegion:region mipmapLevel:0 withBytes:m_draw_buffer bytesPerRow:bytesPerRow];
|
[texture_buffers[current_buffer] replaceRegion:region mipmapLevel:0 withBytes:window_data->draw_buffer bytesPerRow:window_data->buffer_stride];
|
||||||
|
|
||||||
// Create a new command buffer for each render pass to the current drawable
|
// Create a new command buffer for each render pass to the current drawable
|
||||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window->window_data->specific;
|
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window->window_data->specific;
|
||||||
@ -49,7 +49,7 @@ extern Vertex g_vertices[4];
|
|||||||
// dynamic buffers filled with our vertices, that we're writing to this frame, will no longer
|
// dynamic buffers filled with our vertices, that we're writing to this frame, will no longer
|
||||||
// be needed by Metal and the GPU, meaning we can overwrite the buffer contents without
|
// be needed by Metal and the GPU, meaning we can overwrite the buffer contents without
|
||||||
// corrupting the rendering.
|
// corrupting the rendering.
|
||||||
__block dispatch_semaphore_t block_sema = m_semaphore;
|
__block dispatch_semaphore_t block_sema = semaphore;
|
||||||
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> buffer)
|
[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> buffer)
|
||||||
{
|
{
|
||||||
(void)buffer;
|
(void)buffer;
|
||||||
@ -71,7 +71,7 @@ extern Vertex g_vertices[4];
|
|||||||
|
|
||||||
[renderEncoder setVertexBytes:g_vertices length:sizeof(g_vertices) atIndex:0];
|
[renderEncoder setVertexBytes:g_vertices length:sizeof(g_vertices) atIndex:0];
|
||||||
|
|
||||||
[renderEncoder setFragmentTexture:m_texture_buffers[m_current_buffer] atIndex:0];
|
[renderEncoder setFragmentTexture:texture_buffers[current_buffer] atIndex:0];
|
||||||
|
|
||||||
// Draw the vertices of our quads
|
// Draw the vertices of our quads
|
||||||
[renderEncoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
|
[renderEncoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
|
||||||
@ -97,17 +97,17 @@ extern Vertex g_vertices[4];
|
|||||||
|
|
||||||
- (void)updateTrackingAreas
|
- (void)updateTrackingAreas
|
||||||
{
|
{
|
||||||
if(trackingArea != nil) {
|
if(tracking_area != nil) {
|
||||||
[self removeTrackingArea:trackingArea];
|
[self removeTrackingArea:tracking_area];
|
||||||
[trackingArea release];
|
[tracking_area release];
|
||||||
}
|
}
|
||||||
|
|
||||||
int opts = (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways);
|
int opts = (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways);
|
||||||
trackingArea = [ [NSTrackingArea alloc] initWithRect:[self bounds]
|
tracking_area = [[NSTrackingArea alloc] initWithRect:[self bounds]
|
||||||
options:opts
|
options:opts
|
||||||
owner:self
|
owner:self
|
||||||
userInfo:nil];
|
userInfo:nil];
|
||||||
[self addTrackingArea:trackingArea];
|
[self addTrackingArea:tracking_area];
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -136,7 +136,7 @@ extern Vertex g_vertices[4];
|
|||||||
{
|
{
|
||||||
(void)rect;
|
(void)rect;
|
||||||
|
|
||||||
if(!window_data)
|
if(window_data == 0x0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
|
||||||
@ -181,55 +181,69 @@ extern Vertex g_vertices[4];
|
|||||||
- (void)mouseDown:(NSEvent*)event
|
- (void)mouseDown:(NSEvent*)event
|
||||||
{
|
{
|
||||||
(void)event;
|
(void)event;
|
||||||
|
if(window_data != 0x0) {
|
||||||
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, true);
|
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
- (void)mouseUp:(NSEvent*)event
|
- (void)mouseUp:(NSEvent*)event
|
||||||
{
|
{
|
||||||
(void)event;
|
(void)event;
|
||||||
|
if(window_data != 0x0) {
|
||||||
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, false);
|
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
- (void)rightMouseDown:(NSEvent*)event
|
- (void)rightMouseDown:(NSEvent*)event
|
||||||
{
|
{
|
||||||
(void)event;
|
(void)event;
|
||||||
|
if(window_data != 0x0) {
|
||||||
kCall(mouse_btn_func, MOUSE_BTN_2, window_data->mod_keys, true);
|
kCall(mouse_btn_func, MOUSE_BTN_2, window_data->mod_keys, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
- (void)rightMouseUp:(NSEvent*)event
|
- (void)rightMouseUp:(NSEvent*)event
|
||||||
{
|
{
|
||||||
(void)event;
|
(void)event;
|
||||||
|
if(window_data != 0x0) {
|
||||||
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, false);
|
kCall(mouse_btn_func, MOUSE_BTN_1, window_data->mod_keys, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
- (void)otherMouseDown:(NSEvent *)event
|
- (void)otherMouseDown:(NSEvent *)event
|
||||||
{
|
{
|
||||||
(void)event;
|
(void)event;
|
||||||
|
if(window_data != 0x0) {
|
||||||
kCall(mouse_btn_func, [event buttonNumber], window_data->mod_keys, true);
|
kCall(mouse_btn_func, [event buttonNumber], window_data->mod_keys, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
- (void)otherMouseUp:(NSEvent *)event
|
- (void)otherMouseUp:(NSEvent *)event
|
||||||
{
|
{
|
||||||
(void)event;
|
(void)event;
|
||||||
|
if(window_data != 0x0) {
|
||||||
kCall(mouse_btn_func, [event buttonNumber], window_data->mod_keys, false);
|
kCall(mouse_btn_func, [event buttonNumber], window_data->mod_keys, false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
- (void)scrollWheel:(NSEvent *)event
|
- (void)scrollWheel:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
if(window_data != 0x0) {
|
||||||
kCall(mouse_wheel_func, window_data->mod_keys, [event deltaX], [event deltaY]);
|
kCall(mouse_wheel_func, window_data->mod_keys, [event deltaX], [event deltaY]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -250,12 +264,14 @@ extern Vertex g_vertices[4];
|
|||||||
|
|
||||||
- (void)mouseMoved:(NSEvent *)event
|
- (void)mouseMoved:(NSEvent *)event
|
||||||
{
|
{
|
||||||
|
if(window_data != 0x0) {
|
||||||
NSPoint point = [event locationInWindow];
|
NSPoint point = [event locationInWindow];
|
||||||
//NSPoint localPoint = [self convertPoint:point fromView:nil];
|
//NSPoint localPoint = [self convertPoint:point fromView:nil];
|
||||||
window_data->mouse_pos_x = point.x;
|
window_data->mouse_pos_x = point.x;
|
||||||
window_data->mouse_pos_y = point.y;
|
window_data->mouse_pos_y = point.y;
|
||||||
kCall(mouse_move_func, point.x, point.y);
|
kCall(mouse_move_func, point.x, point.y);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -107,6 +107,7 @@ main()
|
|||||||
mfb_set_mouse_scroll_callback(window_a, mouse_scroll);
|
mfb_set_mouse_scroll_callback(window_a, mouse_scroll);
|
||||||
|
|
||||||
mfb_set_user_data(window_a, (void *) "Window A");
|
mfb_set_user_data(window_a, (void *) "Window A");
|
||||||
|
mfb_set_viewport(window_a, 25, 25, WIDTH_A-25, HEIGHT_A-25);
|
||||||
|
|
||||||
//--
|
//--
|
||||||
struct mfb_window *window_b = mfb_open_ex("Secondary Window", WIDTH_B, HEIGHT_B, WF_RESIZABLE);
|
struct mfb_window *window_b = mfb_open_ex("Secondary Window", WIDTH_B, HEIGHT_B, WF_RESIZABLE);
|
||||||
@ -150,6 +151,7 @@ main()
|
|||||||
|
|
||||||
mfb_update_state state_a, state_b;
|
mfb_update_state state_a, state_b;
|
||||||
|
|
||||||
|
if(window_a != 0x0) {
|
||||||
for (i = 0; i < WIDTH_A * HEIGHT_A; ++i)
|
for (i = 0; i < WIDTH_A * HEIGHT_A; ++i)
|
||||||
{
|
{
|
||||||
noise = seed;
|
noise = seed;
|
||||||
@ -164,6 +166,14 @@ main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--
|
//--
|
||||||
|
state_a = mfb_update(window_a, g_buffer_a);
|
||||||
|
if (state_a != STATE_OK) {
|
||||||
|
window_a = 0x0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--
|
||||||
|
if(window_b != 0x0) {
|
||||||
time_x = sinf(time * kPI / 180.0f);
|
time_x = sinf(time * kPI / 180.0f);
|
||||||
time_y = cosf(time * kPI / 180.0f);
|
time_y = cosf(time * kPI / 180.0f);
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -178,27 +188,28 @@ main()
|
|||||||
}
|
}
|
||||||
time += 0.1f;
|
time += 0.1f;
|
||||||
|
|
||||||
//--
|
|
||||||
state_a = mfb_update(window_a, g_buffer_a);
|
|
||||||
if (state_a != STATE_OK) {
|
|
||||||
window_a = 0x0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--
|
//--
|
||||||
state_b = mfb_update(window_b, g_buffer_b);
|
state_b = mfb_update(window_b, g_buffer_b);
|
||||||
if (state_b != STATE_OK) {
|
if (state_b != STATE_OK) {
|
||||||
window_b = 0x0;
|
window_b = 0x0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(window_a == 0x0 && window_b == 0x0) {
|
if(window_a == 0x0 && window_b == 0x0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't need to do this for both windows in the same thread
|
// Don't need to do this for both windows in the same thread
|
||||||
if(window_a != 0x0)
|
if(window_a != 0x0) {
|
||||||
mfb_wait_sync(window_a);
|
if(mfb_wait_sync(window_a) == false) {
|
||||||
else if(window_b != 0x0)
|
window_a = 0x0;
|
||||||
mfb_wait_sync(window_b);
|
}
|
||||||
|
}
|
||||||
|
else if(window_b != 0x0) {
|
||||||
|
if(mfb_wait_sync(window_b) == false) {
|
||||||
|
window_b = 0x0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user