diff --git a/src/BaseEngine.cpp b/src/BaseEngine.cpp index 5675e62..84f863a 100644 --- a/src/BaseEngine.cpp +++ b/src/BaseEngine.cpp @@ -77,7 +77,7 @@ namespace ofxImGui } //-------------------------------------------------------------- - GLuint BaseEngine::loadTextureImage2D(unsigned char * pixels, int width, int height) + unsigned int BaseEngine::loadTextureImage2D(unsigned char * pixels, int width, int height) { GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); diff --git a/src/BaseEngine.h b/src/BaseEngine.h index df1e7a9..d2219a1 100644 --- a/src/BaseEngine.h +++ b/src/BaseEngine.h @@ -29,7 +29,7 @@ namespace ofxImGui virtual void onKeyReleased(ofKeyEventArgs& event) = 0; virtual void onWindowResized(ofResizeEventArgs& window); - virtual GLuint loadTextureImage2D(unsigned char * pixels, int width, int height); + virtual unsigned int loadTextureImage2D(unsigned char * pixels, int width, int height); static const char* getClipboardString(); static void setClipboardString(const char * text); diff --git a/src/BaseTheme.cpp b/src/BaseTheme.cpp index 15e0730..16a207a 100644 --- a/src/BaseTheme.cpp +++ b/src/BaseTheme.cpp @@ -1,6 +1,7 @@ #include "BaseTheme.h" #include "imgui.h" +using namespace std; namespace ofxImGui { diff --git a/src/BaseTheme.h b/src/BaseTheme.h index bf10ba9..d0670c5 100644 --- a/src/BaseTheme.h +++ b/src/BaseTheme.h @@ -22,7 +22,7 @@ namespace ofxImGui ofColor col_win_popup; ofColor col_win_backg; - bool addColorEdit(string label, ofColor& color); + bool addColorEdit( std::string label, ofColor& color); ofColor convertColor(float* f); }; } diff --git a/src/EngineVk.cpp b/src/EngineVk.cpp index a714b59..9cc6107 100644 --- a/src/EngineVk.cpp +++ b/src/EngineVk.cpp @@ -12,16 +12,15 @@ #include "vk/DrawCommand.h" #include -// We keep a shared pointer to the renderer so we don't have to -// fetch it anew every time we need it. - namespace ofxImGui { + using namespace std; + ::of::vk::RenderBatch* EngineVk::batch = nullptr; // current renderbatch std::unique_ptr EngineVk::mImageAllocator; - std::shared_ptr EngineVk::mFontTexture; // wrapper with sampler around font texture + of::vk::Texture EngineVk::mFontTexture; // wrapper with sampler around font texture std::shared_ptr<::vk::Image> EngineVk::mFontImage; // data store for image data ::vk::Device EngineVk::mDevice; // non-owning reference to vk device @@ -37,6 +36,9 @@ namespace ofxImGui { if (isSetup) return; + // We keep a shared pointer to the renderer so we don't have to + // fetch it anew every time we need it. + mRenderer = dynamic_pointer_cast( ofGetCurrentRenderer() ); mDevice = mRenderer->getVkDevice(); @@ -100,8 +102,8 @@ namespace ofxImGui allocatorSettings.physicalDeviceMemoryProperties = rendererProperties.physicalDeviceMemoryProperties; allocatorSettings.physicalDeviceProperties = rendererProperties.physicalDeviceProperties; - mImageAllocator = std::make_unique( allocatorSettings ); - mImageAllocator->setup(); + mImageAllocator = std::make_unique( ); + mImageAllocator->setup(allocatorSettings); } } @@ -177,7 +179,7 @@ namespace ofxImGui return; draw_data->ScaleClipRects(io.DisplayFramebufferScale); - auto & alloc = batch->getContext()->getTransientAllocator(); + auto & alloc = batch->getContext()->getAllocator(); ::vk::DeviceSize offset = 0; void * dataP = nullptr; @@ -259,6 +261,64 @@ namespace ofxImGui io.AddInputCharacter((unsigned short)event.codepoint); } } + + +static const std::string cImGuiFragmentShaderSource = R"~glsl~( +#version 450 core + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +layout (set = 0, binding = 1) uniform sampler2D tex_unit_0; + +// inputs +layout (location = 0) in vec4 inColor; +layout (location = 1) in vec2 inTexCoord; + +// outputs +layout (location = 0) out vec4 outFragColor; + +void main(){ + outFragColor = inColor * texture( tex_unit_0, inTexCoord.st); +} +)~glsl~"; + +static const std::string cImGuiVertexShaderSource = R"~glsl~( +#version 450 core + +#extension GL_ARB_separate_shader_objects : enable +#extension GL_ARB_shading_language_420pack : enable + +// uniforms (resources) +layout (set = 0, binding = 0) uniform DefaultMatrices +{ + mat4 modelViewProjectionMatrix; +}; + +// inputs (vertex attributes) +layout (location = 0) in vec2 inPos; +layout (location = 1) in vec2 inTexCoord; +layout (location = 2) in vec4 inColor; + +// outputs +layout (location = 0) out vec4 outColor; +layout (location = 1) out vec2 outTexCoord; + +// we override the built-in fixed function outputs +// to have more control over the SPIR-V code created. +out gl_PerVertex +{ + vec4 gl_Position; +}; + +void main() +{ + outTexCoord = inTexCoord; + outColor = inColor; + gl_Position = modelViewProjectionMatrix * vec4(inPos,0,1); +} +)~glsl~"; + //-------------------------------------------------------------- @@ -266,10 +326,13 @@ namespace ofxImGui of::vk::Shader::Settings shaderSettings; - shaderSettings.device = mDevice; - shaderSettings.printDebugInfo = true; - shaderSettings.sources[::vk::ShaderStageFlagBits::eVertex] = "imgui.vert"; - shaderSettings.sources[::vk::ShaderStageFlagBits::eFragment] = "imgui.frag"; + shaderSettings + .setDevice(mDevice) + .setPrintDebugInfo( false ) + .setSource( ::vk::ShaderStageFlagBits::eVertex, cImGuiVertexShaderSource ) + .setSource( ::vk::ShaderStageFlagBits::eFragment, cImGuiFragmentShaderSource ) + .setName("imGui default shader") + ; auto vertexInfo = std::make_shared(); @@ -301,7 +364,7 @@ namespace ofxImGui vertexInfo->bindingDescription = { { 0, sizeof( ImDrawVert ), ::vk::VertexInputRate::eVertex } }; // by setting vertexInfo like this we prevent the shader from reflecting - shaderSettings.vertexInfo = vertexInfo; + shaderSettings.vertexInfo = std::move(vertexInfo); auto imGuiShader = std::make_shared( shaderSettings ); @@ -345,7 +408,7 @@ namespace ofxImGui createFontsTexture(); createDrawCommands(); // attach font texture to draw command - mDrawCommand->setTexture( "tex_unit_0", *mFontTexture ); + mDrawCommand->setTexture( "tex_unit_0", mFontTexture ); return true; } @@ -368,28 +431,31 @@ namespace ofxImGui imgData.extent.width = width; imgData.extent.height = height; - mFontImage = mRenderer->getStagingContext()->storeImageCmd( imgData, mImageAllocator ); + mFontImage = mRenderer->getStagingContext()->storeImageCmd( imgData, *mImageAllocator ); - ::vk::SamplerCreateInfo samplerInfo = of::vk::Texture::getDefaultSamplerCreateInfo(); + of::vk::Texture::Settings textureSettings; - samplerInfo - .setMagFilter( ::vk::Filter::eLinear ) - .setMinFilter( ::vk::Filter::eLinear ) - .setMipmapMode( ::vk::SamplerMipmapMode::eLinear ) - .setMinLod( -1000 ) - .setMaxLod( 1000 ) - .setMaxAnisotropy( 1.0f ) - .setAddressModeU( ::vk::SamplerAddressMode::eRepeat ) - .setAddressModeV( ::vk::SamplerAddressMode::eRepeat ) - .setAddressModeW( ::vk::SamplerAddressMode::eRepeat ) + textureSettings + .setDevice(mDevice) + .setImage(*mFontImage) ; - auto imageViewCreateInfo = of::vk::Texture::getDefaultImageViewCreateInfo(*mFontImage); + textureSettings.samplerInfo + .setMagFilter(::vk::Filter::eLinear) + .setMinFilter(::vk::Filter::eLinear) + .setMipmapMode(::vk::SamplerMipmapMode::eLinear) + .setMinLod(-1000) + .setMaxLod(1000) + .setMaxAnisotropy(1.0f) + .setAddressModeU(::vk::SamplerAddressMode::eRepeat) + .setAddressModeV(::vk::SamplerAddressMode::eRepeat) + .setAddressModeW(::vk::SamplerAddressMode::eRepeat) + ; - mFontTexture = std::make_shared( mRenderer->getVkDevice(), samplerInfo , imageViewCreateInfo); + mFontTexture.setup(textureSettings); // Store our identifier - io.Fonts->TexID = (void *)( mFontTexture.get()); + io.Fonts->TexID = (void *)( &mFontTexture ); return true; } diff --git a/src/EngineVk.h b/src/EngineVk.h index 3a2a8b3..8b673ef 100644 --- a/src/EngineVk.h +++ b/src/EngineVk.h @@ -54,7 +54,7 @@ namespace ofxImGui static ::of::vk::RenderBatch* batch; // Current batch used for drawing static std::unique_ptr mImageAllocator; // Allocator used for font texture static std::shared_ptr<::vk::Image> mFontImage; // Data store for image data - static std::shared_ptr mFontTexture; // Wrapper with sampler around font texture + static of::vk::Texture mFontTexture; // Wrapper with sampler around font texture static std::unique_ptr mDrawCommand; // Used to draw ImGui components void createDrawCommands(); diff --git a/src/Gui.cpp b/src/Gui.cpp index 1951d46..6f63389 100644 --- a/src/Gui.cpp +++ b/src/Gui.cpp @@ -12,6 +12,9 @@ namespace ofxImGui { + + using namespace std; + //-------------------------------------------------------------- Gui::Gui() : lastTime(0.0f) diff --git a/src/Gui.h b/src/Gui.h index 9cb84c7..9e7c9e2 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -29,14 +29,14 @@ namespace ofxImGui BaseTheme* theme; GLuint loadImage(ofImage& image); - GLuint loadImage(string imagePath); + GLuint loadImage( std::string imagePath); - GLuint loadPixels(string imagePath); + GLuint loadPixels( std::string imagePath); GLuint loadPixels(ofPixels& pixels); - GLuint loadTexture(string imagePath); - GLuint loadTexture(ofTexture& texture, string imagePath); + GLuint loadTexture( std::string imagePath); + GLuint loadTexture(ofTexture& texture, std::string imagePath); - vector loadedTextures; + std::vector loadedTextures; }; } diff --git a/src/Helpers.cpp b/src/Helpers.cpp index 6c68545..b224665 100644 --- a/src/Helpers.cpp +++ b/src/Helpers.cpp @@ -1,5 +1,7 @@ #include "Helpers.h" +using namespace std; + //-------------------------------------------------------------- ofxImGui::Settings::Settings() : windowPos(kImGuiMargin, kImGuiMargin) @@ -18,7 +20,7 @@ const char * ofxImGui::GetUniqueName(ofAbstractParameter& parameter) //-------------------------------------------------------------- const char * ofxImGui::GetUniqueName(const std::string& candidate) { - std::string result = candidate; + string result = candidate; while (std::find(windowOpen.usedNames.top().begin(), windowOpen.usedNames.top().end(), result) != windowOpen.usedNames.top().end()) { result += " "; @@ -64,7 +66,7 @@ bool ofxImGui::BeginWindow(const string& name, Settings& settings, bool collapse settings.windowBlock = true; // Push a new list of names onto the stack. - windowOpen.usedNames.push(std::vector()); + windowOpen.usedNames.push(vector()); ImGui::SetNextWindowPos(settings.windowPos, ImGuiSetCond_Appearing); ImGui::SetNextWindowSize(settings.windowSize, ImGuiSetCond_Appearing); @@ -84,7 +86,7 @@ bool ofxImGui::BeginWindow(const string& name, Settings& settings, ImGuiWindowFl settings.windowBlock = true; // Push a new list of names onto the stack. - windowOpen.usedNames.push(std::vector()); + windowOpen.usedNames.push(vector()); ImGui::SetNextWindowPos(settings.windowPos, ImGuiSetCond_Appearing); ImGui::SetNextWindowSize(settings.windowSize, ImGuiSetCond_Appearing); @@ -152,7 +154,7 @@ bool ofxImGui::BeginTree(const string& name, Settings& settings) settings.treeLevel += 1; // Push a new list of names onto the stack. - windowOpen.usedNames.push(std::vector()); + windowOpen.usedNames.push(vector()); } return result; } diff --git a/src/Helpers.h b/src/Helpers.h index a21735a..b9b6983 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -12,7 +12,7 @@ namespace ofxImGui struct WindowOpen { std::stack> usedNames; - shared_ptr> parameter; + std::shared_ptr> parameter; bool value; }; @@ -37,12 +37,12 @@ namespace ofxImGui void SetNextWindow(Settings& settings); bool BeginWindow(ofParameter& parameter, Settings& settings, bool collapse = true); - bool BeginWindow(const string& name, Settings& settings, bool collapse = true, bool * open = nullptr); - bool BeginWindow(const string& name, Settings& settings, ImGuiWindowFlags flags, bool * open = nullptr); + bool BeginWindow(const std::string& name, Settings& settings, bool collapse = true, bool * open = nullptr); + bool BeginWindow(const std::string& name, Settings& settings, ImGuiWindowFlags flags, bool * open = nullptr); void EndWindow(Settings& settings); bool BeginTree(ofAbstractParameter& parameter, Settings& settings); - bool BeginTree(const string& name, Settings& settings); + bool BeginTree(const std::string& name, Settings& settings); void EndTree(Settings& settings); void AddGroup(ofParameterGroup& group, Settings& settings); @@ -66,33 +66,33 @@ namespace ofxImGui template bool AddParameter(ofParameter& parameter); - bool AddRadio(ofParameter& parameter, vector labels, int columns = 1); + bool AddRadio(ofParameter& parameter, std::vector labels, int columns = 1); bool AddStepper(ofParameter& parameter, int step = 1, int stepFast = 100); - bool AddRange(const string& name, ofParameter& parameterMin, ofParameter& parameterMax, int speed = 1); - bool AddRange(const string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); + bool AddRange(const std::string& name, ofParameter& parameterMin, ofParameter& parameterMax, int speed = 1); + bool AddRange(const std::string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); #if OF_VERSION_MINOR >= 10 - bool AddRange(const string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); - bool AddRange(const string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); - bool AddRange(const string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); + bool AddRange(const std::string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); + bool AddRange(const std::string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); + bool AddRange(const std::string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); #endif #if OF_VERSION_MINOR >= 10 - bool AddValues(const string& name, vector& values, int minValue, int maxValue); - bool AddValues(const string& name, vector& values, int minValue, int maxValue); - bool AddValues(const string& name, vector& values, int minValue, int maxValue); + bool AddValues(const std::string& name, std::vector& values, int minValue, int maxValue); + bool AddValues(const std::string& name, std::vector& values, int minValue, int maxValue); + bool AddValues(const std::string& name, std::vector& values, int minValue, int maxValue); - bool AddValues(const string& name, vector& values, float minValue, float maxValue); - bool AddValues(const string& name, vector& values, float minValue, float maxValue); - bool AddValues(const string& name, vector& values, float minValue, float maxValue); + bool AddValues(const std::string& name, std::vector& values, float minValue, float maxValue); + bool AddValues(const std::string& name, std::vector& values, float minValue, float maxValue); + bool AddValues(const std::string& name, std::vector& values, float minValue, float maxValue); #endif - bool AddValues(const string& name, vector& values, float minValue, float maxValue); - bool AddValues(const string& name, vector& values, float minValue, float maxValue); - bool AddValues(const string& name, vector& values, float minValue, float maxValue); + bool AddValues(const std::string& name, std::vector& values, float minValue, float maxValue); + bool AddValues(const std::string& name, std::vector& values, float minValue, float maxValue); + bool AddValues(const std::string& name, std::vector& values, float minValue, float maxValue); template - bool AddValues(const string& name, vector& values, DataType minValue, DataType maxValue); + bool AddValues(const std::string& name, std::vector& values, DataType minValue, DataType maxValue); void AddImage(ofBaseHasTexture& hasTexture, const ofVec2f& size); void AddImage(ofTexture& texture, const ofVec2f& size); @@ -143,7 +143,7 @@ bool ofxImGui::AddParameter(ofParameter& parameter) //-------------------------------------------------------------- template -bool ofxImGui::AddValues(const string& name, vector& values, DataType minValue, DataType maxValue) +bool ofxImGui::AddValues(const std::string& name, std::vector& values, DataType minValue, DataType maxValue) { auto result = false; const auto& info = typeid(DataType); diff --git a/src/ofxImGuiLoggerChannel.cpp b/src/ofxImGuiLoggerChannel.cpp index 46d1cb2..9549e77 100644 --- a/src/ofxImGuiLoggerChannel.cpp +++ b/src/ofxImGuiLoggerChannel.cpp @@ -1,5 +1,7 @@ #include "ofxImGuiLoggerChannel.h" +using namespace std; + //-------------------------------------------------------------- ImGuiTextBuffer& ofxImGui::LoggerChannel::getBuffer(){ diff --git a/src/ofxImGuiLoggerChannel.h b/src/ofxImGuiLoggerChannel.h index 2d6eb4c..cc47e5e 100644 --- a/src/ofxImGuiLoggerChannel.h +++ b/src/ofxImGuiLoggerChannel.h @@ -14,9 +14,9 @@ class LoggerChannel : public ofBaseLoggerChannel /// \brief Destroy the console logger channel. virtual ~LoggerChannel(){}; - void log( ofLogLevel level, const string & module, const string & message ); - void log( ofLogLevel level, const string & module, const char* format, ... ) OF_PRINTF_ATTR( 4, 5 ); - void log( ofLogLevel level, const string & module, const char* format, va_list args ); + void log( ofLogLevel level, const std::string & module, const std::string & message ); + void log( ofLogLevel level, const std::string & module, const char* format, ... ) OF_PRINTF_ATTR( 4, 5 ); + void log( ofLogLevel level, const std::string & module, const char* format, std::va_list args ); }; } // end namespace ofxImGui