Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Std explicit #62

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BaseEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/BaseEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've changed this here, as the base engine should be agnostic of its final rendering backend - and GLuint inserts a dependency to OpenGL.

virtual unsigned int loadTextureImage2D(unsigned char * pixels, int width, int height);

static const char* getClipboardString();
static void setClipboardString(const char * text);
Expand Down
1 change: 1 addition & 0 deletions src/BaseTheme.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "BaseTheme.h"

#include "imgui.h"
using namespace std;

namespace ofxImGui
{
Expand Down
2 changes: 1 addition & 1 deletion src/BaseTheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
122 changes: 94 additions & 28 deletions src/EngineVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
#include "vk/DrawCommand.h"
#include <glm/glm.hpp>

// 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<of::vk::ImageAllocator> EngineVk::mImageAllocator;
std::shared_ptr<of::vk::Texture> 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

Expand All @@ -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<ofVkRenderer>( ofGetCurrentRenderer() );
mDevice = mRenderer->getVkDevice();

Expand Down Expand Up @@ -100,8 +102,8 @@ namespace ofxImGui
allocatorSettings.physicalDeviceMemoryProperties = rendererProperties.physicalDeviceMemoryProperties;
allocatorSettings.physicalDeviceProperties = rendererProperties.physicalDeviceProperties;

mImageAllocator = std::make_unique<of::vk::ImageAllocator>( allocatorSettings );
mImageAllocator->setup();
mImageAllocator = std::make_unique<of::vk::ImageAllocator>( );
mImageAllocator->setup(allocatorSettings);
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -259,17 +261,78 @@ 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~";


//--------------------------------------------------------------

void EngineVk::createDrawCommands(){

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<of::vk::Shader::VertexInfo>();

Expand Down Expand Up @@ -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<of::vk::Shader>( shaderSettings );

Expand Down Expand Up @@ -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;
}
Expand All @@ -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<of::vk::Texture>( mRenderer->getVkDevice(), samplerInfo , imageViewCreateInfo);
mFontTexture.setup(textureSettings);

// Store our identifier
io.Fonts->TexID = (void *)( mFontTexture.get());
io.Fonts->TexID = (void *)( &mFontTexture );

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EngineVk.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace ofxImGui
static ::of::vk::RenderBatch* batch; // Current batch used for drawing
static std::unique_ptr<of::vk::ImageAllocator> mImageAllocator; // Allocator used for font texture
static std::shared_ptr<::vk::Image> mFontImage; // Data store for image data
static std::shared_ptr<of::vk::Texture> mFontTexture; // Wrapper with sampler around font texture
static of::vk::Texture mFontTexture; // Wrapper with sampler around font texture
static std::unique_ptr<of::vk::DrawCommand> mDrawCommand; // Used to draw ImGui components

void createDrawCommands();
Expand Down
3 changes: 3 additions & 0 deletions src/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace ofxImGui
{

using namespace std;

//--------------------------------------------------------------
Gui::Gui()
: lastTime(0.0f)
Expand Down
10 changes: 5 additions & 5 deletions src/Gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ofTexture*> loadedTextures;
std::vector<ofTexture*> loadedTextures;
};
}
10 changes: 6 additions & 4 deletions src/Helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "Helpers.h"

using namespace std;

//--------------------------------------------------------------
ofxImGui::Settings::Settings()
: windowPos(kImGuiMargin, kImGuiMargin)
Expand All @@ -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 += " ";
Expand Down Expand Up @@ -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<std::string>());
windowOpen.usedNames.push(vector<string>());

ImGui::SetNextWindowPos(settings.windowPos, ImGuiSetCond_Appearing);
ImGui::SetNextWindowSize(settings.windowSize, ImGuiSetCond_Appearing);
Expand All @@ -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<std::string>());
windowOpen.usedNames.push(vector<string>());

ImGui::SetNextWindowPos(settings.windowPos, ImGuiSetCond_Appearing);
ImGui::SetNextWindowSize(settings.windowSize, ImGuiSetCond_Appearing);
Expand Down Expand Up @@ -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<std::string>());
windowOpen.usedNames.push(vector<string>());
}
return result;
}
Expand Down
42 changes: 21 additions & 21 deletions src/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ofxImGui
struct WindowOpen
{
std::stack<std::vector<std::string>> usedNames;
shared_ptr<ofParameter<bool>> parameter;
std::shared_ptr<ofParameter<bool>> parameter;
bool value;
};

Expand All @@ -37,12 +37,12 @@ namespace ofxImGui

void SetNextWindow(Settings& settings);
bool BeginWindow(ofParameter<bool>& 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);
Expand All @@ -66,33 +66,33 @@ namespace ofxImGui
template<typename ParameterType>
bool AddParameter(ofParameter<ParameterType>& parameter);

