'support' dpi scaling, sorta

main
Patrick Cleavelin 2024-03-20 19:05:38 -05:00
parent 6b94f0dbde
commit 6e0d5d58d2
3 changed files with 15 additions and 3 deletions

View File

@ -44,6 +44,7 @@ vs_main(
float2 scaled_size = ((vertices[vertex_id].position + 1.0) / 2.0) * (glyph.size/2.0);
float2 scaled_size_2 = ((vertices[vertex_id].position + 1.0) / 2.0) * (glyph.size);
float2 glyph_pos = scaled_size + glyph.target_position + float2(0, glyph.y_offset/2.0+32);
float4 device_position = to_device_position(glyph_pos, params.screen_size);
float2 atlas_position = (scaled_size_2 + glyph.atlas_position) / 1024.0;

View File

@ -92,7 +92,9 @@ static void _metal_gfx_send_events(_metal_gfx_context *cx);
_gfx_context.frame_width = _gfx_context.backend.window.contentView.frame.size.width;
_gfx_context.frame_height = _gfx_context.backend.window.contentView.frame.size.height;
[_gfx_context.backend.metal_layer setDrawableSize:CGSizeMake(_gfx_context.frame_width, _gfx_context.frame_height)];
CGFloat scale = _gfx_context.backend.metal_layer.contentsScale;
[_gfx_context.backend.metal_layer setDrawableSize:CGSizeMake(_gfx_context.frame_width * scale, _gfx_context.frame_height * scale)];
_metal_gfx_present(&_gfx_context.backend);
}
@ -161,6 +163,9 @@ static _metal_gfx_context _metal_gfx_init_context(uint32_t width, uint32_t heigh
metal_layer.needsDisplayOnBoundsChange = YES;
metal_layer.presentsWithTransaction = YES;
metal_layer.autoresizingMask = kCALayerWidthSizable|kCALayerHeightSizable;
// TODO: set this to the display dpi scale
metal_layer.contentsScale = 2.0;
view.wantsLayer = YES;
[view.layer addSublayer:metal_layer];
view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay;
@ -191,6 +196,12 @@ static _metal_gfx_context _metal_gfx_init_context(uint32_t width, uint32_t heigh
[pipeline_descriptor setVertexFunction:vertex_func];
[pipeline_descriptor setFragmentFunction:fragment_func];
pipeline_descriptor.colorAttachments[0].pixelFormat = MTLPixelFormatRGBA8Unorm;
pipeline_descriptor.colorAttachments[0].alphaBlendOperation = MTLBlendOperationAdd;
pipeline_descriptor.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha;
pipeline_descriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
pipeline_descriptor.colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;
pipeline_descriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
pipeline_descriptor.colorAttachments[0].blendingEnabled = true;
NSError *pipeline_error = NULL;
array(_MTLRenderPipelineState) pipelines = newArray(_MTLRenderPipelineState, 2);

View File

@ -126,7 +126,7 @@ void ed_init(_gfx_frame_func frame_func) {
// manually add glyph for SPACE
pushArray(GpuGlyph, &state.glyph_cache, ((GpuGlyph){
.atlas_position = { 0 },
.size = { rasterized_font_height/4, rasterized_font_height },
.size = { rasterized_font_height/4, 1 },
.position = { 0 },
.y_offset = -rasterized_font_height,
}));
@ -178,7 +178,7 @@ void ed_frame() {
ui_compute_layout(&state.ui_cx, 0);
state.gpu_glyphs.size = 0;
for (size_t i = 0; i < state.ui_cx.frame_elements.size; ++i) {
for (size_t i = 1; i < state.ui_cx.frame_elements.size; ++i) {
string text = state.ui_cx.frame_elements.data[i].key;
ui_element_frame_data *elm = &state.ui_cx.frame_elements.data[i];