diff --git a/debian/changelog b/debian/changelog index fc9d8b191e7ed45809a85e83f329599f6cba1628..f6d46e1ea4c6e32e59c917185a174b820852b2e0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +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 * Add fragment shader execution time query support (iTimeDelta) diff --git a/examples/50-shadertoy/main.cpp b/examples/50-shadertoy/main.cpp index dd5a519c44a03e0072a63cb05450f1750cb85642..98a94b77e716f2a89b5e269ca64d4d2e805205c5 100644 --- a/examples/50-shadertoy/main.cpp +++ b/examples/50-shadertoy/main.cpp @@ -127,7 +127,7 @@ int parseOptions(string &shaderId, string &shaderApiKey, bool &dump, int argc, c } int loadRemote(const string &shaderId, const string &shaderApiKey, - shadertoy::ContextConfig &contextConfig, string &imageBufferName) + shadertoy::ContextConfig &contextConfig) { // Init CURL curl_global_init(CURL_GLOBAL_DEFAULT); @@ -281,9 +281,6 @@ int loadRemote(const string &shaderId, const string &shaderApiKey, pair<string, shadertoy::BufferConfig> imagebuf(*contextConfig.bufferConfigs.begin()); contextConfig.bufferConfigs.erase(contextConfig.bufferConfigs.begin()); contextConfig.bufferConfigs.insert(imagebuf); - - // Fetch image buffer name - imageBufferName = imagebuf.first; } catch (exception &ex) { @@ -298,9 +295,7 @@ int loadRemote(const string &shaderId, const string &shaderApiKey, return code; } -int render(GLFWwindow* window, - shadertoy::ContextConfig &contextConfig, - const string &imageBufferName) +int render(GLFWwindow* window, shadertoy::ContextConfig &contextConfig) { int code = 0; @@ -388,15 +383,15 @@ int render(GLFWwindow* window, context.RenderScreenQuad(); // Print execution time - auto buffer = context.GetBufferByName(imageBufferName); + auto buffer = context.GetBufferByName(); if (buffer) { auto renderTime = buffer->GetElapsedTime(); - std:cerr << imageBufferName << " time: " << renderTime - << "ns fps: " << (1e9 / renderTime) - << " mpx/s: " << (contextConfig.width * contextConfig.height / (renderTime / 1e3)) - << std::endl; + std::cerr << "frame time: " << renderTime + << "ns fps: " << (1e9 / renderTime) + << " mpx/s: " << (contextConfig.width * contextConfig.height / (renderTime / 1e3)) + << std::endl; } // Buffer swapping @@ -410,7 +405,7 @@ int render(GLFWwindow* window, return code; } -int performRender(shadertoy::ContextConfig &contextConfig, const string &imageBufferName) +int performRender(shadertoy::ContextConfig &contextConfig) { int code = 0; @@ -437,7 +432,7 @@ int performRender(shadertoy::ContextConfig &contextConfig, const string &imageBu glfwMakeContextCurrent(window); glfwSwapInterval(1); - code = render(window, contextConfig, imageBufferName); + code = render(window, contextConfig); glfwDestroyWindow(window); glfwTerminate(); @@ -465,13 +460,12 @@ int main(int argc, char *argv[]) contextConfig.dumpShaders = dumpShaders; // Fetch shader code - string imageBufferName; - code = loadRemote(shaderId, shaderApiKey, contextConfig, imageBufferName); + code = loadRemote(shaderId, shaderApiKey, contextConfig); if (code > 0) return code; // Render - code = performRender(contextConfig, imageBufferName); + code = performRender(contextConfig); return code; } diff --git a/include/shadertoy/RenderContext.hpp b/include/shadertoy/RenderContext.hpp index b7e79e559a87f453e3a4778e8455cd505ac924cb..92e889cbf2b68789d280bba86e223187f07c3f25 100644 --- a/include/shadertoy/RenderContext.hpp +++ b/include/shadertoy/RenderContext.hpp @@ -256,11 +256,12 @@ public: /** * 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 * buffer exists. */ - std::shared_ptr<ToyBuffer> GetBufferByName(const std::string &name); + std::shared_ptr<ToyBuffer> GetBufferByName(const std::string &name = std::string()); }; } diff --git a/src/RenderContext.cpp b/src/RenderContext.cpp index a637f7316c2fb1dff005c6c860f5c735cc629fd8..9099fffce769e6b79d1d76e55a7035dbedfc66d7 100644 --- a/src/RenderContext.cpp +++ b/src/RenderContext.cpp @@ -398,11 +398,23 @@ OpenGL::Shader &RenderContext::GetScreenQuadVertexShader() shared_ptr<ToyBuffer> RenderContext::GetBufferByName(const string &name) { - auto it = buffers.find(name); - if (it == buffers.end()) + if (name.empty()) { - 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; + } }