mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
draw a square, handle resize
This commit is contained in:
@ -174,7 +174,7 @@ pub fn init(alloc: Allocator, font_group: *font.GroupCache) !Metal {
|
||||
};
|
||||
const func_vert = func_vert: {
|
||||
const str = try macos.foundation.String.createWithBytes(
|
||||
"demo_vertex",
|
||||
"basic_vertex",
|
||||
.utf8,
|
||||
false,
|
||||
);
|
||||
@ -336,6 +336,10 @@ pub fn render(
|
||||
const pool = objc_autoreleasePoolPush();
|
||||
defer objc_autoreleasePoolPop(pool);
|
||||
|
||||
// Ensure our layer size is always updated
|
||||
const bounds = self.swapchain.getProperty(macos.graphics.Rect, "bounds");
|
||||
self.swapchain.setProperty("drawableSize", bounds.size);
|
||||
|
||||
// Get our surface (CAMetalDrawable)
|
||||
const surface = self.swapchain.msgSend(objc.Object, objc.sel("nextDrawable"), .{});
|
||||
|
||||
@ -383,6 +387,9 @@ pub fn render(
|
||||
);
|
||||
defer encoder.msgSend(void, objc.sel("endEncoding"), .{});
|
||||
|
||||
//do we need to do this?
|
||||
//encoder.msgSend(void, objc.sel("setViewport:"), .{viewport});
|
||||
|
||||
// Use our shader pipeline
|
||||
encoder.msgSend(void, objc.sel("setRenderPipelineState:"), .{self.pipeline.value});
|
||||
|
||||
@ -394,29 +401,29 @@ pub fn render(
|
||||
);
|
||||
|
||||
// Draw
|
||||
encoder.msgSend(
|
||||
void,
|
||||
objc.sel("drawPrimitives:vertexStart:vertexCount:instanceCount:"),
|
||||
.{
|
||||
@enumToInt(MTLPrimitiveType.triangle),
|
||||
@as(c_ulong, 0),
|
||||
@as(c_ulong, 3),
|
||||
@as(c_ulong, 1),
|
||||
},
|
||||
);
|
||||
|
||||
// encoder.msgSend(
|
||||
// void,
|
||||
// objc.sel("drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:"),
|
||||
// objc.sel("drawPrimitives:vertexStart:vertexCount:instanceCount:"),
|
||||
// .{
|
||||
// @enumToInt(MTLPrimitiveType.triangle),
|
||||
// @as(c_ulong, 6),
|
||||
// @enumToInt(MTLIndexType.uint16),
|
||||
// self.buf_instance.value,
|
||||
// @as(c_ulong, 0),
|
||||
// @as(c_ulong, 3),
|
||||
// @as(c_ulong, 1),
|
||||
// },
|
||||
// );
|
||||
|
||||
encoder.msgSend(
|
||||
void,
|
||||
objc.sel("drawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:"),
|
||||
.{
|
||||
@enumToInt(MTLPrimitiveType.triangle),
|
||||
@as(c_ulong, 6),
|
||||
@enumToInt(MTLIndexType.uint16),
|
||||
self.buf_instance.value,
|
||||
@as(c_ulong, 0),
|
||||
@as(c_ulong, 1),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
buffer.msgSend(void, objc.sel("presentDrawable:"), .{surface.value});
|
||||
|
@ -26,17 +26,11 @@ vertex float4 basic_vertex(unsigned int vid [[ vertex_id ]]) {
|
||||
// Calculate the final position of our cell in world space.
|
||||
// We have to add our cell size since our vertices are offset
|
||||
// one cell up and to the left. (Do the math to verify yourself)
|
||||
cell_pos = cell_size * position;
|
||||
cell_pos = cell_pos + cell_size * position;
|
||||
|
||||
return float4(cell_pos.x, cell_pos.y, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
vertex float4 demo_vertex(
|
||||
const device packed_float3* vertex_array [[ buffer(0) ]],
|
||||
unsigned int vid [[ vertex_id ]]) {
|
||||
return float4(vertex_array[vid], 1.0);
|
||||
}
|
||||
|
||||
fragment half4 basic_fragment() {
|
||||
return half4(1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user