summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-06-12 08:51:08 -0400
committerJonathan Bradley <jcb@pikum.xyz>2025-06-12 08:51:08 -0400
commit61d024686403b7be8d6cbd3cd9c5aeaf39b445af (patch)
tree0c3a6e55e3ea44202df56c482a5cecf09da954b4
parent0f89d12e747b380b35143815a2c8e87c6ee752d4 (diff)
pke: move ui colors to instance buffer
-rw-r--r--assets/shaders/ui-base.vert10
-rw-r--r--src/font.cpp2
-rw-r--r--src/static-ui.cpp4
-rw-r--r--src/window.cpp22
4 files changed, 30 insertions, 8 deletions
diff --git a/assets/shaders/ui-base.vert b/assets/shaders/ui-base.vert
index 458d599..c492a36 100644
--- a/assets/shaders/ui-base.vert
+++ b/assets/shaders/ui-base.vert
@@ -6,8 +6,10 @@ layout(location = 1) in vec2 in_uv;
// instance
layout(location = 2) in mat4 pos_scale;
-layout(location = 6) in vec2 px_scale;
-layout(location = 7) in float depth;
+layout(location = 6) in vec4 in_border_color;
+layout(location = 7) in vec4 in_background_color;
+layout(location = 8) in vec2 px_scale;
+layout(location = 9) in float depth;
layout(location = 0) out vec4 out_border_color;
layout(location = 1) out vec4 out_background_color;
@@ -23,8 +25,8 @@ void main()
{
vec4 transformed_position = pos_scale * vec4(in_position, 0.0, 1.0);
gl_Position = vec4(transformed_position.xy, depth, 1.0);
- out_border_color = vec4(0.8, 0.8, 0.8, 1.0);
- out_background_color = vec4(0.2, 0.3, 0.2, 1.0);
+ out_border_color = in_border_color;
+ out_background_color = in_background_color;
out_px_scale = px_scale;
out_uv = in_uv;
}
diff --git a/src/font.cpp b/src/font.cpp
index 927f806..1c06a06 100644
--- a/src/font.cpp
+++ b/src/font.cpp
@@ -867,7 +867,7 @@ FontRenderHandle FontType_AddStringRender(FontTypeIndex idx_ft, const pk_cstr &&
bufferCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
bufferCI.queueFamilyIndexCount = 1;
bufferCI.pQueueFamilyIndices = &graphicsFamilyIndex;
- bufferCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
+ bufferCI.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
bufferCI.size = byteCount;
vkResult = vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &newBuffer);
assert(vkResult == VK_SUCCESS);
diff --git a/src/static-ui.cpp b/src/static-ui.cpp
index 34887d9..c6b7108 100644
--- a/src/static-ui.cpp
+++ b/src/static-ui.cpp
@@ -19,6 +19,8 @@ TypeSafeInt_B(PKE_UI_BOX_FLAG);
struct pke_ui_box_instance_buffer_item {
glm::mat4 pos_scale;
+ glm::vec4 border_color;
+ glm::vec4 background_color;
glm::vec2 px_scale;
float depth;
float padding[1];
@@ -236,6 +238,8 @@ void pke_ui_calc_px(pk_arr_t<pke_ui_box_instance_buffer_item> &buffer, pke_ui_fl
pke_ui_box_instance_buffer_item tmp{};
tmp.pos_scale = glm::translate(glm::mat4(1), translate);
tmp.pos_scale = glm::scale(tmp.pos_scale, scale);
+ tmp.border_color = glm::vec4(1.0, 0.0, 0.0, 1.0);
+ tmp.background_color = glm::vec4(0.2, 0.3, 0.2, 0.5);
tmp.px_scale.x = (2.0 / (float)Extent.width);
tmp.px_scale.y = (2.0 / (float)Extent.height);
tmp.depth = (float)box->layer;
diff --git a/src/window.cpp b/src/window.cpp
index 1211476..69b06ab 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -253,7 +253,7 @@ void PKVK_BeginBuffer(unsigned int family_index, VkDeviceSize requestedMemorySiz
if (requestedMemorySize == 0) return;
- VkBufferCreateInfo transferBufferCI;
+ VkBufferCreateInfo transferBufferCI{};
transferBufferCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
transferBufferCI.pNext = nullptr;
transferBufferCI.flags = 0;
@@ -305,7 +305,7 @@ void pkvk_buffer_create(pkvk_buffer_create_data *data, pkvk_buffer_create_data_o
* buffer setup
*/
VkBuffer tmpBuffer;
- VkBufferCreateInfo bufferCI;
+ VkBufferCreateInfo bufferCI{};
bufferCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
bufferCI.pNext = nullptr;
bufferCI.flags = {};
@@ -2107,7 +2107,7 @@ void CreateGraphicsPipelines() {
offset = 0;
const long vertexBindingCount_ui_base = 3;
VkVertexInputBindingDescription vertInputBD_ui_base[vertexBindingCount_ui_base];
- const long vertexAttrDescCount_ui_base = 8;
+ const long vertexAttrDescCount_ui_base = 10;
VkVertexInputAttributeDescription vertAttrDesc_ui_base[vertexAttrDescCount_ui_base];
VkPipelineVertexInputStateCreateInfo vkPipelineVertexInputStateCreateInfo_ui_base{vkPipelineVertexInputStateCreateInfo_txtr};
{
@@ -2127,6 +2127,8 @@ void CreateGraphicsPipelines() {
vertInputBD_ui_base[index].binding = index;
vertInputBD_ui_base[index].stride = 0
+ sizeof(glm::mat4) // pos_scale
+ + sizeof(glm::vec4) // in_border_color
+ + sizeof(glm::vec4) // in_background_color
+ sizeof(glm::vec2) // px_scale
+ sizeof(float) // depth
+ (sizeof(float) * 1) // padding
@@ -2160,6 +2162,20 @@ void CreateGraphicsPipelines() {
index += 1;
}
+ // instance - in_border_color
+ vertAttrDesc_ui_base[index].binding = 2;
+ vertAttrDesc_ui_base[index].format = VK_FORMAT_R32G32B32A32_SFLOAT;
+ vertAttrDesc_ui_base[index].offset = offset;
+ offset += sizeof(glm::vec4);
+ index += 1;
+
+ // instance - in_background_color
+ vertAttrDesc_ui_base[index].binding = 2;
+ vertAttrDesc_ui_base[index].format = VK_FORMAT_R32G32B32A32_SFLOAT;
+ vertAttrDesc_ui_base[index].offset = offset;
+ offset += sizeof(glm::vec4);
+ index += 1;
+
// instance - in_sprite_region_min
vertAttrDesc_ui_base[index].binding = 2;
vertAttrDesc_ui_base[index].format = VK_FORMAT_R32G32_SFLOAT;