├── .gitignore ├── CMakeLists.txt ├── HISTORY.TXT ├── INSTALL.TXT ├── LICENSE.TXT ├── README.md ├── doc ├── Doxyfile ├── doxygen.css ├── figures │ ├── example.cpp │ ├── ork-flattenedgraph-inkscape.svg │ ├── ork-flattenedgraph.svg │ ├── ork-render-inkscape.svg │ ├── ork-render-old.svg │ ├── ork-render.svg │ ├── ork-taskgraph-inkscape.svg │ ├── ork-taskgraph.svg │ ├── resource-example.cpp │ ├── scenegraph-example.cpp │ └── textures.png └── overview.txt ├── examples ├── CMakeLists.txt ├── GLFWTest.cpp ├── Main.cpp ├── Main.h ├── MinimalExampleGLFW.cpp ├── RenderExampleGLFW.cpp ├── ResourceExample.cpp ├── SceneGraphExampleGLFW.cpp ├── SceneGraphResourceExampleGLFW.cpp ├── TessellationExample.cpp ├── meshes │ ├── cube.mesh │ ├── plane.mesh │ ├── quad.mesh │ └── sphere.mesh ├── methods │ ├── cameraMethod.xml │ ├── cameraMethodPostprocess.xml │ ├── infoMethod.xml │ ├── lightMethod.xml │ ├── logMethod.xml │ ├── meshMethod.xml │ ├── objectMethod.xml │ └── skyboxMethod.xml ├── scenes │ ├── cubesScene.xml │ ├── exampleScene.xml │ ├── postprocessScene.xml │ └── skyboxScene.xml ├── shaders │ ├── camera.glsl │ ├── camera.xml │ ├── flat.glsl │ ├── flat.xml │ ├── plastic.xml │ ├── plasticFS.glsl │ ├── plasticVS.glsl │ ├── postprocess.glsl │ ├── postprocess.xml │ ├── skybox.glsl │ ├── skybox.xml │ ├── skyboxArray.xml │ ├── spotlight.glsl │ ├── spotlight.xml │ ├── text.glsl │ ├── text.xml │ ├── texturedPlastic.glsl │ └── texturedPlastic.xml └── textures │ ├── checker.png │ ├── checker.xml │ ├── cubemap.png │ ├── cubemap.xml │ ├── cubemapArray.png │ ├── cubemapArray.xml │ ├── defaultFont.xml │ ├── lucidaConsole.png │ ├── lucidaConsole.xml │ ├── offscreenColor.xml │ └── offscreenDepth.xml ├── libraries ├── CMakeLists.txt ├── pmath.h ├── stbi │ ├── CMakeLists.txt │ ├── stb_image.cpp │ └── stb_image.h └── tinyxml │ ├── CMakeLists.txt │ ├── tinyxml.cpp │ ├── tinyxml.h │ ├── tinyxmlerror.cpp │ └── tinyxmlparser.cpp ├── ork ├── CMakeLists.txt ├── core │ ├── Atomic.h │ ├── Factory.h │ ├── FileLogger.cpp │ ├── FileLogger.h │ ├── GPUTimer.cpp │ ├── GPUTimer.h │ ├── Iterator.h │ ├── Logger.cpp │ ├── Logger.h │ ├── Object.cpp │ ├── Object.h │ ├── Timer.cpp │ └── Timer.h ├── math │ ├── box2.h │ ├── box3.h │ ├── half.cpp │ ├── half.h │ ├── mat2.h │ ├── mat3.h │ ├── mat4.h │ ├── quat.h │ ├── vec2.h │ ├── vec3.h │ └── vec4.h ├── ork.pc.in ├── render │ ├── AttributeBuffer.cpp │ ├── AttributeBuffer.h │ ├── Buffer.cpp │ ├── Buffer.h │ ├── CPUBuffer.cpp │ ├── CPUBuffer.h │ ├── FrameBuffer.cpp │ ├── FrameBuffer.h │ ├── GPUBuffer.cpp │ ├── GPUBuffer.h │ ├── Mesh.h │ ├── MeshBuffers.cpp │ ├── MeshBuffers.h │ ├── Module.cpp │ ├── Module.h │ ├── Program.cpp │ ├── Program.h │ ├── Query.cpp │ ├── Query.h │ ├── RenderBuffer.cpp │ ├── RenderBuffer.h │ ├── Sampler.cpp │ ├── Sampler.h │ ├── Texture.cpp │ ├── Texture.h │ ├── Texture1D.cpp │ ├── Texture1D.h │ ├── Texture1DArray.cpp │ ├── Texture1DArray.h │ ├── Texture2D.cpp │ ├── Texture2D.h │ ├── Texture2DArray.cpp │ ├── Texture2DArray.h │ ├── Texture2DMultisample.cpp │ ├── Texture2DMultisample.h │ ├── Texture2DMultisampleArray.cpp │ ├── Texture2DMultisampleArray.h │ ├── Texture3D.cpp │ ├── Texture3D.h │ ├── TextureBuffer.cpp │ ├── TextureBuffer.h │ ├── TextureCube.cpp │ ├── TextureCube.h │ ├── TextureCubeArray.cpp │ ├── TextureCubeArray.h │ ├── TextureRectangle.cpp │ ├── TextureRectangle.h │ ├── TransformFeedback.cpp │ ├── TransformFeedback.h │ ├── Types.cpp │ ├── Types.h │ ├── Uniform.cpp │ ├── Uniform.h │ ├── Value.cpp │ └── Value.h ├── resource │ ├── CompiledResourceLoader.cpp │ ├── CompiledResourceLoader.h │ ├── Resource.cpp │ ├── Resource.h │ ├── ResourceCompiler.cpp │ ├── ResourceCompiler.h │ ├── ResourceDescriptor.cpp │ ├── ResourceDescriptor.h │ ├── ResourceFactory.cpp │ ├── ResourceFactory.h │ ├── ResourceLoader.cpp │ ├── ResourceLoader.h │ ├── ResourceManager.cpp │ ├── ResourceManager.h │ ├── ResourceTemplate.h │ ├── XMLResourceLoader.cpp │ └── XMLResourceLoader.h ├── scenegraph │ ├── AbstractTask.cpp │ ├── AbstractTask.h │ ├── CallMethodTask.cpp │ ├── CallMethodTask.h │ ├── DrawMeshTask.cpp │ ├── DrawMeshTask.h │ ├── LoopTask.cpp │ ├── LoopTask.h │ ├── Method.cpp │ ├── Method.h │ ├── SceneManager.cpp │ ├── SceneManager.h │ ├── SceneNode.cpp │ ├── SceneNode.h │ ├── SequenceTask.cpp │ ├── SequenceTask.h │ ├── SetProgramTask.cpp │ ├── SetProgramTask.h │ ├── SetStateTask.cpp │ ├── SetStateTask.h │ ├── SetTargetTask.cpp │ ├── SetTargetTask.h │ ├── SetTransformsTask.cpp │ ├── SetTransformsTask.h │ ├── ShowInfoTask.cpp │ ├── ShowInfoTask.h │ ├── ShowLogTask.cpp │ └── ShowLogTask.h ├── taskgraph │ ├── MultithreadScheduler.cpp │ ├── MultithreadScheduler.h │ ├── Scheduler.cpp │ ├── Scheduler.h │ ├── Task.cpp │ ├── Task.h │ ├── TaskFactory.cpp │ ├── TaskFactory.h │ ├── TaskGraph.cpp │ └── TaskGraph.h ├── ui │ ├── DebugCallback.cpp │ ├── DebugCallback.h │ ├── EventHandler.cpp │ ├── EventHandler.h │ ├── GlfwWindow.cpp │ ├── GlfwWindow.h │ ├── Window.cpp │ └── Window.h └── util │ ├── Font.cpp │ └── Font.h └── test ├── CMakeLists.txt ├── Test.cpp ├── Test.h ├── TestFrameBuffer.cpp ├── TestProgram.cpp ├── TestResource.cpp ├── TestTexture.cpp ├── TestUniform.cpp └── TestUniformBlock.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore all builds 2 | /build/ 3 | # Ignore bin outut directory 4 | /bin/ 5 | # Ignore library output directory 6 | /lib/ 7 | 8 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(Ork CXX C) 2 | cmake_minimum_required(VERSION 2.6) 3 | cmake_policy(VERSION 2.6) 4 | 5 | SET(ORK_VERSION_MAJOR 3) 6 | SET(ORK_VERSION_MINOR 2) 7 | SET(ORK_VERSION "${ORK_VERSION_MAJOR}.${ORK_VERSION_MINOR}") 8 | 9 | # Avoid source tree pollution 10 | if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) 11 | message(FATAL_ERROR "In-source builds are not permitted. Make a separate folder for building:\nmkdir build; cd build; cmake ..\nBefore that, remove the files already created:\nrm -rf CMakeCache.txt CMakeFiles") 12 | endif(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) 13 | 14 | # Add a sensible build type default and warning because empty means no optimization and no debug info. 15 | if(NOT CMAKE_BUILD_TYPE) 16 | message("WARNING: CMAKE_BUILD_TYPE is not defined!\n Defaulting to CMAKE_BUILD_TYPE=RelWithDebInfo. Use ccmake to set a proper value.") 17 | set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE) 18 | endif(NOT CMAKE_BUILD_TYPE) 19 | 20 | # Common deps 21 | find_package(PkgConfig) 22 | 23 | PKG_CHECK_MODULES(Glew glew REQUIRED) 24 | include_directories(${Glew_INCLUDE_DIRS}) 25 | link_directories(${Glew_LIBRARY_DIRS}) 26 | 27 | PKG_CHECK_MODULES(GLFW glfw3 REQUIRED) 28 | include_directories(${GLFW_INCLUDE_DIRS}) 29 | link_directories(${GLFW_LIBRARY_DIRS}) 30 | 31 | find_package(GLUT) 32 | #find_package(OpenGL) 33 | 34 | 35 | set(LIB_INSTALL_DIR "lib" CACHE STRING "Library directory name (lib/lib32/lib64)" ) 36 | 37 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) 38 | add_definitions("-DORK_API=" "-DTIXML_USE_STL" "-fPIC") 39 | 40 | option(BUILD_SHARED "Build shared library instead of static" OFF) 41 | option(BUILD_EXAMPLES "Build examples" ON ) 42 | option(BUILD_TESTS "Build tests" ON ) 43 | option(USE_SHARED_PTR "Use std::shared_ptr" ON ) 44 | option(USE_FREEGLUT "Use freeglut" ON ) 45 | 46 | if(USE_SHARED_PTR) 47 | add_definitions("-DUSE_SHARED_PTR") 48 | endif(USE_SHARED_PTR) 49 | if(USE_FREEGLUT) 50 | add_definitions("-DUSEFREEGLUT") 51 | endif(USE_FREEGLUT) 52 | 53 | 54 | # Sub dirs 55 | add_subdirectory(libraries) 56 | add_subdirectory(ork) 57 | 58 | if(BUILD_EXAMPLES) 59 | add_subdirectory(examples) 60 | endif(BUILD_EXAMPLES) 61 | 62 | if(BUILD_TESTS) 63 | add_subdirectory(test) 64 | endif(BUILD_TESTS) 65 | -------------------------------------------------------------------------------- /HISTORY.TXT: -------------------------------------------------------------------------------- 1 | Ork 3.1 (october 2010) 2 | 3 | Release of Ork as an Open Source project, with LGPL license. 4 | -------------------------------------------------------------------------------- /INSTALL.TXT: -------------------------------------------------------------------------------- 1 | REQUIREMENTS 2 | ------------------------------------------------------------------------------ 3 | 4 | Ork requires the latest driver for your graphics card, providing support for 5 | OpenGL 3.3. Ork can also benefit from some OpenGL 4.1 features (like the 6 | glProgramUniform* entry points), but it does not require a full support of 7 | OpenGL 4.0 or 4.1 to be used (unless you want to use the new features provided 8 | by OpenGL 4, like tesselation). 9 | 10 | Ork also requires the following external libraries: 11 | - glew-1.5.6 12 | - pthreads-2.8.0 (only the task graph and scene graph frameworks) 13 | - glut or freeglut (only for the GlutWindow class) 14 | 15 | INSTALLATION 16 | ------------------------------------------------------------------------------ 17 | 18 | Ork is built by the following 19 | mkdir build 20 | cd build 21 | cmake .. 22 | make 23 | sudo make install (if you want to install the library - not needed for just 24 | running the examples) 25 | 26 | From the original Ork 3.1: 27 | The USE_SHARED_PTR preprocessor flag can be set to use std::tr1::shared_ptr 28 | (needs a compiler providing support for this). Otherwise smart pointers use 29 | an Ork specific implementation (potentially more efficient since based on 30 | intrusive counters). 31 | 32 | Update: 33 | It is strongly advised to use shared ptrs and not Orks internal smart pointers. 34 | Current branch is untested with orks own smart pointers and there were signs of 35 | bugs and memory leaks when using these. 36 | 37 | 38 | UNIT TESTS 39 | ------------------------------------------------------------------------------ 40 | 41 | The unit tests are launched with the following command line: 42 | 43 | ork-tests (ALL | FORK | testName) [GL4] 44 | 45 | ALL runs all the tests in a single process, FORK runs each test in a separate 46 | process, and 'testName' runs only the test named 'testName'. GL4 is optional. 47 | If present, it means that a GL4 context should be used to run the tests (this 48 | only works with freeglut - in other cases the default context is used). 49 | 50 | EXAMPLES 51 | ------------------------------------------------------------------------------ 52 | 53 | Nine examples are provided with Ork. They are run with the following 54 | command lines: 55 | 56 | - ork-examples minimal 57 | 58 | - ork-examples render examples 59 | - ork-examples resource examples 60 | - ork-examples scenegraph examples 61 | - ork-examples scenegraphresource exampleScene 62 | 63 | - ork-examples scenegraphresource postprocessScene 64 | - ork-examples scenegraphresource skyboxScene 65 | - ork-examples scenegraphresource cubesScene 66 | 67 | - ork-examples tessellation 68 | 69 | The minimal example displays a checkerboard pattern. The next four examples 70 | are four different implementations of the same "application", showing a cube 71 | floating over a plane. The first implementation uses the core API only, the 72 | second one uses this API together with the resource framework, the third 73 | implementation uses the scene graph framework, and the fourth uses the scene 74 | graph framework via the resource framework. This fourth implementation can in 75 | fact load any scene graph, as shown by the next three examples: 76 | postprocessScene shows how the generic scene graph can be use to define 77 | various rendering strategies, skyboxScene illustrates how cubemap textures 78 | must be defined in 2D textures, and cubesScene shows how uniforms defined in 79 | scene nodes can be used in GLSL programs. The last example illustrates how 80 | tessellation shaders can be used (it only works with an OpenGL 4 graphics 81 | card). 82 | 83 | KNOWN BUGS 84 | ------------------------------------------------------------------------------ 85 | 86 | Some tests fail with ATI cards (e.g. HD 2400 or HD 5400), in particular all 87 | the tests related to uniform blocks. As a consequence, many examples fail too. 88 | These bugs do not appear with NVIDIA cards (e.g. GTX 470 or GTX 260M), so we 89 | suspect driver bugs. 90 | -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Ork 2 | [Ork home page](http://ork.gforge.inria.fr/) 3 | 4 | ##Introduction 5 | Ork, for OpenGL rendering kernel, provides a C++ API on top of OpenGL, which greatly simplifies the development of 3D applications. 6 | 7 | ##Example 8 | Suppose that you want to draw a mesh in an offscreen framebuffer, with a program that uses a texture. Assuming that these objects are already created, with the OpenGL API you need something like this: 9 | ```C++ 10 | glUseProgram(myProgram); 11 | glActiveTexture(GL_TEXTURE0 + myUnit); 12 | glBindTexture(GL_TEXTURE_2D, myTexture); 13 | glUniform1i(glGetUniformLocation(myProgram, "mySampler"), myUnit); 14 | glBindBuffer(GL_ARRAY_BUFFER, myVBO); 15 | glVertexAttribPointer(0, 4, GL_FLOAT, false, 16, 0); 16 | glEnableVertexAttribArray(0); 17 | glBindFramebuffer(GL_FRAMEBUFFER, myFramebuffer); 18 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 19 | ``` 20 | With the Ork API you simply need two steps (and the first one does not need to be repeated before each draw, unless you want a different texture for each draw): 21 | ```C++ 22 | myProgram->getUniformSampler("mySampler")->set(myTexture); 23 | myFramebuffer->draw(myProgram, *myMesh); 24 | ``` 25 | 26 | ## My contribution 27 | I am playing with integrating Proland in a project, and Proland runs on Ork. Since Ork does not allways build and run out of the box, the are some modifications to be done. 28 | 29 | -------------------------------------------------------------------------------- /doc/figures/example.cpp: -------------------------------------------------------------------------------- 1 | #include "ork/render/FrameBuffer.h" 2 | #include "ork/ui/GlutWindow.h" 3 | 4 | using namespace ork; 5 | 6 | class SimpleExample : public GlutWindow 7 | { 8 | public: 9 | ptr< Mesh > m; 10 | ptr p; 11 | 12 | SimpleExample() : GlutWindow(Window::Parameters()) 13 | { 14 | m = new Mesh(TRIANGLE_STRIP, GPU_STATIC); 15 | m->addAttributeType(0, 2, A32F, false); 16 | m->addVertex(vec2f(-1, -1)); 17 | m->addVertex(vec2f(+1, -1)); 18 | m->addVertex(vec2f(-1, +1)); 19 | m->addVertex(vec2f(+1, +1)); 20 | 21 | unsigned char data[16] = { 22 | 0, 255, 0, 255, 23 | 255, 0, 255, 0, 24 | 0, 255, 0, 255, 25 | 255, 0, 255, 0 26 | }; 27 | ptr tex = new Texture2D(4, 4, R8, RED, UNSIGNED_BYTE, 28 | Texture::Parameters().mag(NEAREST), Buffer::Parameters(), CPUBuffer(data)); 29 | 30 | p = new Program(new Module(330, NULL, "\ 31 | #version 330\n\ 32 | uniform sampler2D sampler;\n\ 33 | uniform vec2 scale;\n\ 34 | layout(location = 0) out vec4 data;\n\ 35 | void main() {\n\ 36 | data = texture(sampler, gl_FragCoord.xy * scale).rrrr;\n\ 37 | }\n")); 38 | 39 | p->getUniformSampler("sampler")->set(tex); 40 | } 41 | 42 | virtual void redisplay(double t, double dt) 43 | { 44 | ptr fb = FrameBuffer::getDefault(); 45 | fb->clear(true, false, false); 46 | fb->draw(p, *m); 47 | GlutWindow::redisplay(t, dt); 48 | } 49 | 50 | virtual void reshape(int x, int y) 51 | { 52 | FrameBuffer::getDefault()->setViewport(vec4(0, 0, x, y)); 53 | p->getUniform2f("scale")->set(vec2f(1.0f / x, 1.0f / y)); 54 | GlutWindow::reshape(x, y); 55 | idle(false); 56 | } 57 | }; 58 | 59 | int main(int argc, char** argv) 60 | { 61 | atexit(Object::exit); 62 | ptr app = new SimpleExample(); 63 | app->start(); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /doc/figures/resource-example.cpp: -------------------------------------------------------------------------------- 1 | #include "ork/resource/XMLResourceLoader.h" 2 | #include "ork/resource/ResourceManager.h" 3 | #include "ork/render/FrameBuffer.h" 4 | #include "ork/ui/GlutWindow.h" 5 | 6 | using namespace ork; 7 | 8 | class SimpleExample : public GlutWindow 9 | { 10 | public: 11 | ptr resManager; 12 | ptr m; 13 | ptr p; 14 | 15 | SimpleExample() : GlutWindow(Window::Parameters()) 16 | { 17 | ptr resLoader = new XMLResourceLoader(); 18 | resLoader->addPath("resources/textures"); 19 | resLoader->addPath("resources/shaders"); 20 | resLoader->addPath("resources/meshes"); 21 | 22 | resManager = new ResourceManager(resLoader); 23 | m = resManager->loadResource("quad.mesh").cast(); 24 | p = resManager->loadResource("basic;").cast(); 25 | } 26 | 27 | // rest of the code unchanged 28 | }; 29 | -------------------------------------------------------------------------------- /doc/figures/scenegraph-example.cpp: -------------------------------------------------------------------------------- 1 | #include "ork/resource/XMLResourceLoader.h" 2 | #include "ork/render/FrameBuffer.h" 3 | #include "ork/ui/GlutWindow.h" 4 | #include "ork/taskgraph/MultithreadScheduler.h" 5 | #include "ork/scenegraph/SceneManager.h" 6 | 7 | using namespace ork; 8 | 9 | class SimpleExample : public GlutWindow 10 | { 11 | public: 12 | ptr manager; 13 | 14 | SimpleExample() : GlutWindow(Window::Parameters()) 15 | { 16 | ptr l = new XMLResourceLoader(); 17 | l->addPath("resources/textures"); 18 | l->addPath("resources/shaders"); 19 | l->addPath("resources/meshes"); 20 | l->addPath("resources/methods"); 21 | l->addPath("resources/scenes"); 22 | 23 | ptr r = new ResourceManager(l, 8); 24 | 25 | manager = new SceneManager(); 26 | manager->setResourceManager(r); 27 | manager->setScheduler(new MultithreadScheduler()); 28 | manager->setRoot(r->loadResource("scene").cast()); 29 | manager->setCameraNode("camera"); 30 | manager->setCameraMethod("draw"); 31 | } 32 | 33 | virtual void redisplay(double t, double dt) 34 | { 35 | ptr fb = FrameBuffer::getDefault(); 36 | fb->clear(true, false, true); 37 | manager->update(t, dt); 38 | manager->draw(); 39 | Window::redisplay(t, dt); 40 | } 41 | 42 | // rest of the code unchanged 43 | }; 44 | -------------------------------------------------------------------------------- /doc/figures/textures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LarsFlaeten/ork/94464fd098a6c66e5b0798fd9f0400108c4221fa/doc/figures/textures.png -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | set(EXENAME ork-examples) 4 | 5 | # Sources 6 | include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/libraries" "${CMAKE_CURRENT_SOURCE_DIR}") 7 | file(GLOB SOURCE_FILES *.cpp) 8 | 9 | add_definitions("-DORK_API=") 10 | 11 | add_executable(${EXENAME} ${SOURCE_FILES}) 12 | 13 | #Added whole archive due to the "plug-in usage" 14 | set(WHOLE_ORK_LIB -Wl,--whole-archive ork -Wl,--no-whole-archive) 15 | target_link_libraries(${EXENAME} ${WHOLE_ORK_LIB}) 16 | -------------------------------------------------------------------------------- /examples/Main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #include "examples/Main.h" 48 | 49 | using namespace std; 50 | 51 | class MainFunctions 52 | { 53 | public: 54 | vector names; 55 | 56 | vector functions; 57 | }; 58 | 59 | static MainFunctions *mainFunctions = NULL; 60 | 61 | MainFunction::MainFunction(const char* name, mainFunction f) 62 | { 63 | if (mainFunctions == NULL) { 64 | mainFunctions = new MainFunctions(); 65 | } 66 | mainFunctions->names.push_back(name); 67 | mainFunctions->functions.push_back(f); 68 | } 69 | 70 | int mainFunction(int argc, char* argv[]) 71 | { 72 | assert(mainFunctions != NULL); 73 | char funcName[50]; 74 | if (argc > 1) { 75 | sprintf(funcName, "%s", argv[1]); 76 | } else { 77 | sprintf(funcName, "test"); 78 | } 79 | for (unsigned int i = 0; i < mainFunctions->names.size(); ++i) { 80 | if (strcmp(funcName, mainFunctions->names[i]) == 0) { 81 | return mainFunctions->functions[i](argc, argv); 82 | } 83 | } 84 | printf("Unknown command line argument '%s'\n", argv[1]); 85 | printf("Must be one of:\n"); 86 | for (unsigned int i = 0; i < mainFunctions->names.size(); ++i) { 87 | printf("%s\n", mainFunctions->names[i]); 88 | } 89 | return 0; 90 | } 91 | 92 | int main(int argc, char* argv[]) 93 | { 94 | return mainFunction(argc, argv); 95 | } 96 | -------------------------------------------------------------------------------- /examples/Main.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_MAIN_ 43 | #define _ORK_MAIN_ 44 | 45 | class MainFunction 46 | { 47 | public: 48 | typedef int (*mainFunction)(int argc, char* argv[]); 49 | 50 | MainFunction(const char* name, mainFunction f); 51 | }; 52 | 53 | int mainFunction(int argc, char* argv[]); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /examples/meshes/cube.mesh: -------------------------------------------------------------------------------- 1 | -1 1 -1 1 -1 1 2 | triangles 3 | 4 4 | 0 3 float false 5 | 1 3 float false 6 | 2 2 float false 7 | 3 4 ubyte true 8 | 36 9 | -1 -1 +1 0 0 +1 0 0 255 0 0 0 10 | +1 -1 +1 0 0 +1 1 0 255 0 0 0 11 | +1 +1 +1 0 0 +1 1 1 255 0 0 0 12 | +1 +1 +1 0 0 +1 1 1 255 0 0 0 13 | -1 +1 +1 0 0 +1 0 1 255 0 0 0 14 | -1 -1 +1 0 0 +1 0 0 255 0 0 0 15 | +1 -1 +1 +1 0 0 0 0 0 255 0 0 16 | +1 -1 -1 +1 0 0 1 0 0 255 0 0 17 | +1 +1 -1 +1 0 0 1 1 0 255 0 0 18 | +1 +1 -1 +1 0 0 1 1 0 255 0 0 19 | +1 +1 +1 +1 0 0 0 1 0 255 0 0 20 | +1 -1 +1 +1 0 0 0 0 0 255 0 0 21 | -1 +1 +1 0 +1 0 0 0 0 0 255 0 22 | +1 +1 +1 0 +1 0 1 0 0 0 255 0 23 | +1 +1 -1 0 +1 0 1 1 0 0 255 0 24 | +1 +1 -1 0 +1 0 1 1 0 0 255 0 25 | -1 +1 -1 0 +1 0 0 1 0 0 255 0 26 | -1 +1 +1 0 +1 0 0 0 0 0 255 0 27 | +1 -1 -1 0 0 -1 0 0 0 255 255 0 28 | -1 -1 -1 0 0 -1 1 0 0 255 255 0 29 | -1 +1 -1 0 0 -1 1 1 0 255 255 0 30 | -1 +1 -1 0 0 -1 1 1 0 255 255 0 31 | +1 +1 -1 0 0 -1 0 1 0 255 255 0 32 | +1 -1 -1 0 0 -1 0 0 0 255 255 0 33 | -1 -1 -1 -1 0 0 0 0 255 0 255 0 34 | -1 -1 +1 -1 0 0 1 0 255 0 255 0 35 | -1 +1 +1 -1 0 0 1 1 255 0 255 0 36 | -1 +1 +1 -1 0 0 1 1 255 0 255 0 37 | -1 +1 -1 -1 0 0 0 1 255 0 255 0 38 | -1 -1 -1 -1 0 0 0 0 255 0 255 0 39 | -1 -1 -1 0 -1 0 0 0 255 255 0 0 40 | +1 -1 -1 0 -1 0 1 0 255 255 0 0 41 | +1 -1 +1 0 -1 0 1 1 255 255 0 0 42 | +1 -1 +1 0 -1 0 1 1 255 255 0 0 43 | -1 -1 +1 0 -1 0 0 1 255 255 0 0 44 | -1 -1 -1 0 -1 0 0 0 255 255 0 0 45 | 0 46 | //attributes: position - normal - uv - color 47 | -------------------------------------------------------------------------------- /examples/meshes/plane.mesh: -------------------------------------------------------------------------------- 1 | -10 10 -10 10 0 0 2 | trianglestrip 3 | 4 4 | 0 3 float false 5 | 1 3 float false 6 | 2 2 float false 7 | 3 4 ubyte true 8 | 4 9 | -10 -10 0 0 0 +1 0 0 248 166 10 0 10 | +10 -10 0 0 0 +1 1 0 248 166 10 0 11 | -10 +10 0 0 0 +1 0 1 248 166 10 0 12 | +10 +10 0 0 0 +1 1 1 248 166 10 0 13 | 0 14 | // attributes: position - normal - uv - color 15 | -------------------------------------------------------------------------------- /examples/meshes/quad.mesh: -------------------------------------------------------------------------------- 1 | -1 1 -1 1 0 0 2 | trianglestrip 3 | 1 4 | 0 2 float false 5 | 4 6 | -1 -1 7 | +1 -1 8 | -1 +1 9 | +1 +1 10 | 0 11 | -------------------------------------------------------------------------------- /examples/methods/cameraMethod.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/methods/cameraMethodPostprocess.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /examples/methods/infoMethod.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/methods/lightMethod.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/methods/logMethod.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/methods/meshMethod.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/methods/objectMethod.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/methods/skyboxMethod.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/scenes/cubesScene.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /examples/scenes/exampleScene.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /examples/scenes/postprocessScene.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /examples/scenes/skyboxScene.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /examples/shaders/camera.glsl: -------------------------------------------------------------------------------- 1 | uniform camera { 2 | vec3 worldCameraPos; 3 | }; 4 | 5 | uniform mat4 localToScreen; 6 | uniform mat4 localToWorld; 7 | 8 | #ifdef _VERTEX_ 9 | 10 | layout(location = 0) in vec3 POS; 11 | 12 | void projection() { 13 | gl_Position = localToScreen * vec4(POS, 1.0); 14 | } 15 | 16 | void projection(out vec3 worldVertex) { 17 | gl_Position = localToScreen * vec4(POS, 1.0); 18 | worldVertex = (localToWorld * vec4(POS, 1.0)).xyz; 19 | } 20 | 21 | void projection(vec3 normal, out vec3 worldVertex, out vec3 worldNormal) { 22 | gl_Position = localToScreen * vec4(POS, 1.0); 23 | worldVertex = (localToWorld * vec4(POS, 1.0)).xyz; 24 | worldNormal = (localToWorld * vec4(normal, 0.0)).xyz; 25 | } 26 | 27 | #endif 28 | 29 | #ifdef _FRAGMENT_ 30 | 31 | vec3 viewDir(vec3 worldP) { 32 | return normalize(worldP - worldCameraPos); 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /examples/shaders/camera.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/shaders/flat.glsl: -------------------------------------------------------------------------------- 1 | #ifdef _VERTEX_ 2 | 3 | layout(location = 1) in vec3 normal; 4 | layout(location = 3) in vec4 color; 5 | 6 | out vec3 wpos; 7 | out vec3 wnormal; 8 | 9 | void projection(vec3 normal, out vec3 worldPos, out vec3 worldNormal); 10 | 11 | void main() { 12 | projection(normal, wpos, wnormal); 13 | } 14 | 15 | #endif 16 | 17 | #ifdef _FRAGMENT_ 18 | 19 | uniform vec4 color; 20 | 21 | in vec3 wpos; 22 | in vec3 wnormal; 23 | 24 | layout(location = 0) out vec4 data; 25 | 26 | vec3 viewDir(vec3 worldP); 27 | 28 | float illuminance(vec3 worldP, vec3 worldN, out vec3 worldL); 29 | 30 | void main() { 31 | vec3 wl; 32 | vec3 wn = normalize(wnormal); 33 | float light = illuminance(wpos, wn, wl); 34 | data = color * (0.5 + 0.5 * dot(wn, wl)); 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /examples/shaders/flat.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/shaders/plastic.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/shaders/plasticFS.glsl: -------------------------------------------------------------------------------- 1 | in vec3 wpos; 2 | in vec3 wnormal; 3 | in vec4 fcolor; 4 | 5 | layout(location = 0) out vec4 data; 6 | 7 | vec3 viewDir(vec3 worldP); 8 | 9 | float illuminance(vec3 worldP, vec3 worldN, out vec3 worldL); 10 | 11 | void main() { 12 | vec3 wl; 13 | vec3 wn = normalize(wnormal); 14 | float light = illuminance(wpos, wn, wl); 15 | 16 | float angle = dot(viewDir(wpos), reflect(wl, wn)); 17 | float specular = light * pow(max(angle, 0.0), 5.0); 18 | 19 | data = fcolor * (light + 0.2) + vec4(specular); 20 | } 21 | -------------------------------------------------------------------------------- /examples/shaders/plasticVS.glsl: -------------------------------------------------------------------------------- 1 | layout(location = 1) in vec3 normal; 2 | layout(location = 3) in vec4 color; 3 | 4 | out vec3 wpos; 5 | out vec3 wnormal; 6 | out vec4 fcolor; 7 | 8 | void projection(vec3 normal, out vec3 worldPos, out vec3 worldNormal); 9 | 10 | void main() { 11 | projection(normal, wpos, wnormal); 12 | fcolor = color; 13 | } 14 | -------------------------------------------------------------------------------- /examples/shaders/postprocess.glsl: -------------------------------------------------------------------------------- 1 | #ifdef _VERTEX_ 2 | 3 | layout (location = 0) in vec4 vertex; 4 | out vec2 uv; 5 | 6 | void main() { 7 | gl_Position = vertex; 8 | uv = vertex.xy * 0.5 + vec2(0.5); 9 | } 10 | 11 | #endif 12 | 13 | #ifdef _FRAGMENT_ 14 | 15 | uniform sampler2D colorSampler; 16 | uniform sampler2D depthSampler; 17 | 18 | in vec2 uv; 19 | layout (location = 0) out vec4 data; 20 | 21 | void main() { 22 | data = textureLod(colorSampler, uv, 0.0); 23 | data += textureLod(colorSampler, uv, 1.0) * 0.25; 24 | data += textureLod(colorSampler, uv, 2.0) * 0.25; 25 | data += textureLod(colorSampler, uv, 3.0) * 0.25; 26 | data += textureLod(colorSampler, uv, 4.0) * 0.25; 27 | data += textureLod(colorSampler, uv, 5.0) * 0.25; 28 | data += textureLod(colorSampler, uv, 6.0) * 0.25; 29 | data += textureLod(colorSampler, uv, 7.0) * 0.25; 30 | data += textureLod(colorSampler, uv, 8.0) * 0.25; 31 | gl_FragDepth = texture(depthSampler, uv).x; 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /examples/shaders/postprocess.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/shaders/skybox.glsl: -------------------------------------------------------------------------------- 1 | #ifdef _VERTEX_ 2 | 3 | layout (location = 0) in vec3 vertex; 4 | out vec3 dir; 5 | 6 | uniform mat4 cameraToWorld; 7 | uniform mat4 screenToCamera; 8 | 9 | void main() { 10 | dir = (cameraToWorld * vec4((screenToCamera * vec4(vertex, 1.0)).xyz, 0.0)).xyz; 11 | gl_Position = vec4(vertex.xy, 0.9999999, 1.0); 12 | } 13 | 14 | #endif 15 | 16 | #ifdef _FRAGMENT_ 17 | 18 | in vec3 dir; 19 | layout (location = 0) out vec4 data; 20 | 21 | #ifdef CUBEMAPARRAY 22 | #extension GL_ARB_texture_cube_map_array : enable 23 | uniform samplerCubeArray skymap; 24 | uniform float map; 25 | #else 26 | uniform samplerCube skymap; 27 | #endif 28 | 29 | void main() { 30 | #ifdef CUBEMAPARRAY 31 | data = texture(skymap, vec4(dir, map)); 32 | #else 33 | data = texture(skymap, dir); 34 | #endif 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /examples/shaders/skybox.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/shaders/skyboxArray.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/shaders/spotlight.glsl: -------------------------------------------------------------------------------- 1 | uniform light { 2 | vec3 worldLightPos; 3 | vec3 worldLightDir; 4 | vec2 spotlightAngle; 5 | }; 6 | 7 | float illuminance(vec3 worldP, vec3 worldN, out vec3 worldL) { 8 | worldL = normalize(worldLightPos - worldP); 9 | float falloff = 1.0 - smoothstep(spotlightAngle.x, spotlightAngle.y, acos(dot(worldLightDir, -worldL))); 10 | return max(dot(worldN, worldL), 0.0) * falloff; 11 | } 12 | 13 | #ifdef _VERTEX_ 14 | #endif 15 | 16 | #ifdef _FRAGMENT_ 17 | #endif 18 | -------------------------------------------------------------------------------- /examples/shaders/spotlight.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /examples/shaders/text.glsl: -------------------------------------------------------------------------------- 1 | #ifdef _VERTEX_ 2 | 3 | layout(location = 0) in vec4 vertex; 4 | layout(location = 1) in vec4 color; 5 | out vec2 uv; 6 | flat out vec3 rgb; 7 | 8 | void main() { 9 | gl_Position = vec4(vertex.xy, 0.0, 1.0); 10 | uv = vertex.zw; 11 | rgb = color.rgb; 12 | } 13 | 14 | #endif 15 | 16 | #ifdef _FRAGMENT_ 17 | 18 | uniform sampler2D font; 19 | 20 | in vec2 uv; 21 | flat in vec3 rgb; 22 | layout(location = 0) out vec4 color; 23 | 24 | void main() { 25 | float v = texture(font, uv).r; 26 | color.rgb = (1.0 - v) * rgb * 0.25 + v * rgb; 27 | color.a = 0.6 + 0.4 * v; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /examples/shaders/text.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/shaders/texturedPlastic.glsl: -------------------------------------------------------------------------------- 1 | #ifdef _VERTEX_ 2 | 3 | layout(location = 1) in vec3 normal; 4 | layout(location = 2) in vec2 uv; 5 | 6 | out vec3 wpos; 7 | out vec3 wnormal; 8 | out vec2 fuv; 9 | 10 | void projection(vec3 normal, out vec3 worldPos, out vec3 worldNormal); 11 | 12 | void main() { 13 | projection(normal, wpos, wnormal); 14 | fuv = uv; 15 | } 16 | 17 | #endif 18 | 19 | #ifdef _FRAGMENT_ 20 | 21 | uniform sampler2D tex; 22 | 23 | in vec3 wpos; 24 | in vec3 wnormal; 25 | in vec2 fuv; 26 | 27 | layout(location = 0) out vec4 data; 28 | 29 | vec3 viewDir(vec3 worldP); 30 | 31 | float illuminance(vec3 worldP, vec3 worldN, out vec3 worldL); 32 | 33 | void main() { 34 | vec3 wl; 35 | vec3 wn = normalize(wnormal); 36 | float light = illuminance(wpos, wn, wl); 37 | 38 | float angle = dot(viewDir(wpos), reflect(wl, wn)); 39 | float specular = light * pow(max(angle, 0.0), 5.0); 40 | 41 | vec4 fcolor = texture(tex, fuv); 42 | 43 | data = fcolor * (light + 0.2) + vec4(specular); 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /examples/shaders/texturedPlastic.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/textures/checker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LarsFlaeten/ork/94464fd098a6c66e5b0798fd9f0400108c4221fa/examples/textures/checker.png -------------------------------------------------------------------------------- /examples/textures/checker.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/textures/cubemap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LarsFlaeten/ork/94464fd098a6c66e5b0798fd9f0400108c4221fa/examples/textures/cubemap.png -------------------------------------------------------------------------------- /examples/textures/cubemap.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/textures/cubemapArray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LarsFlaeten/ork/94464fd098a6c66e5b0798fd9f0400108c4221fa/examples/textures/cubemapArray.png -------------------------------------------------------------------------------- /examples/textures/cubemapArray.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/textures/defaultFont.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/textures/lucidaConsole.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LarsFlaeten/ork/94464fd098a6c66e5b0798fd9f0400108c4221fa/examples/textures/lucidaConsole.png -------------------------------------------------------------------------------- /examples/textures/lucidaConsole.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/textures/offscreenColor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/textures/offscreenDepth.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /libraries/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}") 2 | 3 | add_subdirectory(stbi) 4 | add_subdirectory(tinyxml) 5 | 6 | INSTALL(FILES pmath.h DESTINATION include/ork/math) 7 | INSTALL(FILES tinyxml/tinyxml.h DESTINATION include/ork/resource/tinyxml) 8 | INSTALL(FILES stbi/stb_image.h DESTINATION include/ork/resource/stbi) 9 | -------------------------------------------------------------------------------- /libraries/stbi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LIBNAME "stb_image") 2 | 3 | # Sources 4 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}") 5 | file(GLOB SOURCE_FILES *.cpp) 6 | 7 | # Create a static library 8 | add_library(${LIBNAME} STATIC ${SOURCE_FILES}) 9 | 10 | link_directories(${CMAKE_CURRENT_BINARY_DIR}) 11 | 12 | # Install library 13 | INSTALL(TARGETS ${LIBNAME} LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR}) 14 | 15 | -------------------------------------------------------------------------------- /libraries/tinyxml/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LIBNAME "tinyxml") 2 | 3 | # Sources 4 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}") 5 | file(GLOB SOURCE_FILES *.cpp) 6 | 7 | add_definitions("-DORK_API=" "-DTIXML_USE_STL") 8 | 9 | # Create a static library 10 | add_library(${LIBNAME} STATIC ${SOURCE_FILES}) 11 | 12 | link_directories(${CMAKE_CURRENT_BINARY_DIR}) 13 | 14 | # Install library 15 | INSTALL(TARGETS ${LIBNAME} LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR}) 16 | 17 | -------------------------------------------------------------------------------- /libraries/tinyxml/tinyxmlerror.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | www.sourceforge.net/projects/tinyxml 3 | Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com) 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any 7 | damages arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any 10 | purpose, including commercial applications, and to alter it and 11 | redistribute it freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must 14 | not claim that you wrote the original software. If you use this 15 | software in a product, an acknowledgment in the product documentation 16 | would be appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and 19 | must not be misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | */ 24 | 25 | #include "tinyxml.h" 26 | 27 | // The goal of the seperate error file is to make the first 28 | // step towards localization. tinyxml (currently) only supports 29 | // english error messages, but the could now be translated. 30 | // 31 | // It also cleans up the code a bit. 32 | // 33 | 34 | const char* TiXmlBase::errorString[ TIXML_ERROR_STRING_COUNT ] = 35 | { 36 | "No error", 37 | "Error", 38 | "Failed to open file", 39 | "Memory allocation failed.", 40 | "Error parsing Element.", 41 | "Failed to read Element name", 42 | "Error reading Element value.", 43 | "Error reading Attributes.", 44 | "Error: empty tag.", 45 | "Error reading end tag.", 46 | "Error parsing Unknown.", 47 | "Error parsing Comment.", 48 | "Error parsing Declaration.", 49 | "Error document empty.", 50 | "Error null (0) or unexpected EOF found in input stream.", 51 | "Error parsing CDATA.", 52 | "Error when TiXmlDocument added to document, because TiXmlDocument can only be at the root.", 53 | }; 54 | -------------------------------------------------------------------------------- /ork/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LIBNAME "ork") 2 | 3 | # Sources 4 | include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/libraries" "${PROJECT_SOURCE_DIR}/libraries/*") 5 | file(GLOB SOURCE_FILES *.cpp */*.cpp) 6 | 7 | # Libraries 8 | set(LIBS GL GLU GLEW pthread stb_image tinyxml Xinerama Xcursor) 9 | if(UNIX) 10 | set(LIBS ${LIBS} rt) 11 | endif(UNIX) 12 | 13 | #message(STATUS "Using libs: " ${LIBS}) 14 | #message(STATUS "GLFW needs: " ${GLFW_STATIC_LIBRARIES}) 15 | # Static or shared? 16 | set(LIBTYPE STATIC) 17 | set(GLFWLIBS ${GLFW_STATIC_LIBRARIES}) 18 | if(BUILD_SHARED) 19 | set(LIBTYPE SHARED) 20 | set(GLFWLIBS glfw3) 21 | endif(BUILD_SHARED) 22 | set(LIBS ${LIBS} ${GLFWLIBS}) 23 | message(STATUS "GLFW libs for " ${LIBTYPE} " library: " ${GLFWLIBS}) 24 | 25 | # Create a static library 26 | add_library(${LIBNAME} ${LIBTYPE} ${SOURCE_FILES}) 27 | target_link_libraries(${LIBNAME} ${LIBS}) 28 | 29 | # Adds SO Version and subversion. To be added to ensure ABI/API compatibility. 30 | #SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES SOVERSION ${ORK_VERSION_MAJOR} VERSION ${ORK_VERSION}) 31 | 32 | set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) 33 | 34 | link_directories(${PROJECT_SOURCE_DIR}/lib) 35 | 36 | # Install headers 37 | FOREACH(subdir core math render resource scenegraph taskgraph ui util) 38 | FILE(GLOB include-files ${subdir}/*.h) 39 | INSTALL(FILES ${include-files} DESTINATION include/ork/${subdir}) 40 | ENDFOREACH(subdir) 41 | 42 | # Install library 43 | INSTALL(TARGETS ork LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR}) 44 | 45 | message(STATUS "Setting ork cflags for installation package") 46 | SET(ORK_CFLAGS "-DORK_API= -DTIXML_USE_STL" ) 47 | if(USE_SHARED_PTR) 48 | message(STATUS "Setting shared ptr usage to final package") 49 | set(ORK_CFLAGS ${ORK_CFLAGS} "-DUSE_SHARED_PTR") 50 | endif(USE_SHARED_PTR) 51 | if(USE_FREEGLUT) 52 | message(STATUS "Setting freeglut usage to final package") 53 | set(ORK_CFLAGS ${ORK_CFLAGS} "-DUSEFREEGLUT") 54 | endif(USE_FREEGLUT) 55 | 56 | message(STATUS "ork cflags: " ${ORK_CFLAGS}) 57 | 58 | CONFIGURE_FILE(ork.pc.in ${PROJECT_BINARY_DIR}/ork.pc @ONLY) 59 | INSTALL(FILES ${PROJECT_BINARY_DIR}/ork.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) 60 | -------------------------------------------------------------------------------- /ork/core/Atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ATOMIC_H_ 43 | #define _ATOMIC_H_ 44 | 45 | #if defined(_MSC_VER) // MSVC 46 | #include 47 | #endif 48 | 49 | namespace ork 50 | { 51 | 52 | //#define SINGLE_THREAD 53 | 54 | /** 55 | * This file defines some atomic operations. 56 | * Those are supported across MSVC and GCC. 57 | * 58 | * Implements needed atomic operations. 59 | * - atomic_exchange_and_add(*pw, dv) 60 | * adds dv to *pw and returns the old value of pw 61 | * 62 | * - atomic_increment(*pw) 63 | * adds 1 to *pw and returns void 64 | * 65 | * - atomic_decrement(*pw) 66 | * adds 1 to *pw and returns its *previous* value 67 | */ 68 | 69 | #if defined(_MSC_VER) 70 | #define FORCE_INLINE __forceinline 71 | #else 72 | #define FORCE_INLINE __attribute__((always_inline)) 73 | #endif 74 | 75 | #ifdef SINGLE_THREAD 76 | 77 | static FORCE_INLINE int atomic_exchange_and_add(int volatile * pw, int dv) 78 | { 79 | int r = *pw; 80 | *pw += dv; 81 | return r; 82 | } 83 | 84 | static FORCE_INLINE void atomic_increment(int volatile * pw) 85 | { 86 | (*pw)++; 87 | } 88 | 89 | static FORCE_INLINE int atomic_decrement(int volatile * pw) 90 | { 91 | return (*pw)--; 92 | } 93 | 94 | #elif defined(_MSC_VER) // MSVC 95 | 96 | #define atomic_exchange_and_add(pw,dv) _InterlockedExchangeAdd((volatile long*)(pw),(dv)) 97 | #define atomic_increment(pw) (_InterlockedIncrement((volatile long*)(pw))) 98 | #define atomic_decrement(pw) (_InterlockedDecrement((volatile long*)(pw))+1) 99 | #elif defined(__GNUC__) // GCC 100 | 101 | #define atomic_exchange_and_add(pw,dv) __sync_fetch_and_add((volatile long*)(pw), dv) 102 | #define atomic_increment(pw) __sync_fetch_and_add((volatile long*)(pw), 1) 103 | #define atomic_decrement(pw) __sync_fetch_and_sub((volatile long*)(pw), 1) 104 | 105 | #else 106 | 107 | #error Unsupported compiler 108 | 109 | #endif 110 | 111 | } 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /ork/core/GPUTimer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/core/GPUTimer.h" 43 | 44 | #include 45 | 46 | #include "GL/glew.h" 47 | 48 | namespace ork 49 | { 50 | 51 | GPUTimer::GPUTimer() : Timer() 52 | { 53 | glGenQueries(1, &query); 54 | } 55 | 56 | GPUTimer::~GPUTimer() 57 | { 58 | glDeleteQueries(1, &query); 59 | } 60 | 61 | double GPUTimer::start() 62 | { 63 | getQueryResult(); 64 | numCycles++; 65 | glBeginQuery(GL_TIME_ELAPSED, query); 66 | return 0.0; 67 | } 68 | 69 | double GPUTimer::end() 70 | { 71 | glEndQuery(GL_TIME_ELAPSED); 72 | return lastDuration; 73 | } 74 | 75 | double GPUTimer::getTime() 76 | { 77 | if (lastDuration == 0) { 78 | getQueryResult(); 79 | } 80 | return lastDuration; 81 | } 82 | 83 | double GPUTimer::getAvgTime() 84 | { 85 | if (numCycles == 0) { 86 | return 0.0; 87 | } 88 | return totalDuration / numCycles; 89 | } 90 | 91 | void GPUTimer::getQueryResult() 92 | { 93 | if (numCycles > 0) { 94 | GLuint64 timeElapsed; 95 | glGetQueryObjectui64v(query, GL_QUERY_RESULT, &timeElapsed); 96 | if (timeElapsed != 0) { 97 | lastDuration = (double) timeElapsed; 98 | totalDuration += lastDuration; 99 | minDuration = std::min(lastDuration, minDuration); 100 | maxDuration = std::max(lastDuration, maxDuration); 101 | } 102 | } 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /ork/core/GPUTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_GPU_TIMER_H_ 43 | #define _ORK_GPU_TIMER_H_ 44 | 45 | #include "ork/core/Timer.h" 46 | 47 | namespace ork 48 | { 49 | 50 | /** 51 | * A timer to measure time and time intervals on GPU. Since GPU computations 52 | * are asynchroneous, we can't just use CPU time to check the duration of 53 | * an operation. 54 | * @ingroup core 55 | */ 56 | class ORK_API GPUTimer : public Timer 57 | { 58 | public: 59 | /** 60 | * Creates a new GPUTimer. 61 | */ 62 | GPUTimer(); 63 | 64 | /** 65 | * Destroys this timer. 66 | */ 67 | virtual ~GPUTimer(); 68 | 69 | /** 70 | * Starts this timer and returns the current time in micro seconds. 71 | */ 72 | virtual double start(); 73 | 74 | /** 75 | * Returns the delay since the last call to #start() in micro seconds. 76 | */ 77 | virtual double end(); 78 | 79 | /** 80 | * See Timer#getTime(). 81 | */ 82 | virtual double getTime(); 83 | 84 | /** 85 | * See Timer#getAvgTime(). 86 | */ 87 | virtual double getAvgTime(); 88 | 89 | protected: 90 | unsigned int query; ///< GPU query used to measure time on GPU. 91 | 92 | void getQueryResult(); ///< Returns the result of the query #query. 93 | }; 94 | 95 | } 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /ork/core/Logger.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/core/Logger.h" 43 | 44 | #include 45 | 46 | #include 47 | #include 48 | #include 49 | 50 | using namespace std; 51 | 52 | namespace ork 53 | { 54 | 55 | static_ptr Logger::DEBUG_LOGGER(NULL); 56 | 57 | static_ptr Logger::INFO_LOGGER(new Logger("INFO")); 58 | 59 | static_ptr Logger::WARNING_LOGGER(new Logger("WARNING")); 60 | 61 | static_ptr Logger::ERROR_LOGGER(new Logger("ERROR")); 62 | 63 | Logger::Logger(const string &type) : Object("Logger"), type(type) 64 | { 65 | mutex = new pthread_mutex_t; 66 | pthread_mutex_init((pthread_mutex_t*) mutex, NULL); 67 | } 68 | 69 | Logger::~Logger() 70 | { 71 | pthread_mutex_destroy((pthread_mutex_t*) mutex); 72 | delete (pthread_mutex_t*) mutex; 73 | } 74 | 75 | void Logger::addTopic(const string &topic) 76 | { 77 | topics = topics + topic + ";"; 78 | } 79 | 80 | bool Logger::hasTopic(const string &topic) 81 | { 82 | return topics.size() == 0 || topics.find(topic, 0) != string::npos; 83 | } 84 | 85 | void Logger::log(const string &topic, const string &msg) 86 | { 87 | if (hasTopic(topic)) { 88 | pthread_mutex_lock((pthread_mutex_t*) mutex); 89 | cerr << type << " [" << topic << "] " << msg << endl; 90 | pthread_mutex_unlock((pthread_mutex_t*) mutex); 91 | } 92 | } 93 | 94 | void Logger::logf(const char * topic, const char *fmt, ...) 95 | { 96 | static const int MAX_LOG_SIZE = 512; 97 | char buf[MAX_LOG_SIZE]; 98 | 99 | va_list vl; 100 | va_start(vl, fmt); 101 | vsnprintf(buf, MAX_LOG_SIZE, fmt, vl); 102 | va_end(vl); 103 | std::string topicStr = topic; 104 | std::string msgStr = buf; 105 | log(topicStr, msgStr); 106 | } 107 | 108 | void Logger::flush() 109 | { 110 | cerr.flush(); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /ork/ork.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | libdir=${prefix}/@LIB_INSTALL_DIR@ 3 | includedir=${prefix}/include 4 | 5 | Name: ork 6 | Description: OpenGL Rendering Kernel 7 | Version: @ORK_VERSION@ 8 | Requires: 9 | Libs: -L${libdir} -lork 10 | Cflags: -I${includedir} @ORK_CFLAGS@ 11 | -------------------------------------------------------------------------------- /ork/render/AttributeBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/render/AttributeBuffer.h" 43 | 44 | #include 45 | #include 46 | 47 | using namespace std; 48 | 49 | namespace ork 50 | { 51 | 52 | AttributeBuffer::AttributeBuffer(int index, int size, AttributeType t, bool norm, ptr b, int stride, int offset, int divisor) : 53 | Object("AttributeBuffer"), index(index), size(size), type(t), I(false), L(false), norm(norm), b(b), stride(stride), offset(offset), divisor(divisor) 54 | { 55 | } 56 | 57 | AttributeBuffer::AttributeBuffer(int index, int size, AttributeType t, ptr b, int stride, int offset, int divisor) : 58 | Object("AttributeBuffer"), index(index), size(size), type(t), I(true), L(false), norm(false), b(b), stride(stride), offset(offset), divisor(divisor) 59 | { 60 | } 61 | 62 | AttributeBuffer::AttributeBuffer(int index, int size, ptr b, int stride, int offset, int divisor) : 63 | Object("AttributeBuffer"), index(index), size(size), type(A64F), I(true), L(true), norm(false), b(b), stride(stride), offset(offset), divisor(divisor) 64 | { 65 | } 66 | 67 | AttributeBuffer::~AttributeBuffer() 68 | { 69 | } 70 | 71 | int AttributeBuffer::getSize() 72 | { 73 | return size; 74 | } 75 | 76 | AttributeType AttributeBuffer::getType() 77 | { 78 | return type; 79 | } 80 | 81 | int AttributeBuffer::getAttributeSize() 82 | { 83 | int size; 84 | switch (type) { 85 | case A8I: 86 | case A8UI: 87 | size = 1; 88 | break; 89 | case A16I: 90 | case A16UI: 91 | case A16F: 92 | size = 2; 93 | break; 94 | case A32I: 95 | case A32UI: 96 | case A32F: 97 | size = 4; 98 | break; 99 | case A64F: 100 | size = 8; 101 | break; 102 | case A32I_2_10_10_10_REV: 103 | case A32UI_2_10_10_10_REV: 104 | return 4; 105 | default: 106 | assert(false); 107 | throw exception(); 108 | } 109 | return this->size * size; 110 | } 111 | 112 | ptr AttributeBuffer::getBuffer() 113 | { 114 | return b; 115 | } 116 | 117 | int AttributeBuffer::getStride() 118 | { 119 | return stride; 120 | } 121 | 122 | int AttributeBuffer::getOffset() 123 | { 124 | return offset; 125 | } 126 | 127 | void AttributeBuffer::setBuffer(ptr b) 128 | { 129 | this->b = b; 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /ork/render/CPUBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/render/CPUBuffer.h" 43 | 44 | #include 45 | 46 | #include "ork/render/FrameBuffer.h" 47 | 48 | namespace ork 49 | { 50 | 51 | CPUBuffer::CPUBuffer(const void *data) 52 | { 53 | p = data; 54 | } 55 | 56 | CPUBuffer::~CPUBuffer() 57 | { 58 | } 59 | 60 | void CPUBuffer::bind(int target) const 61 | { 62 | glBindBuffer(target, 0); 63 | assert(FrameBuffer::getError() == GL_NO_ERROR); 64 | } 65 | 66 | void *CPUBuffer::data(int offset) const 67 | { 68 | return (void*)((char*)p + offset); 69 | } 70 | 71 | void CPUBuffer::unbind(int target) const 72 | { 73 | } 74 | 75 | void CPUBuffer::dirty() const 76 | { 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /ork/render/CPUBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_CPU_BUFFER_H_ 43 | #define _ORK_CPU_BUFFER_H_ 44 | 45 | #include "ork/render/Buffer.h" 46 | 47 | namespace ork 48 | { 49 | 50 | /** 51 | * A Buffer whose data is on the CPU. 52 | * @ingroup render 53 | */ 54 | class ORK_API CPUBuffer : public Buffer 55 | { 56 | public: 57 | /** 58 | * Creates a new CPU buffer with the given data. 59 | * 60 | * @param data the buffer data. May be NULL. 61 | */ 62 | CPUBuffer(const void *data = 0); 63 | 64 | /** 65 | * Destroys this CPU buffer. The buffer data itself is NOT destroyed. 66 | */ 67 | virtual ~CPUBuffer(); 68 | 69 | protected: 70 | virtual void bind(int target) const; 71 | 72 | virtual void *data(int offset) const; 73 | 74 | virtual void unbind(int target) const; 75 | 76 | virtual void dirty() const; 77 | 78 | private: 79 | /** 80 | * The buffer data. May be NULL. 81 | */ 82 | const void *p; 83 | 84 | friend class FrameBuffer; 85 | }; 86 | 87 | } 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /ork/render/Query.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/render/Query.h" 43 | 44 | #include 45 | 46 | namespace ork 47 | { 48 | 49 | Query::Query(QueryType type) : Object("Query"), type(type), resultAvailable(false), resultRead(false) 50 | { 51 | glGenQueries(1, &id); 52 | switch (type) { 53 | case PRIMITIVES_GENERATED: 54 | target = GL_PRIMITIVES_GENERATED; 55 | break; 56 | case TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: 57 | target = GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN; 58 | break; 59 | case SAMPLES_PASSED: 60 | target = GL_SAMPLES_PASSED; 61 | break; 62 | case ANY_SAMPLES_PASSED: 63 | target = GL_ANY_SAMPLES_PASSED; 64 | break; 65 | case TIME_STAMP: 66 | target = GL_TIME_ELAPSED; 67 | break; 68 | } 69 | } 70 | 71 | Query::~Query() 72 | { 73 | glDeleteQueries(1, &id); 74 | } 75 | 76 | QueryType Query::getType() 77 | { 78 | return type; 79 | } 80 | 81 | GLuint Query::getId() 82 | { 83 | return id; 84 | } 85 | 86 | void Query::begin() 87 | { 88 | resultRead = false; 89 | glBeginQuery(target, id); 90 | if (target == GL_TIME_ELAPSED) { 91 | glQueryCounter(id, GL_TIMESTAMP); 92 | } 93 | } 94 | 95 | void Query::end() 96 | { 97 | glEndQuery(target); 98 | } 99 | 100 | bool Query::available() 101 | { 102 | if (!resultAvailable) { 103 | GLuint result; 104 | glGetQueryObjectuiv(id, GL_QUERY_RESULT_AVAILABLE, &result); 105 | resultAvailable = result != 0; 106 | } 107 | return resultAvailable; 108 | } 109 | 110 | GLuint64 Query::getResult() 111 | { 112 | if (!resultRead) { 113 | glGetQueryObjectui64v(id, GL_QUERY_RESULT, &result); 114 | resultRead = true; 115 | } 116 | return result; 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /ork/render/Query.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_QUERY_H_ 43 | #define _ORK_QUERY_H_ 44 | 45 | #include "ork/core/Object.h" 46 | #include "ork/render/Types.h" 47 | 48 | namespace ork 49 | { 50 | 51 | /** 52 | * An asynchronous GPU query. A query measures some value, depending on its type, 53 | * between the calls to #begin() and #end(). After #end() has been called, the 54 | * result is available asynchronously. Its availability can be tested with 55 | * #available(), and its value with #getResult(). 56 | * 57 | * @ingroup render 58 | */ 59 | class ORK_API Query : public Object 60 | { 61 | public: 62 | /** 63 | * Creates a new Query of the given type. 64 | * 65 | * @param type the query type. 66 | */ 67 | Query(QueryType type); 68 | 69 | /** 70 | * Deletes this query. 71 | */ 72 | virtual ~Query(); 73 | 74 | /** 75 | * Returns the type of this query. 76 | */ 77 | QueryType getType(); 78 | 79 | /** 80 | * Returns the id of this query. 81 | */ 82 | GLuint getId(); 83 | 84 | /** 85 | * Starts this query. 86 | */ 87 | void begin(); 88 | 89 | /** 90 | * Ends this query. 91 | */ 92 | void end(); 93 | 94 | /** 95 | * Returns true if the result of this query is available. 96 | */ 97 | bool available(); 98 | 99 | /** 100 | * Returns the result of this query. This may block the caller 101 | * until the result is available. 102 | */ 103 | GLuint64 getResult(); 104 | 105 | private: 106 | /** 107 | * The type of this query. 108 | */ 109 | QueryType type; 110 | 111 | /** 112 | * The OpenGL target for this query. 113 | */ 114 | GLenum target; 115 | 116 | /** 117 | * The id of this query. 118 | */ 119 | GLuint id; 120 | 121 | /** 122 | * True if the result of this query is available. 123 | */ 124 | bool resultAvailable; 125 | 126 | /** 127 | * True if the result of this query had been read. 128 | */ 129 | bool resultRead; 130 | 131 | /** 132 | * The result of this query. 133 | */ 134 | GLuint64 result; 135 | }; 136 | 137 | } 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /ork/render/Texture2DMultisample.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/render/Texture2DMultisample.h" 43 | 44 | #include 45 | 46 | #include 47 | 48 | #include "ork/render/FrameBuffer.h" 49 | 50 | using namespace std; 51 | 52 | namespace ork 53 | { 54 | 55 | GLenum getTextureInternalFormat(TextureInternalFormat f); 56 | 57 | Texture2DMultisample::Texture2DMultisample(int w, int h, int samples, TextureInternalFormat tf, bool fixedLocations) : 58 | Texture("Texture2DMultisample", GL_TEXTURE_2D_MULTISAMPLE) 59 | { 60 | glGenTextures(1, &textureId); 61 | assert(textureId > 0); 62 | 63 | this->internalFormat = tf; 64 | this->w = w; 65 | this->h = h; 66 | this->samples = samples; 67 | 68 | bindToTextureUnit(); 69 | 70 | glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, getTextureInternalFormat(tf), w, h, fixedLocations); 71 | 72 | if (FrameBuffer::getError() != 0) { 73 | throw exception(); 74 | } 75 | } 76 | 77 | Texture2DMultisample::~Texture2DMultisample() 78 | { 79 | } 80 | 81 | int Texture2DMultisample::getWidth() 82 | { 83 | return w; 84 | } 85 | 86 | int Texture2DMultisample::getHeight() 87 | { 88 | return h; 89 | } 90 | 91 | int Texture2DMultisample::getSamples() 92 | { 93 | return samples; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /ork/render/Texture2DMultisample.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_TEXTURE_2D_MULTISAMPLE_H_ 43 | #define _ORK_TEXTURE_2D_MULTISAMPLE_H_ 44 | 45 | #include "ork/render/Buffer.h" 46 | #include "ork/render/Texture.h" 47 | 48 | namespace ork 49 | { 50 | 51 | /** 52 | * A 2D texture with multiple samples per pixel. 53 | * @ingroup render 54 | */ 55 | class ORK_API Texture2DMultisample : public Texture 56 | { 57 | public: 58 | /** 59 | * Creates a new 2D texture with multiple samples per pixel. 60 | * 61 | * @param w the width of this texture in pixels. 62 | * @param h the height of this texture in pixels. 63 | * @param samples the number of samples per pixel. 64 | * @param tf texture data format on GPU. 65 | * @param fixedLocations true to use fixed sample locations for all pixels. 66 | */ 67 | Texture2DMultisample(int w, int h, int samples, TextureInternalFormat tf, bool fixedLocations); 68 | 69 | /** 70 | * Destroys this 2D texture with multiple samples per pixel. 71 | */ 72 | virtual ~Texture2DMultisample(); 73 | 74 | /** 75 | * Returns the width of this texture. 76 | */ 77 | int getWidth(); 78 | 79 | /** 80 | * Returns the height of this texture. 81 | */ 82 | int getHeight(); 83 | 84 | /** 85 | * Returns the number of samples per pixel of this texture. 86 | */ 87 | int getSamples(); 88 | 89 | protected: 90 | /** 91 | * The width of this texture. 92 | */ 93 | int w; 94 | 95 | /** 96 | * The height of this texture. 97 | */ 98 | int h; 99 | 100 | /** 101 | * The number of samples per pixel of this texture. 102 | */ 103 | int samples; 104 | }; 105 | 106 | } 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /ork/render/Texture2DMultisampleArray.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/render/Texture2DMultisampleArray.h" 43 | 44 | #include 45 | 46 | #include 47 | 48 | #include "ork/render/FrameBuffer.h" 49 | 50 | using namespace std; 51 | 52 | namespace ork 53 | { 54 | 55 | GLenum getTextureInternalFormat(TextureInternalFormat f); 56 | 57 | Texture2DMultisampleArray::Texture2DMultisampleArray(int w, int h, int l, int samples, TextureInternalFormat tf, bool fixedLocations) : 58 | Texture("Texture2DMultisampleArray", GL_TEXTURE_2D_MULTISAMPLE_ARRAY) 59 | { 60 | glGenTextures(1, &textureId); 61 | assert(textureId > 0); 62 | 63 | this->internalFormat = tf; 64 | this->w = w; 65 | this->h = h; 66 | this->l = l; 67 | this->samples = samples; 68 | 69 | bindToTextureUnit(); 70 | 71 | glTexImage3DMultisample(GL_TEXTURE_2D_MULTISAMPLE_ARRAY, samples, getTextureInternalFormat(tf), w, h, l, fixedLocations); 72 | 73 | if (FrameBuffer::getError() != 0) { 74 | throw exception(); 75 | } 76 | } 77 | 78 | Texture2DMultisampleArray::~Texture2DMultisampleArray() 79 | { 80 | } 81 | 82 | int Texture2DMultisampleArray::getWidth() 83 | { 84 | return w; 85 | } 86 | 87 | int Texture2DMultisampleArray::getHeight() 88 | { 89 | return h; 90 | } 91 | 92 | int Texture2DMultisampleArray::getLayers() 93 | { 94 | return l; 95 | } 96 | 97 | int Texture2DMultisampleArray::getSamples() 98 | { 99 | return samples; 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /ork/render/Texture2DMultisampleArray.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Copyright (c) 2008-2010 INRIA 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | /* 20 | * Authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 21 | */ 22 | 23 | #ifndef _ORK_TEXTURE_2D_MULTISAMPLE_ARRAY_H_ 24 | #define _ORK_TEXTURE_2D_MULTISAMPLE_ARRAY_H_ 25 | 26 | #include "ork/render/Buffer.h" 27 | #include "ork/render/Texture2D.h" 28 | 29 | namespace ork 30 | { 31 | 32 | /** 33 | * A 2D array texture with multiple samples per pixel. 34 | * @ingroup render 35 | */ 36 | class ORK_API Texture2DMultisampleArray : public Texture 37 | { 38 | public: 39 | /** 40 | * Creates a new 2D texture array with multiple samples per pixel. 41 | * 42 | * @param w the width of this texture in pixels. 43 | * @param h the height of this texture in pixels. 44 | * @param l the number of layers of this texture. 45 | * @param samples the number of samples per pixel. 46 | * @param tf texture data format on GPU. 47 | * @param fixedLocations true to use fixed sample locations for all pixels. 48 | */ 49 | Texture2DMultisampleArray(int w, int h, int l, int samples, TextureInternalFormat tf, bool fixedLocations); 50 | 51 | /** 52 | * Destroys this 2D texture with multiple samples per pixel. 53 | */ 54 | virtual ~Texture2DMultisampleArray(); 55 | 56 | /** 57 | * Returns the width of this texture. 58 | */ 59 | int getWidth(); 60 | 61 | /** 62 | * Returns the height of this texture. 63 | */ 64 | int getHeight(); 65 | 66 | /** 67 | * Returns the number of layers of this texture. 68 | */ 69 | int getLayers(); 70 | 71 | /** 72 | * Returns the number of samples per pixel of this texture. 73 | */ 74 | int getSamples(); 75 | 76 | protected: 77 | /** 78 | * The width of this texture. 79 | */ 80 | int w; 81 | 82 | /** 83 | * The height of this texture. 84 | */ 85 | int h; 86 | 87 | /** 88 | * The number of this layers of this texture. 89 | */ 90 | int l; 91 | 92 | /** 93 | * The number of samples per pixel of this texture. 94 | */ 95 | int samples; 96 | }; 97 | 98 | } 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /ork/render/TextureBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/render/TextureBuffer.h" 43 | 44 | #include 45 | 46 | #include 47 | 48 | #include "ork/render/FrameBuffer.h" 49 | 50 | using namespace std; 51 | 52 | namespace ork 53 | { 54 | 55 | GLenum getTextureInternalFormat(TextureInternalFormat f); 56 | 57 | TextureBuffer::TextureBuffer(TextureInternalFormat tf, ptr pixels) : Texture("TextureBuffer", GL_TEXTURE_BUFFER) 58 | { 59 | int formatSize; 60 | switch (tf) { 61 | case R8: 62 | case R8I: 63 | case R8UI: 64 | formatSize = 1; 65 | break; 66 | case R16: 67 | case R16I: 68 | case R16UI: 69 | case R16F: 70 | case RG8: 71 | case RG8I: 72 | case RG8UI: 73 | formatSize = 2; 74 | break; 75 | case R32I: 76 | case R32UI: 77 | case R32F: 78 | case RG16: 79 | case RG16I: 80 | case RG16UI: 81 | case RG16F: 82 | case RGBA8: 83 | case RGBA8I: 84 | case RGBA8UI: 85 | formatSize = 4; 86 | break; 87 | case RG32I: 88 | case RG32UI: 89 | case RG32F: 90 | case RGBA16: 91 | case RGBA16I: 92 | case RGBA16UI: 93 | case RGBA16F: 94 | formatSize = 8; 95 | break; 96 | case RGBA32I: 97 | case RGBA32UI: 98 | case RGBA32F: 99 | formatSize = 16; 100 | break; 101 | default: 102 | assert(false); // other formats not allowed for texture buffers 103 | throw exception(); 104 | } 105 | 106 | Parameters params; 107 | params.wrapS(CLAMP_TO_EDGE); 108 | params.wrapT(CLAMP_TO_EDGE); 109 | params.wrapR(CLAMP_TO_EDGE); 110 | params.min(NEAREST); 111 | params.mag(NEAREST); 112 | params.maxLevel(0); 113 | 114 | Texture::init(tf, params); 115 | this->w = pixels->getSize() / formatSize; 116 | this->b = pixels; 117 | 118 | glTexBuffer(textureTarget, getTextureInternalFormat(internalFormat), pixels->getId()); 119 | 120 | if (FrameBuffer::getError() != 0) { 121 | throw exception(); 122 | } 123 | } 124 | 125 | TextureBuffer::~TextureBuffer() 126 | { 127 | } 128 | 129 | int TextureBuffer::getWidth() 130 | { 131 | return w; 132 | } 133 | 134 | ptr TextureBuffer::getBuffer() 135 | { 136 | return b; 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /ork/render/TextureBuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_TEXTURE_BUFFER_H_ 43 | #define _ORK_TEXTURE_BUFFER_H_ 44 | 45 | #include "ork/render/GPUBuffer.h" 46 | #include "ork/render/Texture.h" 47 | 48 | namespace ork 49 | { 50 | 51 | /** 52 | * A buffer texture. A buffer texture is similar to a one-dimensional texture. 53 | * However, unlike other texture types, the texel array is not stored as part 54 | * of the texture. Instead, a buffer object is attached to a buffer texture 55 | * and the texel array is taken from the data store of an attached buffer 56 | * object. When the contents of a buffer object's data store are modified, 57 | * those changes are reflected in the contents of any buffer texture to which 58 | * the buffer object is attached. Also unlike other textures, buffer 59 | * textures do not have multiple image levels; only a single data store is 60 | * available. 61 | * 62 | * @ingroup render 63 | */ 64 | class ORK_API TextureBuffer : public Texture 65 | { 66 | public: 67 | /** 68 | * Creates a new buffer texture. 69 | * 70 | * @param tf texture data format in 'pixels'. 71 | * @param pixels the buffer holding the texture's texel array. 72 | */ 73 | TextureBuffer(TextureInternalFormat tf, ptr pixels); 74 | 75 | /** 76 | * Destroys this buffer texture. 77 | */ 78 | virtual ~TextureBuffer(); 79 | 80 | /** 81 | * Returns the width of this texture. 82 | */ 83 | int getWidth(); 84 | 85 | /** 86 | * Returns the buffer holding the texture's texel array. 87 | */ 88 | ptr getBuffer(); 89 | 90 | protected: 91 | /** 92 | * The width of this texture. 93 | */ 94 | int w; 95 | 96 | /** 97 | * The buffer holding the texture's texel array. 98 | */ 99 | ptr b; 100 | }; 101 | 102 | } 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /ork/render/Types.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LarsFlaeten/ork/94464fd098a6c66e5b0798fd9f0400108c4221fa/ork/render/Types.h -------------------------------------------------------------------------------- /ork/resource/CompiledResourceLoader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/resource/CompiledResourceLoader.h" 43 | 44 | #include 45 | 46 | using namespace std; 47 | 48 | namespace ork 49 | { 50 | 51 | CompiledResourceLoader::StaticResourceDescriptor::StaticResourceDescriptor(const TiXmlElement *descriptor, unsigned char *data, unsigned int size) : 52 | ResourceDescriptor(descriptor, data, size) 53 | { 54 | } 55 | 56 | CompiledResourceLoader::StaticResourceDescriptor::~StaticResourceDescriptor() 57 | { 58 | } 59 | 60 | void CompiledResourceLoader::StaticResourceDescriptor::clearData() 61 | { 62 | } 63 | 64 | CompiledResourceLoader::CompiledResourceLoader(const string &resourceDataFile) : ResourceLoader() 65 | { 66 | ifstream fs(resourceDataFile.c_str(), ios::binary); 67 | fs.seekg(0, ios::end); 68 | unsigned int size = fs.tellg(); 69 | data = new unsigned char[size]; 70 | fs.seekg(0); 71 | fs.read((char*) data, size); 72 | fs.close(); 73 | } 74 | 75 | CompiledResourceLoader::~CompiledResourceLoader() 76 | { 77 | delete[] data; 78 | } 79 | 80 | string CompiledResourceLoader::findResource(const string &name) 81 | { 82 | return paths[name]; 83 | } 84 | 85 | ptr CompiledResourceLoader::loadResource(const string &name) 86 | { 87 | return resources[name]; 88 | } 89 | 90 | ptr CompiledResourceLoader::reloadResource(const string &name, ptr currentValue) 91 | { 92 | return NULL; 93 | } 94 | 95 | void CompiledResourceLoader::addPath(const string &name, const string &path) 96 | { 97 | paths.insert(make_pair(name, path)); 98 | } 99 | 100 | void CompiledResourceLoader::addResource(const string &name, ptr desc) 101 | { 102 | resources.insert(make_pair(name, desc)); 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /ork/resource/ResourceCompiler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/resource/ResourceCompiler.h" 43 | 44 | using namespace std; 45 | 46 | namespace ork 47 | { 48 | 49 | int resCounter = 0; 50 | 51 | int compile(TiXmlElement *e, ostream &out) 52 | { 53 | int p = resCounter++; 54 | out << "TiXmlElement *e" << p << " = new TiXmlElement(\"" << e->Value() << "\");" << endl; 55 | 56 | TiXmlAttribute *a = e->FirstAttribute(); 57 | while (a != NULL) { 58 | out << "e" << p << "->SetAttribute(\"" << a->Name() << "\", \"" << a->Value() << "\");" << endl; 59 | a = a->Next(); 60 | } 61 | 62 | TiXmlNode *n = e->FirstChild(); 63 | while (n != NULL) { 64 | TiXmlElement *f = n->ToElement(); 65 | if (f != NULL) { 66 | int c = compile(f, out); 67 | out << "e" << p << "->LinkEndChild(e" << c << ");" << endl; 68 | } 69 | n = n->NextSibling(); 70 | } 71 | 72 | return p; 73 | } 74 | 75 | void compile(unsigned char* data, unsigned int size, ostream &out, unsigned int &offset) 76 | { 77 | char c = 0; 78 | out.write((const char*) data, size); 79 | out.write(&c, 1); 80 | offset += size + 1; 81 | } 82 | 83 | ResourceCompiler::ResourceCompiler(const string &resourceFile, const string &resourceDataFile) : 84 | XMLResourceLoader(), 85 | out(resourceFile.c_str(), ios_base::out), 86 | dout(resourceDataFile.c_str(), ios_base::out | ios_base::binary), 87 | offset(0) 88 | { 89 | } 90 | 91 | ResourceCompiler::~ResourceCompiler() 92 | { 93 | out.close(); 94 | dout.close(); 95 | } 96 | 97 | string ResourceCompiler::findResource(const string &name) 98 | { 99 | string s = XMLResourceLoader::findResource(name); 100 | out << "addPath(\"" << name << "\", \"" << s << "\");" << endl; 101 | return s; 102 | } 103 | 104 | ptr ResourceCompiler::loadResource(const string &name) 105 | { 106 | ptr desc = XMLResourceLoader::loadResource(name); 107 | int a = compile((TiXmlElement*) desc->descriptor, out); 108 | if (desc->getData() != NULL) { 109 | unsigned int o = offset; 110 | compile(desc->getData(), desc->getSize(), dout, offset); 111 | out << "addResource(\"" << name << "\", new StaticResourceDescriptor(e" << a << ", data + " << o << ", " << desc->getSize() << "));" << endl; 112 | } else { 113 | out << "addResource(\"" << name << "\", new ResourceDescriptor(e" << a << ", NULL, 0));" << endl; 114 | } 115 | return desc; 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /ork/resource/ResourceCompiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_RESOURCE_COMPILER_H_ 43 | #define _ORK_RESOURCE_COMPILER_H_ 44 | 45 | #include 46 | 47 | #include "ork/resource/XMLResourceLoader.h" 48 | 49 | namespace ork 50 | { 51 | 52 | /** 53 | * An XMLResourceLoader that produces compiled resources for a 54 | * CompiledResourceLoader. This class concatenates and stores the 55 | * resources it loads into two files. The first file 56 | * contains source code that builds the XML descriptors of the resources. 57 | * The second file contains the %resource data (shader source code, texture 58 | * data, mesh data, etc). The first file can be included in the source code 59 | * of a CompiledResourceLoader subclass, and the second file can be passed 60 | * as argument to the constructor of this subclass: 61 | \code 62 | class MyResourceLoader : public CompiledResourceLoader 63 | { 64 | public: 65 | MyResourceLoader(const std::string &resourceDataFile) : 66 | CompiledResourceLoader(resourceDataFile) 67 | { 68 | #include "resourceFile" 69 | } 70 | }; 71 | \endcode 72 | * 73 | * @ingroup resource 74 | */ 75 | class ResourceCompiler : public XMLResourceLoader 76 | { 77 | public: 78 | /** 79 | * Creates a new ResourceCompiler. 80 | * 81 | * @param resourceFile the file that will contain the source code to build 82 | * the XML descriptors of the loaded resources. 83 | * @param resourceDataFile the file that will contain the data of the 84 | * loaded resources. 85 | */ 86 | ResourceCompiler(const std::string &resourceFile, const std::string &resourceDataFile); 87 | 88 | /** 89 | * Deletes this ResourceCompiler. 90 | */ 91 | virtual ~ResourceCompiler(); 92 | 93 | /** 94 | * Returns the path of the resource of the given name. 95 | * 96 | * @param name the name of a resource. 97 | * @return the path of this resource. 98 | * @throw exception if the resource is not found. 99 | */ 100 | virtual std::string findResource(const std::string &name); 101 | 102 | /** 103 | * Loads the ResourceDescriptor of the given name. 104 | * 105 | * @param name the name of the ResourceDescriptor to be loaded. 106 | * @return the ResourceDescriptor of the given name, or NULL if the %resource 107 | * is not found. 108 | */ 109 | virtual ptr loadResource(const std::string &name); 110 | 111 | private: 112 | /** 113 | * The stream to write into the resourceFile file. 114 | */ 115 | std::ofstream out; 116 | 117 | /** 118 | * The stream to write into the resourceDataFile file. 119 | */ 120 | std::ofstream dout; 121 | 122 | /** 123 | * The number of bytes currently written into dout. 124 | */ 125 | unsigned int offset; 126 | }; 127 | 128 | } 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /ork/resource/ResourceDescriptor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/resource/ResourceDescriptor.h" 43 | 44 | namespace ork 45 | { 46 | 47 | ResourceDescriptor::ResourceDescriptor(const TiXmlElement *descriptor, unsigned char *data, unsigned int size) : 48 | Object("ResourceDescriptor"), data(data), size(size) 49 | { 50 | this->descriptor = descriptor; 51 | assert(this->descriptor != NULL); 52 | } 53 | 54 | ResourceDescriptor::~ResourceDescriptor() 55 | { 56 | delete descriptor; 57 | clearData(); 58 | } 59 | 60 | unsigned char *ResourceDescriptor::getData() const 61 | { 62 | return data; 63 | } 64 | 65 | unsigned int ResourceDescriptor::getSize() const 66 | { 67 | return size; 68 | } 69 | 70 | void ResourceDescriptor::clearData() 71 | { 72 | if (data != NULL) { 73 | delete[] data; 74 | data = NULL; 75 | } 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /ork/resource/ResourceDescriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_RESOURCE_DESCRIPTOR_H_ 43 | #define _ORK_RESOURCE_DESCRIPTOR_H_ 44 | 45 | #include "ork/core/Object.h" 46 | 47 | #include "tinyxml/tinyxml.h" 48 | 49 | namespace ork 50 | { 51 | 52 | /** 53 | * A %resource descriptor, contains all the data to create an actual Resource. 54 | * This data is described with an XML element and with an optional ASCII or 55 | * binary data section. For example, for a texture, the XML part describes the 56 | * texture options (internal format, min and mag filter, min and max LOD, etc), 57 | * while the binary data part contains the texture data itself. For a shader 58 | * the XML part describes default values for the shader uniforms, while the 59 | * binary data part contains the shader source code. And so on for other 60 | * resources. 61 | * 62 | * @ingroup resource 63 | */ 64 | class ORK_API ResourceDescriptor : public Object 65 | { 66 | public: 67 | /** 68 | * The XML part of this %resource descriptor. This part can describe 69 | * optional elements that cannot be stored in the %resource itself, such as 70 | * the internal format for a texture, default uniform values for a shader, 71 | * etc. The tag of the descriptor is the type of the %resource (e.g. 72 | * texture1D, texture2D, shader, program, mesh, etc). 73 | */ 74 | const TiXmlElement *descriptor; 75 | 76 | /** 77 | * Creates a new %resource descriptor. 78 | * 79 | * @param descriptor the XML part of this %resource descriptor. 80 | * @param data the ASCII of binary data part of the descriptor. 81 | * @param size the size of the ASCII or binary part in bytes. 82 | */ 83 | ResourceDescriptor(const TiXmlElement *descriptor, unsigned char *data, unsigned int size); 84 | 85 | /** 86 | * Deletes this %resource descriptor. This deletes both the XML and the 87 | * binary data part. 88 | */ 89 | virtual ~ResourceDescriptor(); 90 | 91 | /** 92 | * Returns the ASCII or binary data part of this %resource descriptor. 93 | */ 94 | unsigned char *getData() const; 95 | 96 | /** 97 | * Returns the size in bytes of the ASCII or binary data part of this 98 | * %resource descriptor. 99 | */ 100 | unsigned int getSize() const; 101 | 102 | /** 103 | * Deletes the ASCII or binary data part of this %resource descriptor. 104 | */ 105 | virtual void clearData(); 106 | 107 | private: 108 | /** 109 | * The ASCII or binary data part of this %resource descriptor. 110 | */ 111 | unsigned char* data; 112 | 113 | /** 114 | * Size in bytes of the ASCII or binary data part of this %resource descriptor. 115 | */ 116 | unsigned int size; 117 | }; 118 | 119 | } 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /ork/resource/ResourceFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/resource/ResourceFactory.h" 43 | 44 | #include "ork/resource/ResourceManager.h" 45 | 46 | using namespace std; 47 | 48 | namespace ork 49 | { 50 | 51 | ResourceFactory *ResourceFactory::INSTANCE = NULL; 52 | 53 | ResourceFactory *ResourceFactory::getInstance() 54 | { 55 | if (INSTANCE == NULL) { 56 | INSTANCE = new ResourceFactory(); 57 | } 58 | return INSTANCE; 59 | } 60 | 61 | void ResourceFactory::addType(const string &type, createFunc f) 62 | { 63 | types[type] = f; 64 | } 65 | 66 | void ResourceFactory::dumpTypes() 67 | { 68 | std::map::iterator i; 69 | for(i = types.begin(); i != types.end(); ++i) 70 | cout << i->first << endl; 71 | 72 | 73 | } 74 | 75 | 76 | ptr ResourceFactory::create(ptr manager, const string &name, 77 | ptr desc, const TiXmlElement *e) 78 | { 79 | e = e == NULL ? desc->descriptor : e; 80 | map::iterator i = types.find(e->ValueStr()); 81 | if (i != types.end()) { 82 | return i->second(manager, name, desc, e); 83 | } else { 84 | if (Logger::ERROR_LOGGER != NULL) { 85 | Resource::log(Logger::ERROR_LOGGER, desc, e, "Unknown resource type '" + e->ValueStr() + "'"); 86 | } 87 | throw exception(); 88 | } 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /ork/resource/ResourceFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Copyright (c) 2008-2010 INRIA 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | /* 20 | * Authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 21 | */ 22 | 23 | #ifndef _ORK_RESOURCE_FACTORY_H_ 24 | #define _ORK_RESOURCE_FACTORY_H_ 25 | 26 | #include 27 | #include 28 | 29 | #include "ork/resource/Resource.h" 30 | 31 | namespace ork 32 | { 33 | 34 | /** 35 | * A Resource factory, creates resources from ResourceDescriptor. There is only 36 | * one instance of this class, which registers a creation function for each 37 | * %resource type name. 38 | * 39 | * @ingroup resource 40 | */ 41 | class ORK_API ResourceFactory 42 | { 43 | public: 44 | /** 45 | * A function that creates a Resource from a ResourceDescriptor. 46 | * 47 | * @param manager the manager that will manage the created %resource. 48 | * @param name the %resource name. 49 | * @param desc the %resource descriptor. 50 | * @param e an optional XML element providing contextual information (such 51 | * as the XML element in which the %resource descriptor was found). 52 | * @return the created %resource. 53 | */ 54 | typedef ptr (*createFunc) (ptr manager, const std::string &name, 55 | ptr desc, const TiXmlElement *e); 56 | 57 | /** 58 | * Returns the unique instance of this class. 59 | */ 60 | static ResourceFactory *getInstance(); 61 | 62 | /** 63 | * Registers a new %resource type with this factory. 64 | * 65 | * @param type a %resource type, as it appears in the tag of a 66 | * ResourceDescriptor (e.g. texture1D, texture2D, shader, program, etc). 67 | * @param f a function that can create %resources of this type. 68 | */ 69 | void addType(const std::string &type, createFunc f); 70 | 71 | /** 72 | * Creates a Resource from the given ResourceDescriptor. 73 | * 74 | * @param manager the manager that will manage the created %resource. 75 | * @param name the %resoure name. 76 | * @param desc the %resource descriptor. 77 | * @param e an optional XML element providing contextual information (such 78 | * as the XML element in which the %resource descriptor was found). 79 | * @return the created %resource. 80 | */ 81 | ptr create(ptr manager, const std::string &name, 82 | ptr desc, const TiXmlElement *e = NULL); 83 | 84 | /** 85 | * Utility function to dump all the types of resources 86 | * Used for debugging 87 | * TODO: remove? 88 | * */ 89 | 90 | void dumpTypes(); 91 | 92 | /** 93 | * A utility template to automate the registration of new %resource types. 94 | * @tparam t a %resource type (e.g. texture1D, shader, mesh, etc). 95 | * @tparam T the corresponding concrete Resource class. This class must be 96 | * instantiated for all resources of type t. 97 | */ 98 | template 99 | class Type 100 | { 101 | public: 102 | /** 103 | * Creation function for resources of class T. This function 104 | * just calls new T(manager, name, desc, e). 105 | * See ResourceFactory::createFunc 106 | */ 107 | static ptr ctor(ptr manager, const std::string &name, 108 | ptr desc, const TiXmlElement *e) 109 | { 110 | return new T(manager, name, desc, e); 111 | } 112 | 113 | /** 114 | * Creates a new Type instance. This constructor registers the creation 115 | * function #ctor (encapsulating a call to new T) with the %resource 116 | * type t in the ResourceFactory instance. Hence declaring a static 117 | * variable of type Type automatically registers a new %resource 118 | * type. 119 | */ 120 | Type() 121 | { 122 | ResourceFactory::getInstance()->addType(std::string(t), ctor); 123 | } 124 | }; 125 | 126 | private: 127 | /** 128 | * The registered creation functions. Maps %resource types (such as shader, 129 | * program, mesh, etc) to %resource creation functions. 130 | */ 131 | std::map types; 132 | 133 | /** 134 | * The unique instance of this class. 135 | */ 136 | static ResourceFactory *INSTANCE; 137 | }; 138 | 139 | } 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /ork/resource/ResourceLoader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/resource/ResourceLoader.h" 43 | 44 | namespace ork 45 | { 46 | 47 | ResourceLoader::ResourceLoader() : Object("ResourceLoader") 48 | { 49 | } 50 | 51 | ResourceLoader::~ResourceLoader() 52 | { 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /ork/resource/ResourceLoader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_RESOURCE_LOADER_H_ 43 | #define _ORK_RESOURCE_LOADER_H_ 44 | 45 | #include "ork/resource/ResourceDescriptor.h" 46 | 47 | namespace ork 48 | { 49 | 50 | /** 51 | * An abstract %resource loader, loads ResourceDescriptor from disk or other 52 | * locations. 53 | * 54 | * @ingroup resource 55 | */ 56 | class ORK_API ResourceLoader : public Object 57 | { 58 | public: 59 | /** 60 | * Creates a new %resource loader. 61 | */ 62 | ResourceLoader(); 63 | 64 | /** 65 | * Deletes this %resource loader. 66 | */ 67 | virtual ~ResourceLoader(); 68 | 69 | /** 70 | * Returns the path of the resource of the given name. 71 | * 72 | * @param name the name of a resource. 73 | * @return the path of this resource. 74 | * @throw exception if the resource is not found. 75 | */ 76 | virtual std::string findResource(const std::string &name) = 0; 77 | 78 | /** 79 | * Loads the ResourceDescriptor of the given name. 80 | * 81 | * @param name the name of the ResourceDescriptor to be loaded. 82 | * @return the ResourceDescriptor of the given name, or NULL if the %resource 83 | * is not found. 84 | */ 85 | virtual ptr loadResource(const std::string &name) = 0; 86 | 87 | /** 88 | * Reloads the ResourceDescriptor of the given name. 89 | * 90 | * @param name the name of the ResourceDescriptor to be loaded. 91 | * @param currentValue the current value of this ResourceDescriptor. 92 | * @return the new value of this ResourceDescriptor, or NULL if this value 93 | * has not changed. 94 | */ 95 | virtual ptr reloadResource(const std::string &name, ptr currentValue) = 0; 96 | }; 97 | 98 | } 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /ork/scenegraph/AbstractTask.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/scenegraph/AbstractTask.h" 43 | 44 | #include "ork/scenegraph/SceneManager.h" 45 | 46 | using namespace std; 47 | 48 | namespace ork 49 | { 50 | 51 | AbstractTask::AbstractTask(const char* type) : 52 | TaskFactory(type) 53 | { 54 | } 55 | 56 | AbstractTask::~AbstractTask() 57 | { 58 | } 59 | 60 | AbstractTask::QualifiedName::QualifiedName() 61 | { 62 | } 63 | 64 | AbstractTask::QualifiedName::QualifiedName(const string &n) 65 | { 66 | string::size_type i = n.find('.', 0); 67 | if (i != string::npos) { 68 | target = n.substr(0, i); 69 | name = n.substr(i + 1); 70 | } else { 71 | name = n; 72 | } 73 | } 74 | 75 | ptr AbstractTask::QualifiedName::getTarget(ptr context) 76 | { 77 | if (target.size() == 0) { 78 | return NULL; 79 | } else if (strcmp(target.c_str(), "this") == 0) { 80 | return context; 81 | } else if (target[0] == '$') { 82 | return context->getOwner()->getNodeVar(target.substr(1)); 83 | } else { 84 | SceneManager::NodeIterator i = context->getOwner()->getNodes(target); 85 | return i.hasNext() ? i.next() : NULL; 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /ork/scenegraph/AbstractTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_ABSTRACT_TASK_H_ 43 | #define _ORK_ABSTRACT_TASK_H_ 44 | 45 | #include "ork/taskgraph/TaskFactory.h" 46 | #include "ork/scenegraph/SceneNode.h" 47 | 48 | namespace ork 49 | { 50 | 51 | /** 52 | * An abstract task for a Method. A method "task" is in fact a TaskFactory that 53 | * creates Task. Indeed a new Task is created at each method invocation. 54 | * 55 | * @ingroup scenegraph 56 | */ 57 | class ORK_API AbstractTask : public TaskFactory 58 | { 59 | public: 60 | /** 61 | * Creates a new AbstractTask. 62 | * 63 | * @param type the task type. 64 | */ 65 | AbstractTask(const char* type); 66 | 67 | /** 68 | * Deletes this AbstractTask. 69 | */ 70 | virtual ~AbstractTask(); 71 | 72 | protected: 73 | /** 74 | * A qualified name of the form target.name. 75 | */ 76 | struct ORK_API QualifiedName { 77 | 78 | /** 79 | * The first part of this qualified name. The first part is optional. 80 | * It can be "this", "$v" or any scene node flag. 81 | */ 82 | std::string target; 83 | 84 | /** 85 | * The second part of this qualified name. 86 | */ 87 | std::string name; 88 | 89 | /** 90 | * Creates an empty qualified name. 91 | */ 92 | QualifiedName(); 93 | 94 | /** 95 | * Creates a qualified name. 96 | * 97 | * @param n a qualified name of the form target.name or 98 | * name. 99 | */ 100 | QualifiedName(const std::string &n); 101 | 102 | /** 103 | * Returns the SceneNode designated by this qualified name. 104 | * 105 | * @param context the scene graph into which the target SceneNode must 106 | * be looked for. 107 | */ 108 | ptr getTarget(ptr context); 109 | }; 110 | }; 111 | 112 | } 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /ork/scenegraph/CallMethodTask.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/scenegraph/CallMethodTask.h" 43 | 44 | #include "ork/resource/ResourceTemplate.h" 45 | #include "ork/taskgraph/TaskGraph.h" 46 | #include "ork/scenegraph/SceneManager.h" 47 | 48 | using namespace std; 49 | 50 | namespace ork 51 | { 52 | 53 | CallMethodTask::CallMethodTask() : AbstractTask("CallMethodTask") 54 | { 55 | } 56 | 57 | CallMethodTask::CallMethodTask(const QualifiedName &method) : 58 | AbstractTask("CallMethodTask") 59 | { 60 | init(method); 61 | } 62 | 63 | void CallMethodTask::init(const QualifiedName &method) 64 | { 65 | this->method = method; 66 | } 67 | 68 | CallMethodTask::~CallMethodTask() 69 | { 70 | } 71 | 72 | ptr CallMethodTask::getTask(ptr context) 73 | { 74 | ptr n = context.cast()->getOwner(); 75 | ptr target = method.getTarget(n); 76 | if (target != NULL) { 77 | ptr m = target->getMethod(method.name); 78 | if (m != NULL) { 79 | if (m->isEnabled()) { 80 | return m->getTask(); 81 | } else { 82 | return new TaskGraph(); 83 | } 84 | } 85 | } 86 | if (Logger::ERROR_LOGGER != NULL) { 87 | Logger::ERROR_LOGGER->log("SCENEGRAPH", "CallMethod: cannot find method '" + method.target + "." + method.name + "'"); 88 | } 89 | throw exception(); 90 | } 91 | 92 | void CallMethodTask::swap(ptr t) 93 | { 94 | std::swap(method, t->method); 95 | } 96 | 97 | /// @cond RESOURCES 98 | 99 | class CallMethodTaskResource : public ResourceTemplate<40, CallMethodTask> 100 | { 101 | public: 102 | CallMethodTaskResource(ptr manager, const string &name, ptr desc, const TiXmlElement *e = NULL) : 103 | ResourceTemplate<40, CallMethodTask>(manager, name, desc) 104 | { 105 | e = e == NULL ? desc->descriptor : e; 106 | checkParameters(desc, e, "name,"); 107 | string n = getParameter(desc, e, "name"); 108 | init(QualifiedName(n)); 109 | } 110 | }; 111 | 112 | extern const char callMethod[] = "callMethod"; 113 | 114 | static ResourceFactory::Type CallMethodTaskType; 115 | 116 | /// @endcond 117 | 118 | } 119 | -------------------------------------------------------------------------------- /ork/scenegraph/CallMethodTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_CALL_METHOD_TASK_H_ 43 | #define _ORK_CALL_METHOD_TASK_H_ 44 | 45 | #include "ork/scenegraph/AbstractTask.h" 46 | 47 | namespace ork 48 | { 49 | 50 | /** 51 | * An AbstractTask to execute a Method on a SceneNode. 52 | * @ingroup scenegraph 53 | */ 54 | class ORK_API CallMethodTask : public AbstractTask 55 | { 56 | public: 57 | /** 58 | * Creates a new CallMethodTask. 59 | * 60 | * @param method a "node.method" qualified name. The first part specifies 61 | * the scene node on which the method must be called. The second part 62 | * specifies the name of the method that must be called. 63 | */ 64 | CallMethodTask(const QualifiedName &method); 65 | 66 | /** 67 | * Deletes this CallMethodTask. 68 | */ 69 | virtual ~CallMethodTask(); 70 | 71 | virtual ptr getTask(ptr context); 72 | protected: 73 | 74 | /** 75 | * Creates an empty CallMethodTask. 76 | */ 77 | CallMethodTask(); 78 | 79 | /** 80 | * Initializes this CallMethodTask. 81 | * 82 | * @param method a "node.method" qualified name. The first part specifies 83 | * the scene node on which the method must be called. The second part 84 | * specifies the name of the method that must be called. 85 | */ 86 | void init(const QualifiedName &method); 87 | 88 | /** 89 | * Swaps this CallMethodTask with the given one. 90 | * 91 | * @param t a CallMethodTask. 92 | */ 93 | void swap(ptr t); 94 | 95 | private: 96 | /** 97 | * A "node.method" qualified name. The first part specifies the scene node 98 | * on which the method must be called. The second part specifies the name of 99 | * the method that must be called. 100 | */ 101 | QualifiedName method; 102 | }; 103 | 104 | } 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /ork/scenegraph/DrawMeshTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_DRAW_MESH_TASK_H_ 43 | #define _ORK_DRAW_MESH_TASK_H_ 44 | 45 | #include "ork/scenegraph/AbstractTask.h" 46 | 47 | namespace ork 48 | { 49 | 50 | /** 51 | * An AbstractTask to draw a mesh. The mesh is drawn using the current 52 | * framebuffer and the current program. 53 | * 54 | * @ingroup scenegraph 55 | */ 56 | class ORK_API DrawMeshTask : public AbstractTask 57 | { 58 | public: 59 | /** 60 | * Creates a new DrawMeshTask. 61 | * 62 | * @param mesh a "node.mesh" qualified name. The first part specifies the 63 | * scene node that contains the mesh. The second part specifies the 64 | * name of the mesh in this node. 65 | * @param count the number of time this mesh must be drawn. 66 | */ 67 | DrawMeshTask(const QualifiedName &mesh, int count = 1); 68 | 69 | /** 70 | * Deletes this DrawMeshTask. 71 | */ 72 | virtual ~DrawMeshTask(); 73 | 74 | virtual ptr getTask(ptr context); 75 | 76 | /** 77 | * Creates an empty DrawMeshTask. 78 | */ 79 | DrawMeshTask(); 80 | protected: 81 | /** 82 | * Initializes this DrawMeshTask. 83 | * 84 | * @param mesh a "node.mesh" qualified name. The first part specifies the 85 | * scene node that contains the mesh. The second part specifies the 86 | * name of the mesh in this node. 87 | * @param count the number of time this mesh must be drawn. 88 | */ 89 | void init(const QualifiedName &mesh, int count); 90 | 91 | /** 92 | * Swaps this DrawMeshTask with anoter one. 93 | * 94 | * @param t a DrawMeshTask. 95 | */ 96 | void swap(ptr t); 97 | 98 | private: 99 | /** 100 | * A "node.mesh" qualified name. The first part specifies the scene node 101 | * that contains the mesh. The second part specifies the name of the mesh in 102 | * this node. 103 | */ 104 | QualifiedName mesh; 105 | 106 | /** 107 | * The number of time the mesh must be drawn. 108 | */ 109 | int count; 110 | 111 | /** 112 | * A ork::Task to draw a mesh. 113 | */ 114 | class Impl : public Task 115 | { 116 | public: 117 | /** 118 | * The mesh that must be drawn. 119 | */ 120 | ptr m; 121 | 122 | /** 123 | * The number of time #m must be drawn. 124 | */ 125 | int count; 126 | 127 | /** 128 | * Creates a new DrawMeshTask::Impl task. 129 | * 130 | * @param m the mesh to be drawn. 131 | * @param count the number of time the mesh must be drawn. 132 | */ 133 | Impl(ptr m, int count); 134 | 135 | /** 136 | * Deletes this DrawMeshTask::Impl task. 137 | */ 138 | virtual ~Impl(); 139 | 140 | virtual bool run(); 141 | }; 142 | }; 143 | 144 | } 145 | 146 | #endif 147 | -------------------------------------------------------------------------------- /ork/scenegraph/LoopTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_LOOP_TASK_H_ 43 | #define _ORK_LOOP_TASK_H_ 44 | 45 | #include "ork/scenegraph/AbstractTask.h" 46 | 47 | namespace ork 48 | { 49 | 50 | /** 51 | * An AbstractTask to execute a task on a set of scene nodes. 52 | * @ingroup scenegraph 53 | */ 54 | class ORK_API LoopTask : public AbstractTask 55 | { 56 | public: 57 | /** 58 | * Creates a new LoopTask. 59 | * 60 | * @param var the loop variable name. 61 | * @param flag a flag that specifies the scene nodes to which the loop must 62 | * be applied. 63 | * @param cull true to apply the loop only on the visible scene nodes. 64 | * @param parallel true the apply the loop to all scene nodes in parallel. 65 | * @param subtask the task that must be executed on each SceneNode. 66 | */ 67 | LoopTask(const std::string &var, const std::string &flag, bool cull, bool parallel, ptr subtask); 68 | 69 | /** 70 | * Deletes this LoopTask. 71 | */ 72 | virtual ~LoopTask(); 73 | 74 | virtual ptr getTask(ptr context); 75 | 76 | protected: 77 | /** 78 | * Creates an empty LoopTask. 79 | */ 80 | LoopTask(); 81 | 82 | /** 83 | * Initializes this LoopTask. 84 | * 85 | * @param var the loo variable name. 86 | * @param flag a flag that specifies the scene nodes to which the loop must 87 | * be applied. 88 | * @param cull true to apply the loop only on the visible scene nodes. 89 | * @param parallel true the apply the loop to all scene nodes in parallel. 90 | * @param subtask the task that must be executed on each SceneNode. 91 | */ 92 | void init(const std::string &var, const std::string &flag, bool cull, bool parallel, ptr subtask); 93 | 94 | /** 95 | * Swaps this LoopTask with the given one. 96 | * 97 | * @param t a LoopTask. 98 | */ 99 | void swap(ptr t); 100 | 101 | private: 102 | /** 103 | * The loop variable name. 104 | */ 105 | std::string var; 106 | 107 | /** 108 | * The flag thatt specifies the scene nodes to which the loop must be applied. 109 | */ 110 | std::string flag; 111 | 112 | /** 113 | * True to apply the loop to all scene nodes in parallel. 114 | */ 115 | bool parallel; 116 | 117 | /** 118 | * True to apply the loop only on the visible scene nodes. 119 | */ 120 | bool cull; 121 | 122 | /** 123 | * The task that must be executed on each scene node. 124 | */ 125 | ptr subtask; 126 | }; 127 | 128 | } 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /ork/scenegraph/Method.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/scenegraph/Method.h" 43 | 44 | #include "ork/scenegraph/SceneNode.h" 45 | 46 | namespace ork 47 | { 48 | 49 | Method::Method(ptr body) : Object("Method"), enabled(true) 50 | { 51 | taskFactory = body; 52 | } 53 | 54 | Method::~Method() 55 | { 56 | } 57 | 58 | ptr Method::getOwner() 59 | { 60 | return owner; 61 | } 62 | 63 | bool Method::isEnabled() 64 | { 65 | return enabled; 66 | } 67 | 68 | void Method::setIsEnabled(bool enabled) 69 | { 70 | this->enabled = enabled; 71 | } 72 | 73 | ptr Method::getTaskFactory() 74 | { 75 | return taskFactory; 76 | } 77 | 78 | void Method::setTaskFactory(ptr taskFactory) 79 | { 80 | this->taskFactory = taskFactory; 81 | } 82 | 83 | ptr Method::getTask() 84 | { 85 | return taskFactory->getTask(this); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /ork/scenegraph/Method.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Copyright (c) 2008-2010 INRIA 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | /* 20 | * Authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 21 | */ 22 | 23 | #ifndef _ORK_METHOD_H_ 24 | #define _ORK_METHOD_H_ 25 | 26 | #include "ork/taskgraph/TaskFactory.h" 27 | 28 | namespace ork 29 | { 30 | 31 | class SceneNode; 32 | 33 | /** 34 | * A SceneNode method. A Method defines a behavior of a scene node. It can be a 35 | * basic task or a combination of basic tasks using sequences, loops or method 36 | * calls. The body of a method is TaskFactory that can be shared between 37 | * several methods. This TaskFactory is used to get the tasks to be run to 38 | * execute the method, depending on the context (the context passed to 39 | * TaskFactory#getTask being the Method itself, from which the owner SceneNode 40 | * can be found, and then then owner SceneManager). 41 | * 42 | * @ingroup scenegraph 43 | */ 44 | class ORK_API Method : public Object 45 | { 46 | public: 47 | /** 48 | * Creates a new Method using the given basic or compound task. 49 | * 50 | * @param body the method definition. 51 | */ 52 | Method(ptr body); 53 | 54 | /** 55 | * Deletes this method. 56 | */ 57 | virtual ~Method(); 58 | 59 | /** 60 | * Returns the SceneNode to which this Method belongs. 61 | * See SceneNode#getMethod. 62 | */ 63 | ptr getOwner(); 64 | 65 | /** 66 | * Returns true if this method is enabled. A call to disabled method is 67 | * skipped. A method is enabled by default. 68 | */ 69 | bool isEnabled(); 70 | 71 | /** 72 | * Enables or disables this method. A call to disabled method is skipped. 73 | * 74 | * @param enabled true to enable this method, false to disable it. 75 | */ 76 | void setIsEnabled(bool enabled); 77 | 78 | /** 79 | * Returns the body of this method. 80 | */ 81 | ptr getTaskFactory(); 82 | 83 | /** 84 | * Sets the body of this method. 85 | * 86 | * @param taskFactory the new method body. 87 | */ 88 | void setTaskFactory(ptr taskFactory); 89 | 90 | /** 91 | * Returns the Task to be run to execute this method. 92 | */ 93 | ptr getTask(); 94 | 95 | private: 96 | /** 97 | * The SceneNode to which this Method belongs. 98 | */ 99 | SceneNode *owner; 100 | 101 | /** 102 | * True if this method is enabled. 103 | */ 104 | bool enabled; 105 | 106 | /** 107 | * The body of this method. 108 | */ 109 | ptr taskFactory; 110 | 111 | friend class SceneNode; 112 | }; 113 | 114 | } 115 | 116 | #endif 117 | -------------------------------------------------------------------------------- /ork/scenegraph/SequenceTask.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Copyright (c) 2008-2010 INRIA 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | /* 20 | * Authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 21 | */ 22 | 23 | #include "ork/scenegraph/SequenceTask.h" 24 | 25 | #include "ork/resource/ResourceTemplate.h" 26 | #include "ork/taskgraph/TaskGraph.h" 27 | #include "ork/scenegraph/SceneManager.h" 28 | 29 | using namespace std; 30 | 31 | namespace ork 32 | { 33 | 34 | SequenceTask::SequenceTask() : AbstractTask("SequenceTask") 35 | { 36 | } 37 | 38 | SequenceTask::SequenceTask(const vector< ptr > &subtasks) : 39 | AbstractTask("SequenceTask") 40 | { 41 | init(subtasks); 42 | } 43 | 44 | void SequenceTask::init(const vector< ptr > &subtasks) 45 | { 46 | this->subtasks = subtasks; 47 | } 48 | 49 | SequenceTask::~SequenceTask() 50 | { 51 | } 52 | 53 | ptr SequenceTask::getTask(ptr context) 54 | { 55 | if (subtasks.size() == 1) { 56 | return subtasks[0]->getTask(context); 57 | } else { 58 | ptr result = new TaskGraph(); 59 | ptr prev = NULL; 60 | for (unsigned int i = 0; i < subtasks.size(); ++i) { 61 | try { 62 | ptr next = subtasks[i]->getTask(context); 63 | if (next.cast() == NULL || !next.cast()->isEmpty()) { 64 | result->addTask(next); 65 | if (prev != NULL) { 66 | result->addDependency(next, prev); 67 | } 68 | prev = next; 69 | } 70 | } catch (...) { 71 | } 72 | } 73 | return result; 74 | } 75 | } 76 | 77 | void SequenceTask::swap(ptr t) 78 | { 79 | std::swap(subtasks, t->subtasks); 80 | } 81 | 82 | /// @cond RESOURCES 83 | 84 | class SequenceTaskResource : public ResourceTemplate<40, SequenceTask> 85 | { 86 | public: 87 | SequenceTaskResource(ptr manager, const string &name, ptr desc, const TiXmlElement *e = NULL) : 88 | ResourceTemplate<40, SequenceTask>(manager, name, desc) 89 | { 90 | e = e == NULL ? desc->descriptor : e; 91 | checkParameters(desc, e, "name,"); 92 | vector< ptr > subtasks; 93 | const TiXmlNode *n = e->FirstChild(); 94 | while (n != NULL) { 95 | const TiXmlElement *f = n->ToElement(); 96 | if (f != NULL) { 97 | ptr tf; 98 | tf = ResourceFactory::getInstance()->create(manager, "", desc, f).cast(); 99 | subtasks.push_back(tf); 100 | } 101 | n = n->NextSibling(); 102 | } 103 | init(subtasks); 104 | } 105 | }; 106 | 107 | extern const char sequence[] = "sequence"; 108 | 109 | static ResourceFactory::Type SequenceTaskType; 110 | 111 | /// @endcond 112 | 113 | } 114 | -------------------------------------------------------------------------------- /ork/scenegraph/SequenceTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_SEQUENCE_TASK_H_ 43 | #define _ORK_SEQUENCE_TASK_H_ 44 | 45 | #include "ork/scenegraph/AbstractTask.h" 46 | 47 | namespace ork 48 | { 49 | 50 | /** 51 | * An AbstractTask to compose a list of tasks in a sequence. 52 | * @ingroup scenegraph 53 | */ 54 | class ORK_API SequenceTask : public AbstractTask 55 | { 56 | public: 57 | /** 58 | * Creates a SequenceTask with the given list of tasks. 59 | * 60 | * @param subtasks the tasks that must be composed into a sequence. 61 | */ 62 | SequenceTask(const std::vector< ptr > &subtasks); 63 | 64 | /** 65 | * Deletes this SequenceTask. 66 | */ 67 | virtual ~SequenceTask(); 68 | 69 | virtual ptr getTask(ptr context); 70 | 71 | protected: 72 | /** 73 | * Creates an empty SequenceTask. 74 | */ 75 | SequenceTask(); 76 | 77 | /** 78 | * Initializes this SequenceTask with the given list of tasks. 79 | * 80 | * @param subtasks the tasks that must be composed into a sequence. 81 | */ 82 | void init(const std::vector< ptr > &subtasks); 83 | 84 | /** 85 | * Swaps this SequenceTask with another one. 86 | * 87 | * @param t a SequenceTask. 88 | */ 89 | void swap(ptr t); 90 | 91 | private: 92 | /** 93 | * The tasks that are composed sequentially by this task. 94 | */ 95 | std::vector< ptr > subtasks; 96 | }; 97 | 98 | } 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /ork/scenegraph/SetProgramTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Copyright (c) 2008-2010 INRIA 4 | * 5 | * This library is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or (at 8 | * your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 13 | * for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public License 16 | * along with this library; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | /* 20 | * Authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 21 | */ 22 | 23 | #ifndef _ORK_SET_PROGRAM_TASK_H_ 24 | #define _ORK_SET_PROGRAM_TASK_H_ 25 | 26 | #include "ork/render/Program.h" 27 | #include "ork/scenegraph/AbstractTask.h" 28 | 29 | namespace ork 30 | { 31 | 32 | /** 33 | * An AbstractTask to set a program. 34 | * @ingroup scenegraph 35 | */ 36 | class ORK_API SetProgramTask : public AbstractTask 37 | { 38 | public: 39 | /** 40 | * Creates a SetProgramTask. 41 | * 42 | * @param modules the modules of the program to be set. Each module is 43 | * specified by a "node.module" qualified name. The first part 44 | * specifies the scene node that contains the module. The second part 45 | * specifies the name of the module in this node. 46 | * @param setUniforms true to set the uniforms of the program, using the 47 | * values defined in the scene node from which this task is called. 48 | */ 49 | SetProgramTask(const std::vector &modules, bool setUniforms); 50 | 51 | /** 52 | * Deletes this SetProgramTask. 53 | */ 54 | virtual ~SetProgramTask(); 55 | 56 | virtual ptr getTask(ptr context); 57 | 58 | protected: 59 | /** 60 | * Creates an uninitialized SetProgramTask. 61 | */ 62 | SetProgramTask(); 63 | 64 | /** 65 | * Initializes this SetProgramTask. 66 | * 67 | * @param modules the modules of the program to be set. Each module is 68 | * specified by a "node.module" qualified name. The first part 69 | * specifies the scene node that contains the module. The second part 70 | * specifies the name of the module in this node. 71 | * @param setUniforms true to set the uniforms of the program, using the 72 | * values defined in the scene node from which this task is called. 73 | */ 74 | void init(const std::vector &modules, bool setUniforms); 75 | 76 | /** 77 | * Swaps this SetProgramTask with the given one. 78 | * 79 | * @param t a SetProgramTask. 80 | */ 81 | void swap(ptr t); 82 | 83 | private: 84 | /** 85 | * The modules of the program to be set. Each module is specified by a 86 | * "node.module" qualified name. The first part specifies the scene node 87 | * that contains the module. The second part specifies the name of the 88 | * module in this node. 89 | */ 90 | std::vector modules; 91 | 92 | /** 93 | * True to set the uniforms of the program, using the values defined 94 | * in the scene node from which this task is called. 95 | */ 96 | bool setUniforms; 97 | 98 | /** 99 | * A ork::Task to set a program. 100 | */ 101 | class Impl : public Task 102 | { 103 | public: 104 | /** 105 | * The program to be set. 106 | */ 107 | ptr p; 108 | 109 | /** 110 | * The scene node whose uniforms must be in #p. 111 | */ 112 | ptr n; 113 | 114 | /** 115 | * Creates a new SetProgramTask:Impl. 116 | * 117 | * @param p the program to be set. 118 | * @param n the scene node whose uniforms must be in #p. 119 | */ 120 | Impl(ptr p, ptr n); 121 | 122 | /** 123 | * Deletes this SetProgramTask::Impl. 124 | */ 125 | virtual ~Impl(); 126 | 127 | virtual bool run(); 128 | }; 129 | }; 130 | 131 | } 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /ork/scenegraph/ShowLogTask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_SHOW_LOG_TASK_H_ 43 | #define _ORK_SHOW_LOG_TASK_H_ 44 | 45 | #include "ork/scenegraph/ShowInfoTask.h" 46 | 47 | namespace ork 48 | { 49 | 50 | /** 51 | * A ShowInfoTask sub class to display the ork::Logger messages. 52 | * @ingroup scenegraph 53 | */ 54 | class ORK_API ShowLogTask : public ShowInfoTask 55 | { 56 | public: 57 | /** 58 | * True if this task is enabled. When disabled the message logs are not 59 | * displayed. 60 | */ 61 | static bool enabled; 62 | 63 | /** 64 | * Creates a new ShowLogTask. 65 | * 66 | * @param f the Font used to display Text. 67 | * @param p the program to be used to draw characters. 68 | * @param fontHeight the used font height. 69 | * @param pos x,y position and maximum number of lines of text to display. 70 | */ 71 | ShowLogTask(ptr f, ptr p, float fontHeight, vec3i pos); 72 | 73 | /** 74 | * Deletes this ShowLogTask. 75 | */ 76 | virtual ~ShowLogTask(); 77 | 78 | protected: 79 | /** 80 | * Creates an uninitialized ShowLogTask. 81 | */ 82 | ShowLogTask(); 83 | 84 | /** 85 | * Initializes this ShowLogTask. 86 | * 87 | * @param f the Font used to display Text. 88 | * @param p the program to be used to draw characters. 89 | * @param fontHeight the used font height. 90 | * @param pos x,y position and maximum number of lines of text to display. 91 | */ 92 | virtual void init(ptr f, ptr p, float fontHeight, vec3i pos); 93 | 94 | virtual void draw(ptr context); 95 | }; 96 | 97 | } 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /ork/taskgraph/Scheduler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/taskgraph/Scheduler.h" 43 | 44 | namespace ork 45 | { 46 | 47 | Scheduler::Scheduler(const char* type) : Object(type) 48 | { 49 | } 50 | 51 | Scheduler::~Scheduler() 52 | { 53 | } 54 | 55 | void Scheduler::swap(ptr s) 56 | { 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /ork/taskgraph/Scheduler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_SCHEDULER_H_ 43 | #define _ORK_SCHEDULER_H_ 44 | 45 | #include "ork/taskgraph/Task.h" 46 | 47 | namespace ork 48 | { 49 | 50 | /** 51 | * An abstract scheduler, sorts and executes tasks with one or more threads. 52 | * @ingroup taskgraph 53 | */ 54 | class ORK_API Scheduler : public Object 55 | { 56 | public: 57 | /** 58 | * Creates a new scheduler. 59 | * 60 | * @param type the type of this scheduler. 61 | */ 62 | Scheduler(const char *type); 63 | 64 | /** 65 | * Deletes this scheduler. 66 | */ 67 | virtual ~Scheduler(); 68 | 69 | /** 70 | * Returns true if this scheduler can execute CPU or GPU tasks whose 71 | * deadline is not immediate. This means tasks whose result will be needed 72 | * in the next few frames, but that are known in advance and could be 73 | * computed ahead of time to reduce the load of these coming frames. 74 | * 75 | * @param gpuTasks true to know if this scheduler can prefetch GPU tasks, 76 | * or false to know if it can prefetch CPU tasks. 77 | * @return true if this scheduler can prefetch GPU (resp. CPU) tasks, if 78 | * gpuTasks is true (resp. false). 79 | */ 80 | virtual bool supportsPrefetch(bool gpuTasks) = 0; 81 | 82 | /** 83 | * Adds a task whose deadline is not immediate. This method must not be 84 | * called if this scheduler does not support prefetch (see 85 | * #supportsPrefetch). Otherwise it adds this task and its sub tasks to the 86 | * list of tasks to be executed by this scheduler, and returns immediately 87 | * (i.e. before these tasks are executed). 88 | * 89 | * @param task a task or task graph whose deadline is not immediate. 90 | */ 91 | virtual void schedule(ptr task) = 0; 92 | 93 | /** 94 | * Forces the reexecution of the given task and of its sub tasks. 95 | * 96 | * @param task a task or task graph that must be reexecuted. This task is marked 97 | * as undone (with Task#setIsDone) so that it will be reexecuted. 98 | * @param r the reason why the task must be reexecuted. 99 | * @param deadline the frame number before which this task must be 100 | * reexecuted. 101 | */ 102 | virtual void reschedule(ptr task, Task::reason r, unsigned int deadline) = 0; 103 | 104 | /** 105 | * Executes the given tasks. This method does not return before all tasks 106 | * with an immediate deadline are completed. 107 | * 108 | * @param task a task or task graph to be executed. 109 | */ 110 | virtual void run(ptr task) = 0; 111 | 112 | protected: 113 | /** 114 | * Swaps this scheduler with the given one. 115 | */ 116 | void swap(ptr s); 117 | }; 118 | 119 | } 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /ork/taskgraph/TaskFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/taskgraph/TaskFactory.h" 43 | 44 | namespace ork 45 | { 46 | 47 | TaskFactory::TaskFactory(const char *type) : Object(type) 48 | { 49 | } 50 | 51 | TaskFactory::~TaskFactory() 52 | { 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /ork/taskgraph/TaskFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_TASK_GRAPH_FACTORY_H_ 43 | #define _ORK_TASK_GRAPH_FACTORY_H_ 44 | 45 | #include "ork/taskgraph/Task.h" 46 | 47 | namespace ork 48 | { 49 | 50 | /** 51 | * An object that can create Task. 52 | * @ingroup taskgraph 53 | */ 54 | class ORK_API TaskFactory : public Object 55 | { 56 | public: 57 | /** 58 | * Creates a new task factory. 59 | * 60 | * @param type the type of this factory. 61 | */ 62 | TaskFactory(const char* type); 63 | 64 | /** 65 | * Deletes this task factory. 66 | */ 67 | virtual ~TaskFactory(); 68 | 69 | /** 70 | * Creates a new task. 71 | * 72 | * @param context an optional parameter to control the task creation. 73 | * @return the created task. 74 | */ 75 | virtual ptr getTask(ptr context) = 0; 76 | }; 77 | 78 | } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /ork/ui/DebugCallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "DebugCallback.h" 43 | 44 | #include "ork/core/Logger.h" 45 | 46 | #include 47 | 48 | #include 49 | 50 | #include 51 | 52 | #ifndef CALLBACK 53 | #define CALLBACK 54 | #endif 55 | 56 | using namespace std; 57 | 58 | namespace ork 59 | { 60 | 61 | void CALLBACK debugCallback(unsigned int source, unsigned int type, 62 | unsigned int id, unsigned int severity, 63 | int length, const char* message, const void* userParam) 64 | { 65 | char debSource[16]; 66 | switch (source) { 67 | case GL_DEBUG_SOURCE_API_ARB: 68 | strcpy(debSource, "OPENGL"); 69 | break; 70 | case GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB: 71 | strcpy(debSource, "WINDOWS"); 72 | break; 73 | case GL_DEBUG_SOURCE_SHADER_COMPILER_ARB: 74 | strcpy(debSource, "COMPILER"); 75 | break; 76 | case GL_DEBUG_SOURCE_THIRD_PARTY_ARB: 77 | strcpy(debSource, "LIBRARY"); 78 | break; 79 | case GL_DEBUG_SOURCE_APPLICATION_ARB: 80 | strcpy(debSource, "APPLICATION"); 81 | break; 82 | //case GL_DEBUG_SOURCE_OTHER_ARB: 83 | default: 84 | strcpy(debSource, "UNKNOWN"); 85 | } 86 | 87 | char debType[20]; 88 | switch (type) { 89 | case GL_DEBUG_TYPE_ERROR_ARB: 90 | strcpy(debType, "Error"); 91 | break; 92 | case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: 93 | strcpy(debType, "Deprecated behavior"); 94 | break; 95 | case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: 96 | strcpy(debType, "Undefined behavior"); 97 | break; 98 | case GL_DEBUG_TYPE_PORTABILITY_ARB: 99 | strcpy(debType, "Portability"); 100 | break; 101 | case GL_DEBUG_TYPE_PERFORMANCE_ARB: 102 | strcpy(debType, "Performance"); 103 | break; 104 | //case GL_DEBUG_TYPE_OTHER_ARB: 105 | default: 106 | strcpy(debType, "Other"); 107 | } 108 | 109 | if (severity == GL_DEBUG_SEVERITY_HIGH_ARB && Logger::ERROR_LOGGER != NULL) { 110 | Logger::ERROR_LOGGER->logf(debSource, "%s: %s", debType, message); 111 | } 112 | if (severity == GL_DEBUG_SEVERITY_MEDIUM_ARB && Logger::WARNING_LOGGER != NULL) { 113 | Logger::WARNING_LOGGER->logf(debSource, "%s: %s", debType, message); 114 | } 115 | if (severity == GL_DEBUG_SEVERITY_LOW_ARB && Logger::INFO_LOGGER != NULL) { 116 | Logger::INFO_LOGGER->logf(debSource, "%s: %s", debType, message); 117 | } 118 | } 119 | 120 | 121 | } 122 | 123 | -------------------------------------------------------------------------------- /ork/ui/DebugCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | #ifndef DEBUGCALLBACK_H_INCLUDED 42 | #define DEBUGCALLBACK_H_INCLUDED 43 | 44 | #ifndef CALLBACK 45 | #define CALLBACK 46 | #endif 47 | 48 | namespace ork 49 | { 50 | 51 | void CALLBACK debugCallback(unsigned int source, unsigned int type, 52 | unsigned int id, unsigned int severity, 53 | int length, const char* message, const void* userParam); 54 | 55 | } 56 | 57 | #endif // DEBUGCALLBACK_H_INCLUDED 58 | -------------------------------------------------------------------------------- /ork/ui/EventHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/ui/EventHandler.h" 43 | 44 | namespace ork 45 | { 46 | 47 | EventHandler::EventHandler(const char *type) : Object(type) 48 | { 49 | } 50 | 51 | EventHandler::~EventHandler() 52 | { 53 | } 54 | 55 | void EventHandler::redisplay(double t, double dt) 56 | { 57 | } 58 | 59 | void EventHandler::reshape(int x, int y) 60 | { 61 | } 62 | 63 | void EventHandler::idle(bool damaged) 64 | { 65 | } 66 | 67 | bool EventHandler::mouseClick(button b, state s, modifier m, int x, int y) 68 | { 69 | return false; 70 | } 71 | 72 | bool EventHandler::mouseWheel(wheel b, modifier m, int x, int y) 73 | { 74 | return false; 75 | } 76 | 77 | bool EventHandler::mouseMotion(int x, int y) 78 | { 79 | return false; 80 | } 81 | 82 | bool EventHandler::mousePassiveMotion(int x, int y) 83 | { 84 | return false; 85 | } 86 | 87 | bool EventHandler::keyTyped(unsigned char c, modifier m, int x, int y) 88 | { 89 | return false; 90 | } 91 | 92 | bool EventHandler::keyReleased(unsigned char c, modifier m, int x, int y) 93 | { 94 | return false; 95 | } 96 | 97 | bool EventHandler::specialKey(key k, modifier m, int x, int y) 98 | { 99 | return false; 100 | } 101 | 102 | bool EventHandler::specialKeyReleased(key k, modifier m, int x, int y) 103 | { 104 | return false; 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /ork/ui/Window.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #include "ork/ui/Window.h" 43 | 44 | using namespace std; 45 | 46 | namespace ork 47 | { 48 | 49 | Window::Parameters::Parameters() : 50 | _name("Untitled"), _width(640), _height(480), _major(3), _minor(3), 51 | _debug(false), _alpha(false), _depth(false), _stencil(false), _multiSample(false) 52 | { 53 | } 54 | 55 | string Window::Parameters::name() const 56 | { 57 | return _name; 58 | } 59 | 60 | int Window::Parameters::width() const 61 | { 62 | return _width; 63 | } 64 | 65 | int Window::Parameters::height() const 66 | { 67 | return _height; 68 | } 69 | 70 | vec2 Window::Parameters::version() const 71 | { 72 | return vec2(_major, _minor); 73 | } 74 | 75 | bool Window::Parameters::debug() const 76 | { 77 | return _debug; 78 | } 79 | 80 | bool Window::Parameters::alpha() const 81 | { 82 | return _alpha; 83 | } 84 | 85 | bool Window::Parameters::depth() const 86 | { 87 | return _depth; 88 | } 89 | 90 | bool Window::Parameters::stencil() const 91 | { 92 | return _stencil; 93 | } 94 | 95 | bool Window::Parameters::multiSample() const 96 | { 97 | return _multiSample; 98 | } 99 | 100 | Window::Parameters &Window::Parameters::name(const string name) 101 | { 102 | _name = name; 103 | return *this; 104 | } 105 | 106 | Window::Parameters &Window::Parameters::size(int width, int height) 107 | { 108 | _width = width; 109 | _height = height; 110 | return *this; 111 | } 112 | 113 | Window::Parameters &Window::Parameters::version(int major, int minor, bool debug) 114 | { 115 | _major = major; 116 | _minor = minor; 117 | _debug = debug; 118 | return *this; 119 | } 120 | 121 | Window::Parameters &Window::Parameters::alpha(bool alpha) 122 | { 123 | _alpha = alpha; 124 | return *this; 125 | } 126 | 127 | Window::Parameters &Window::Parameters::depth(bool depth) 128 | { 129 | _depth = depth; 130 | return *this; 131 | } 132 | 133 | Window::Parameters &Window::Parameters::stencil(bool stencil) 134 | { 135 | _stencil = stencil; 136 | return *this; 137 | } 138 | 139 | Window::Parameters &Window::Parameters::multiSample(bool multiSample) 140 | { 141 | _multiSample = multiSample; 142 | return *this; 143 | } 144 | 145 | Window::Window(const Parameters ¶ms) : EventHandler("Window") 146 | { 147 | } 148 | 149 | Window::~Window() 150 | { 151 | } 152 | 153 | } 154 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | set(EXENAME ork-test) 4 | 5 | # Sources 6 | include_directories("${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/libraries" "${CMAKE_CURRENT_SOURCE_DIR}") 7 | file(GLOB SOURCE_FILES *.cpp) 8 | 9 | add_definitions("-DORK_API=") 10 | 11 | add_executable(${EXENAME} ${SOURCE_FILES}) 12 | target_link_libraries(${EXENAME} ork) 13 | 14 | -------------------------------------------------------------------------------- /test/Test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ork: a small object-oriented OpenGL Rendering Kernel. 3 | * Website : http://ork.gforge.inria.fr/ 4 | * Copyright (c) 2008-2015 INRIA - LJK (CNRS - Grenoble University) 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * 3. Neither the name of the copyright holder nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 24 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 28 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 | * OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | */ 32 | /* 33 | * Ork is distributed under the BSD3 Licence. 34 | * For any assistance, feedback and remarks, you can check out the 35 | * mailing list on the project page : 36 | * http://ork.gforge.inria.fr/ 37 | */ 38 | /* 39 | * Main authors: Eric Bruneton, Antoine Begault, Guillaume Piolat. 40 | */ 41 | 42 | #ifndef _ORK_TEST_ 43 | #define _ORK_TEST_ 44 | 45 | #include 46 | #include 47 | 48 | typedef void (*testFunction)(); 49 | 50 | class TestSuite 51 | { 52 | public: 53 | std::vector tests; 54 | 55 | std::vector testNames; 56 | 57 | std::vector testVersions; 58 | 59 | static TestSuite *getInstance(); 60 | 61 | private: 62 | static TestSuite *INSTANCE; 63 | }; 64 | 65 | class Test 66 | { 67 | public: 68 | Test(const char *name, testFunction test, int majorVersion = 3); 69 | }; 70 | 71 | void test(bool result, const char* file, int line); 72 | 73 | #define TEST(x) void x(); Test _##x(#x, x); void x() 74 | 75 | #define TEST4(x) void x(); Test _##x(#x, x, 4); void x() 76 | 77 | #define ASSERT(x) test(x, __FILE__, __LINE__) 78 | 79 | #endif 80 | --------------------------------------------------------------------------------