update_ex working on iOS
This commit is contained in:
parent
f4c537d6f0
commit
5f9594cb23
@ -4,10 +4,13 @@
|
||||
#include <WindowData.h>
|
||||
#include <MetalKit/MetalKit.h>
|
||||
|
||||
@class iOSViewDelegate;
|
||||
|
||||
typedef struct Vertex {
|
||||
float x, y, z, w;
|
||||
} Vertex;
|
||||
|
||||
typedef struct {
|
||||
Vertex vertices[4];
|
||||
iOSViewDelegate *view_delegate;
|
||||
Vertex vertices[4];
|
||||
} SWindowData_IOS;
|
||||
|
@ -150,6 +150,17 @@ mfb_update_ex(struct mfb_window *window, void *buffer, unsigned width, unsigned
|
||||
return STATE_INVALID_BUFFER;
|
||||
}
|
||||
|
||||
SWindowData_IOS *window_data_ios = (SWindowData_IOS *) window_data->specific;
|
||||
|
||||
if(window_data->buffer_width != width || window_data->buffer_height != height) {
|
||||
window_data->buffer_width = width;
|
||||
window_data->buffer_stride = width * 4;
|
||||
window_data->buffer_height = height;
|
||||
window_data->draw_buffer = realloc(window_data->draw_buffer, window_data->buffer_stride * window_data->buffer_height);
|
||||
|
||||
[window_data_ios->view_delegate resizeTextures];
|
||||
}
|
||||
|
||||
memcpy(window_data->draw_buffer, buffer, window_data->buffer_width * window_data->buffer_height * 4);
|
||||
|
||||
return STATE_OK;
|
||||
|
@ -17,7 +17,7 @@
|
||||
@implementation iOSViewController
|
||||
{
|
||||
iOSView *metal_view;
|
||||
iOSViewDelegate *view_delegate;
|
||||
//iOSViewDelegate *view_delegate;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
@ -60,10 +60,11 @@
|
||||
return;
|
||||
}
|
||||
|
||||
view_delegate = [[iOSViewDelegate alloc] initWithMetalKitView:metal_view windowData:window_data];
|
||||
[view_delegate mtkView:metal_view drawableSizeWillChange:metal_view.bounds.size];
|
||||
SWindowData_IOS *window_data_ios = (SWindowData_IOS *) window_data->specific;
|
||||
window_data_ios->view_delegate = [[iOSViewDelegate alloc] initWithMetalKitView:metal_view windowData:window_data];
|
||||
[window_data_ios->view_delegate mtkView:metal_view drawableSizeWillChange:metal_view.bounds.size];
|
||||
|
||||
metal_view.delegate = view_delegate;
|
||||
metal_view.delegate = window_data_ios->view_delegate;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -17,6 +17,7 @@
|
||||
}
|
||||
|
||||
-(nonnull instancetype) initWithMetalKitView:(nonnull MTKView *) view windowData:(nonnull SWindowData *) windowData;
|
||||
- (void) resizeTextures;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -167,6 +167,19 @@ NSString *g_shader_src = kShader(
|
||||
texture_buffer = [metal_device newTextureWithDescriptor:td];
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
- (void) resizeTextures {
|
||||
MTLTextureDescriptor *td;
|
||||
td = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
|
||||
width:window_data->buffer_width
|
||||
height:window_data->buffer_height
|
||||
mipmapped:false];
|
||||
|
||||
// Create the texture from the device by using the descriptor
|
||||
[texture_buffer release];
|
||||
texture_buffer = [metal_device newTextureWithDescriptor:td];
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
- (void) drawInMTKView:(nonnull MTKView *) view {
|
||||
// Wait to ensure only MaxBuffersInFlight number of frames are getting proccessed
|
||||
|
@ -74,7 +74,7 @@ resize(struct mfb_window *window, int width, int height) {
|
||||
}
|
||||
}
|
||||
|
||||
mfb_update_state state = mfb_update(g_window, g_buffer);
|
||||
mfb_update_state state = mfb_update_ex(g_window, g_buffer, g_width, g_height);
|
||||
if (state != STATE_OK) {
|
||||
free(g_buffer);
|
||||
g_buffer = 0x0;
|
||||
|
Loading…
Reference in New Issue
Block a user