Merge branch 'master' into ios_support

This commit is contained in:
Carlos Aragones 2020-04-26 19:52:13 +02:00
commit 6a96ceb1f5
5 changed files with 25 additions and 23 deletions

View File

@ -21,13 +21,6 @@ void init_keycodes();
id<MTLDevice> g_metal_device = nil; id<MTLDevice> g_metal_device = nil;
id<MTLLibrary> g_library = nil; id<MTLLibrary> g_library = nil;
Vertex g_vertices[4] = {
{-1.0, -1.0, 0, 1},
{-1.0, 1.0, 0, 1},
{ 1.0, -1.0, 0, 1},
{ 1.0, 1.0, 0, 1},
};
//------------------------------------- //-------------------------------------
#define kShader(inc, src) @inc#src #define kShader(inc, src) @inc#src
@ -185,6 +178,14 @@ mfb_open_ex(const char *title, unsigned width, unsigned height, unsigned flags)
if (!window_data->draw_buffer) if (!window_data->draw_buffer)
return 0x0; return 0x0;
static Vertex s_vertices[4] = {
{-1.0, -1.0, 0, 1},
{-1.0, 1.0, 0, 1},
{ 1.0, -1.0, 0, 1},
{ 1.0, 1.0, 0, 1},
};
memcpy(window_data_osx->metal.vertices, s_vertices, sizeof(s_vertices));
// Setup command queue // Setup command queue
window_data_osx->metal.command_queue = [g_metal_device newCommandQueue]; window_data_osx->metal.command_queue = [g_metal_device newCommandQueue];
@ -431,17 +432,19 @@ mfb_set_viewport(struct mfb_window *window, unsigned offset_x, unsigned offset_y
float y1 = ((float) offset_y / window_data->window_height) * 2.0f - 1.0f; float y1 = ((float) offset_y / window_data->window_height) * 2.0f - 1.0f;
float y2 = (((float) offset_y + height) / window_data->window_height) * 2.0f - 1.0f; float y2 = (((float) offset_y + height) / window_data->window_height) * 2.0f - 1.0f;
g_vertices[0].x = x1; SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window_data->specific;
g_vertices[0].y = y1;
g_vertices[1].x = x1; window_data_osx->metal.vertices[0].x = x1;
g_vertices[1].y = y2; window_data_osx->metal.vertices[0].y = y1;
g_vertices[2].x = x2; window_data_osx->metal.vertices[1].x = x1;
g_vertices[2].y = y1; window_data_osx->metal.vertices[1].y = y2;
g_vertices[3].x = x2; window_data_osx->metal.vertices[2].x = x2;
g_vertices[3].y = y2; window_data_osx->metal.vertices[2].y = y1;
window_data_osx->metal.vertices[3].x = x2;
window_data_osx->metal.vertices[3].y = y2;
#endif #endif
return true; return true;

View File

@ -5,10 +5,6 @@
#if defined(USE_METAL_API) #if defined(USE_METAL_API)
#import <MetalKit/MetalKit.h> #import <MetalKit/MetalKit.h>
typedef struct Vertex {
float x, y, z, w;
} Vertex;
// Number of textures in flight (tripple buffered) // Number of textures in flight (tripple buffered)
enum { MaxBuffersInFlight = 3 }; enum { MaxBuffersInFlight = 3 };

View File

@ -9,8 +9,6 @@
extern id<MTLDevice> g_metal_device; extern id<MTLDevice> g_metal_device;
extern id<MTLLibrary> g_library; extern id<MTLLibrary> g_library;
extern Vertex g_vertices[4];
@implementation WindowViewController @implementation WindowViewController
- (void) mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size { - (void) mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size {
@ -69,7 +67,7 @@ extern Vertex g_vertices[4];
SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window->window_data->specific; SWindowData_OSX *window_data_osx = (SWindowData_OSX *) window->window_data->specific;
[renderEncoder setRenderPipelineState:window_data_osx->metal.pipeline_state]; [renderEncoder setRenderPipelineState:window_data_osx->metal.pipeline_state];
[renderEncoder setVertexBytes:g_vertices length:sizeof(g_vertices) atIndex:0]; [renderEncoder setVertexBytes:window_data_osx->metal.vertices length:sizeof(window_data_osx->metal.vertices) atIndex:0];
[renderEncoder setFragmentTexture:texture_buffers[current_buffer] atIndex:0]; [renderEncoder setFragmentTexture:texture_buffers[current_buffer] atIndex:0];

View File

@ -9,6 +9,10 @@
@class OSXWindow; @class OSXWindow;
typedef struct Vertex {
float x, y, z, w;
} Vertex;
typedef struct { typedef struct {
OSXWindow *window; OSXWindow *window;
struct mfb_timer *timer; struct mfb_timer *timer;
@ -17,6 +21,7 @@ typedef struct {
struct { struct {
id<MTLCommandQueue> command_queue; id<MTLCommandQueue> command_queue;
id<MTLRenderPipelineState> pipeline_state; id<MTLRenderPipelineState> pipeline_state;
Vertex vertices[4];
} metal; } metal;
#endif #endif
} SWindowData_OSX; } SWindowData_OSX;

View File

@ -107,7 +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); mfb_set_viewport(window_a, 25, 25, WIDTH_A-50, HEIGHT_A-50);
//-- //--
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);