added cursor to vulkan

This commit is contained in:
KojoZero 2026-04-24 13:27:49 -07:00
parent e489fac61b
commit f83e60243e
3 changed files with 45 additions and 4 deletions

View file

@ -7,7 +7,7 @@
layout (location = 0) in vec2 frag_tex_coord;
layout (location = 0) out vec4 color;
layout (location = 1) in vec2 pixelUnit;
layout (push_constant, std140) uniform DrawInfo {
mat4 modelview_matrix;
vec4 i_resolution;
@ -22,6 +22,7 @@ layout (push_constant, std140) uniform DrawInfo {
layout (set = 0, binding = 0) uniform sampler2D screen_textures[3];
vec4 GetScreen(int screen_id) {
#ifdef ARRAY_DYNAMIC_INDEX
return texture(screen_textures[screen_id], frag_tex_coord);
@ -38,5 +39,42 @@ vec4 GetScreen(int screen_id) {
}
void main() {
color = GetScreen(screen_id_l);
vec4 pixel = GetScreen(screen_id_l);
vec2 rfrag_tex_coord = vec2(frag_tex_coord.y, 1.0 - frag_tex_coord.x);
//Cursor
if (cursor_enable == 1){
//Black Outline
if (rfrag_tex_coord.x <= (cursor_pos.x + (2.0*pixelUnit.x)) &&
rfrag_tex_coord.x >= (cursor_pos.x - (1.0*pixelUnit.x))) {
if (rfrag_tex_coord.y <= (cursor_pos.y + (5.0*pixelUnit.y)) &&
rfrag_tex_coord.y >= (cursor_pos.y - (4.0*pixelUnit.y))) {
pixel = vec4(0.0, 0.0, 0.0, 1.0);
}
}
if (rfrag_tex_coord.y <= (cursor_pos.y + (2.0*pixelUnit.y)) &&
rfrag_tex_coord.y >= (cursor_pos.y - (1.0*pixelUnit.y))) {
if (rfrag_tex_coord.x <= (cursor_pos.x + (5.0*pixelUnit.x)) &&
rfrag_tex_coord.x >= (cursor_pos.x - (4.0*pixelUnit.x))) {
pixel = vec4(0.0, 0.0, 0.0, 1.0);
}
}
//White Cross
if (rfrag_tex_coord.x <= (cursor_pos.x + (1.0*pixelUnit.x)) &&
rfrag_tex_coord.x >= (cursor_pos.x - (0.0*pixelUnit.x))) {
if (rfrag_tex_coord.y <= (cursor_pos.y + (4.0*pixelUnit.y)) &&
rfrag_tex_coord.y >= (cursor_pos.y - (3.0*pixelUnit.y))) {
pixel = vec4(1.0, 1.0, 1.0, 1.0);
}
}
if (rfrag_tex_coord.y <= (cursor_pos.y + (1.0*pixelUnit.y)) &&
rfrag_tex_coord.y >= (cursor_pos.y - (0.0*pixelUnit.y))) {
if (rfrag_tex_coord.x <= (cursor_pos.x + (4.0*pixelUnit.x)) &&
rfrag_tex_coord.x >= (cursor_pos.x - (3.0*pixelUnit.x))) {
pixel = vec4(1.0, 1.0, 1.0, 1.0);
}
}
}
color = vec4(pixel.rgb, 1.0);
}

View file

@ -8,7 +8,7 @@
layout (location = 0) in vec2 vert_position;
layout (location = 1) in vec2 vert_tex_coord;
layout (location = 0) out vec2 frag_tex_coord;
layout (location = 1) out vec2 pixelUnit;
layout (push_constant, std140) uniform DrawInfo {
mat4 modelview_matrix;
vec4 i_resolution;
@ -24,4 +24,6 @@ void main() {
vec4 position = vec4(vert_position, 0.0, 1.0) * modelview_matrix;
gl_Position = vec4(position.x, position.y, 0.0, 1.0);
frag_tex_coord = vert_tex_coord;
pixelUnit.x = 1/320.0;
pixelUnit.y = 1/240.0;
}

View file

@ -1020,7 +1020,8 @@ void RendererVulkan::DrawScreens(Frame* frame, const Layout::FramebufferLayout&
if (settings.shader_update_requested.exchange(false)) {
ReloadPipeline(layout.render_3d_mode);
}
cursor_pos[0] += 1;
cursor_pos[1] += 1;
PrepareDraw(frame, layout);
const auto& top_screen = layout.top_screen;