Renamed text overlay class to avoid collision with base class

This commit is contained in:
saschawillems 2016-05-15 13:33:57 +02:00
parent 33915ac557
commit 5f80f49153
2 changed files with 19 additions and 15 deletions

View file

@ -61,6 +61,8 @@ static void draw_string_float(float x, float y, char *str) // draw with top-left
} }
*/ */
#pragma once
#ifndef STB_FONTCHAR__TYPEDEF #ifndef STB_FONTCHAR__TYPEDEF
#define STB_FONTCHAR__TYPEDEF #define STB_FONTCHAR__TYPEDEF
typedef struct typedef struct

View file

@ -21,6 +21,7 @@
#include <glm/gtc/matrix_inverse.hpp> #include <glm/gtc/matrix_inverse.hpp>
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "vulkanexamplebase.h" #include "vulkanexamplebase.h"
#include "../external/stb/stb_font_consolas_24_latin1.inl" #include "../external/stb/stb_font_consolas_24_latin1.inl"
@ -49,8 +50,7 @@ std::vector<vkMeshLoader::VertexLayout> vertexLayout =
#define MAX_CHAR_COUNT 2048 #define MAX_CHAR_COUNT 2048
// Mostly self-contained text overlay class // Mostly self-contained text overlay class
// todo : comment class TextOverlay
class VulkanTextOverlay
{ {
private: private:
VkPhysicalDevice physicalDevice; VkPhysicalDevice physicalDevice;
@ -108,7 +108,7 @@ public:
bool visible = true; bool visible = true;
VulkanTextOverlay( TextOverlay(
VkPhysicalDevice physicalDevice, VkPhysicalDevice physicalDevice,
VkDevice device, VkDevice device,
VkQueue queue, VkQueue queue,
@ -143,7 +143,7 @@ public:
preparePipeline(); preparePipeline();
} }
~VulkanTextOverlay() ~TextOverlay()
{ {
// Free up all Vulkan resources requested by the text overlay // Free up all Vulkan resources requested by the text overlay
vkDestroySampler(device, sampler, nullptr); vkDestroySampler(device, sampler, nullptr);
@ -695,7 +695,7 @@ public:
class VulkanExample : public VulkanExampleBase class VulkanExample : public VulkanExampleBase
{ {
public: public:
VulkanTextOverlay *textOverlay = nullptr; TextOverlay *textOverlay = nullptr;
struct { struct {
vkTools::VulkanTexture background; vkTools::VulkanTexture background;
@ -742,6 +742,8 @@ public:
zoomSpeed = 2.5f; zoomSpeed = 2.5f;
rotation = { -25.0f, 0.0f, 0.0f }; rotation = { -25.0f, 0.0f, 0.0f };
title = "Vulkan Example - Text overlay"; title = "Vulkan Example - Text overlay";
// Disable text overlay of the example base class
enableTextOverlay = false;
} }
~VulkanExample() ~VulkanExample()
@ -817,15 +819,15 @@ public:
{ {
textOverlay->beginTextUpdate(); textOverlay->beginTextUpdate();
textOverlay->addText(title, 5.0f, 5.0f, VulkanTextOverlay::alignLeft); textOverlay->addText(title, 5.0f, 5.0f, TextOverlay::alignLeft);
std::stringstream ss; std::stringstream ss;
ss << std::fixed << std::setprecision(2) << (frameTimer * 1000.0f) << "ms (" << lastFPS << " fps)"; ss << std::fixed << std::setprecision(2) << (frameTimer * 1000.0f) << "ms (" << lastFPS << " fps)";
textOverlay->addText(ss.str(), 5.0f, 25.0f, VulkanTextOverlay::alignLeft); textOverlay->addText(ss.str(), 5.0f, 25.0f, TextOverlay::alignLeft);
textOverlay->addText(deviceProperties.deviceName, 5.0f, 45.0f, VulkanTextOverlay::alignLeft); textOverlay->addText(deviceProperties.deviceName, 5.0f, 45.0f, TextOverlay::alignLeft);
textOverlay->addText("Press \"space\" to toggle text overlay", 5.0f, height - 20.0f, VulkanTextOverlay::alignLeft); textOverlay->addText("Press \"space\" to toggle text overlay", 5.0f, height - 20.0f, TextOverlay::alignLeft);
// Display projected cube vertices // Display projected cube vertices
for (int32_t x = -1; x <= 1; x += 2) for (int32_t x = -1; x <= 1; x += 2)
@ -837,29 +839,29 @@ public:
std::stringstream vpos; std::stringstream vpos;
vpos << std::showpos << x << "/" << y << "/" << z; vpos << std::showpos << x << "/" << y << "/" << z;
glm::vec3 projected = glm::project(glm::vec3((float)x, (float)y, (float)z), uboVS.model, uboVS.projection, glm::vec4(0, 0, (float)width, (float)height)); glm::vec3 projected = glm::project(glm::vec3((float)x, (float)y, (float)z), uboVS.model, uboVS.projection, glm::vec4(0, 0, (float)width, (float)height));
textOverlay->addText(vpos.str(), projected.x, projected.y + (y > -1 ? 5.0f : -20.0f), VulkanTextOverlay::alignCenter); textOverlay->addText(vpos.str(), projected.x, projected.y + (y > -1 ? 5.0f : -20.0f), TextOverlay::alignCenter);
} }
} }
} }
// Display current model view matrix // Display current model view matrix
textOverlay->addText("model view matrix", width, 5.0f, VulkanTextOverlay::alignRight); textOverlay->addText("model view matrix", width, 5.0f, TextOverlay::alignRight);
for (uint32_t i = 0; i < 4; i++) for (uint32_t i = 0; i < 4; i++)
{ {
ss.str(""); ss.str("");
ss << std::fixed << std::setprecision(2) << std::showpos; ss << std::fixed << std::setprecision(2) << std::showpos;
ss << uboVS.model[0][i] << " " << uboVS.model[1][i] << " " << uboVS.model[2][i] << " " << uboVS.model[3][i]; ss << uboVS.model[0][i] << " " << uboVS.model[1][i] << " " << uboVS.model[2][i] << " " << uboVS.model[3][i];
textOverlay->addText(ss.str(), width, 25.0f + (float)i * 20.0f, VulkanTextOverlay::alignRight); textOverlay->addText(ss.str(), width, 25.0f + (float)i * 20.0f, TextOverlay::alignRight);
} }
glm::vec3 projected = glm::project(glm::vec3(0.0f), uboVS.model, uboVS.projection, glm::vec4(0, 0, (float)width, (float)height)); glm::vec3 projected = glm::project(glm::vec3(0.0f), uboVS.model, uboVS.projection, glm::vec4(0, 0, (float)width, (float)height));
textOverlay->addText("Uniform cube", projected.x, projected.y, VulkanTextOverlay::alignCenter); textOverlay->addText("Uniform cube", projected.x, projected.y, TextOverlay::alignCenter);
#if defined(__ANDROID__) #if defined(__ANDROID__)
// toto // toto
#else #else
textOverlay->addText("Hold middle mouse button and drag to move", 5.0f, height - 40.0f, VulkanTextOverlay::alignLeft); textOverlay->addText("Hold middle mouse button and drag to move", 5.0f, height - 40.0f, TextOverlay::alignLeft);
#endif #endif
textOverlay->endTextUpdate(); textOverlay->endTextUpdate();
} }
@ -1167,7 +1169,7 @@ public:
shaderStages.push_back(loadShader(getAssetPath() + "shaders/textoverlay/text.vert.spv", VK_SHADER_STAGE_VERTEX_BIT)); shaderStages.push_back(loadShader(getAssetPath() + "shaders/textoverlay/text.vert.spv", VK_SHADER_STAGE_VERTEX_BIT));
shaderStages.push_back(loadShader(getAssetPath() + "shaders/textoverlay/text.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT)); shaderStages.push_back(loadShader(getAssetPath() + "shaders/textoverlay/text.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT));
textOverlay = new VulkanTextOverlay( textOverlay = new TextOverlay(
physicalDevice, physicalDevice,
device, device,
queue, queue,