bool AddRadio(ofParameter<int>& parameter, vector<string> labels, int columns = 1);
bool AddRadio(ofParameter<int>& parameter, std::vector<std::string> labels, int columns = 1);
bool AddStepper(ofParameter<int>& parameter, int step = 1, int stepFast = 100);

bool AddRange(const string& name, ofParameter<int>& parameterMin, ofParameter<int>& parameterMax, int speed = 1);
bool AddRange(const string& name, ofParameter<float>& parameterMin, ofParameter<float>& parameterMax, float speed = 0.01f);
bool AddRange(const std::string& name, ofParameter<int>& parameterMin, ofParameter<int>& parameterMax, int speed = 1);
bool AddRange(const std::string& name, ofParameter<float>& parameterMin, ofParameter<float>& parameterMax, float speed = 0.01f);
#if OF_VERSION_MINOR >= 10
bool AddRange(const string& name, ofParameter<glm::vec2>& parameterMin, ofParameter<glm::vec2>& parameterMax, float speed = 0.01f);
bool AddRange(const string& name, ofParameter<glm::vec3>& parameterMin, ofParameter<glm::vec3>& parameterMax, float speed = 0.01f);
bool AddRange(const string& name, ofParameter<glm::vec4>& parameterMin, ofParameter<glm::vec4>& parameterMax, float speed = 0.01f);
bool AddRange(const std::string& name, ofParameter<glm::vec2>& parameterMin, ofParameter<glm::vec2>& parameterMax, float speed = 0.01f);
bool AddRange(const std::string& name, ofParameter<glm::vec3>& parameterMin, ofParameter<glm::vec3>& parameterMax, float speed = 0.01f);
bool AddRange(const std::string& name, ofParameter<glm::vec4>& parameterMin, ofParameter<glm::vec4>& parameterMax, float speed = 0.01f);
#endif

#if OF_VERSION_MINOR >= 10
bool AddValues(const string& name, vector<glm::ivec2>& values, int minValue, int maxValue);
bool AddValues(const string& name, vector<glm::ivec3>& values, int minValue, int maxValue);
bool AddValues(const string& name, vector<glm::ivec4>& values, int minValue, int maxValue);
bool AddValues(const std::string& name, std::vector<glm::ivec2>& values, int minValue, int maxValue);
bool AddValues(const std::string& name, std::vector<glm::ivec3>& values, int minValue, int maxValue);
bool AddValues(const std::string& name, std::vector<glm::ivec4>& values, int minValue, int maxValue);

bool AddValues(const string& name, vector<glm::vec2>& values, float minValue, float maxValue);
bool AddValues(const string& name, vector<glm::vec3>& values, float minValue, float maxValue);
bool AddValues(const string& name, vector<glm::vec4>& values, float minValue, float maxValue);
bool AddValues(const std::string& name, std::vector<glm::vec2>& values, float minValue, float maxValue);
bool AddValues(const std::string& name, std::vector<glm::vec3>& values, float minValue, float maxValue);
bool AddValues(const std::string& name, std::vector<glm::vec4>& values, float minValue, float maxValue);
#endif

bool AddValues(const string& name, vector<ofVec2f>& values, float minValue, float maxValue);
bool AddValues(const string& name, vector<ofVec3f>& values, float minValue, float maxValue);
bool AddValues(const string& name, vector<ofVec4f>& values, float minValue, float maxValue);
bool AddValues(const std::string& name, std::vector<ofVec2f>& values, float minValue, float maxValue);
bool AddValues(const std::string& name, std::vector<ofVec3f>& values, float minValue, float maxValue);
bool AddValues(const std::string& name, std::vector<ofVec4f>& values, float minValue, float maxValue);

template<typename DataType>
bool AddValues(const string& name, vector<DataType>& values, DataType minValue, DataType maxValue);
bool AddValues(const std::string& name, std::vector<DataType>& values, DataType minValue, DataType maxValue);

void AddImage(ofBaseHasTexture& hasTexture, const ofVec2f& size);
void AddImage(ofTexture& texture, const ofVec2f& size);
Expand Down Expand Up @@ -143,7 +143,7 @@ bool ofxImGui::AddParameter(ofParameter<ParameterType>& parameter)

//--------------------------------------------------------------
template<typename DataType>
bool ofxImGui::AddValues(const string& name, vector<DataType>& values, DataType minValue, DataType maxValue)
bool ofxImGui::AddValues(const std::string& name, std::vector<DataType>& values, DataType minValue, DataType maxValue)
{
auto result = false;
const auto& info = typeid(DataType);
Expand Down
Loading