Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 0e7d394a authored by TAVERNIER Vincent's avatar TAVERNIER Vincent
Browse files

Add default parameter to GetBufferByName

parent 911b156e
No related branches found
No related tags found
No related merge requests found
libshadertoy (0.1.7) unstable; urgency=medium
* Add default parameter for buffer query from context
-- Vincent Tavernier <vincent.tavernier@inria.fr> Thu, 08 Feb 2018 13:15:00 +0200
libshadertoy (0.1.6) unstable; urgency=medium libshadertoy (0.1.6) unstable; urgency=medium
* Add fragment shader execution time query support (iTimeDelta) * Add fragment shader execution time query support (iTimeDelta)
......
...@@ -127,7 +127,7 @@ int parseOptions(string &shaderId, string &shaderApiKey, bool &dump, int argc, c ...@@ -127,7 +127,7 @@ int parseOptions(string &shaderId, string &shaderApiKey, bool &dump, int argc, c
} }
int loadRemote(const string &shaderId, const string &shaderApiKey, int loadRemote(const string &shaderId, const string &shaderApiKey,
shadertoy::ContextConfig &contextConfig, string &imageBufferName) shadertoy::ContextConfig &contextConfig)
{ {
// Init CURL // Init CURL
curl_global_init(CURL_GLOBAL_DEFAULT); curl_global_init(CURL_GLOBAL_DEFAULT);
...@@ -281,9 +281,6 @@ int loadRemote(const string &shaderId, const string &shaderApiKey, ...@@ -281,9 +281,6 @@ int loadRemote(const string &shaderId, const string &shaderApiKey,
pair<string, shadertoy::BufferConfig> imagebuf(*contextConfig.bufferConfigs.begin()); pair<string, shadertoy::BufferConfig> imagebuf(*contextConfig.bufferConfigs.begin());
contextConfig.bufferConfigs.erase(contextConfig.bufferConfigs.begin()); contextConfig.bufferConfigs.erase(contextConfig.bufferConfigs.begin());
contextConfig.bufferConfigs.insert(imagebuf); contextConfig.bufferConfigs.insert(imagebuf);
// Fetch image buffer name
imageBufferName = imagebuf.first;
} }
catch (exception &ex) catch (exception &ex)
{ {
...@@ -298,9 +295,7 @@ int loadRemote(const string &shaderId, const string &shaderApiKey, ...@@ -298,9 +295,7 @@ int loadRemote(const string &shaderId, const string &shaderApiKey,
return code; return code;
} }
int render(GLFWwindow* window, int render(GLFWwindow* window, shadertoy::ContextConfig &contextConfig)
shadertoy::ContextConfig &contextConfig,
const string &imageBufferName)
{ {
int code = 0; int code = 0;
...@@ -388,15 +383,15 @@ int render(GLFWwindow* window, ...@@ -388,15 +383,15 @@ int render(GLFWwindow* window,
context.RenderScreenQuad(); context.RenderScreenQuad();
// Print execution time // Print execution time
auto buffer = context.GetBufferByName(imageBufferName); auto buffer = context.GetBufferByName();
if (buffer) if (buffer)
{ {
auto renderTime = buffer->GetElapsedTime(); auto renderTime = buffer->GetElapsedTime();
std:cerr << imageBufferName << " time: " << renderTime std::cerr << "frame time: " << renderTime
<< "ns fps: " << (1e9 / renderTime) << "ns fps: " << (1e9 / renderTime)
<< " mpx/s: " << (contextConfig.width * contextConfig.height / (renderTime / 1e3)) << " mpx/s: " << (contextConfig.width * contextConfig.height / (renderTime / 1e3))
<< std::endl; << std::endl;
} }
// Buffer swapping // Buffer swapping
...@@ -410,7 +405,7 @@ int render(GLFWwindow* window, ...@@ -410,7 +405,7 @@ int render(GLFWwindow* window,
return code; return code;
} }
int performRender(shadertoy::ContextConfig &contextConfig, const string &imageBufferName) int performRender(shadertoy::ContextConfig &contextConfig)
{ {
int code = 0; int code = 0;
...@@ -437,7 +432,7 @@ int performRender(shadertoy::ContextConfig &contextConfig, const string &imageBu ...@@ -437,7 +432,7 @@ int performRender(shadertoy::ContextConfig &contextConfig, const string &imageBu
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
glfwSwapInterval(1); glfwSwapInterval(1);
code = render(window, contextConfig, imageBufferName); code = render(window, contextConfig);
glfwDestroyWindow(window); glfwDestroyWindow(window);
glfwTerminate(); glfwTerminate();
...@@ -465,13 +460,12 @@ int main(int argc, char *argv[]) ...@@ -465,13 +460,12 @@ int main(int argc, char *argv[])
contextConfig.dumpShaders = dumpShaders; contextConfig.dumpShaders = dumpShaders;
// Fetch shader code // Fetch shader code
string imageBufferName; code = loadRemote(shaderId, shaderApiKey, contextConfig);
code = loadRemote(shaderId, shaderApiKey, contextConfig, imageBufferName);
if (code > 0) if (code > 0)
return code; return code;
// Render // Render
code = performRender(contextConfig, imageBufferName); code = performRender(contextConfig);
return code; return code;
} }
...@@ -256,11 +256,12 @@ public: ...@@ -256,11 +256,12 @@ public:
/** /**
* Obtains the buffer object for the given name. * Obtains the buffer object for the given name.
* *
* @param name Name of the buffer object to obtain * @param name [optional] Name of the buffer object to obtain. If empty,
* returns the image buffer.
* @return Pointer to the buffer object, or a null pointer if no such * @return Pointer to the buffer object, or a null pointer if no such
* buffer exists. * buffer exists.
*/ */
std::shared_ptr<ToyBuffer> GetBufferByName(const std::string &name); std::shared_ptr<ToyBuffer> GetBufferByName(const std::string &name = std::string());
}; };
} }
......
...@@ -398,11 +398,23 @@ OpenGL::Shader &RenderContext::GetScreenQuadVertexShader() ...@@ -398,11 +398,23 @@ OpenGL::Shader &RenderContext::GetScreenQuadVertexShader()
shared_ptr<ToyBuffer> RenderContext::GetBufferByName(const string &name) shared_ptr<ToyBuffer> RenderContext::GetBufferByName(const string &name)
{ {
auto it = buffers.find(name); if (name.empty())
if (it == buffers.end())
{ {
return shared_ptr<ToyBuffer>(); if (buffers.empty())
{
return shared_ptr<ToyBuffer>();
}
return buffers.rbegin()->second;
} }
else
{
auto it = buffers.find(name);
if (it == buffers.end())
{
return shared_ptr<ToyBuffer>();
}
return it->second; return it->second;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment