/***************************************************************************************** * * * OpenSpace * * * * Copyright (c) 2014-2023 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * * without restriction, including without limitation the rights to use, copy, modify, * * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * * permit persons to whom the Software is furnished to do so, subject to the following * * conditions: * * * * The above copyright notice and this permission notice shall be included in all copies * * or substantial portions of the Software. * * * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ #ifndef __OPENSPACE_CORE___HELPER___H__ #define __OPENSPACE_CORE___HELPER___H__ #include namespace ghoul::opengl { class ProgramObject; class Texture; } // namespace ghoul::opengl namespace openspace { class LightSource; struct RenderData; } // namespace openspace namespace openspace::rendering::helper { enum class Anchor { Center, NW, NE, SW, SE }; void initialize(); void deinitialize(); glm::mat4 ortho(const glm::vec2& position, const glm::vec2& size, Anchor anchor = Anchor::NW); void renderBox(ghoul::opengl::ProgramObject& program, GLint orthoLocation, GLint colorLocation, const glm::vec2& position, const glm::vec2& size, const glm::vec4& color, Anchor anchor = Anchor::NW); void renderBox(const glm::vec2& position, const glm::vec2& size, const glm::vec4& color, Anchor anchor = Anchor::NW); void renderBox(const glm::vec2& position, const glm::vec2& size, const glm::vec4& color, const ghoul::opengl::Texture& texture, Anchor anchor = Anchor::NW); struct Shaders { struct { std::unique_ptr program; UniformCache(tex, hasTexture, shouldFlipTexture, proj, color) cache; } xyuvrgba; struct { std::unique_ptr program; UniformCache(tex, hasTexture, shouldFlipTexture, proj, color) cache; } screenfilling; }; struct VertexObjects { struct { GLuint vao = 0; GLuint vbo = 0; } square; struct { GLuint vao = 0; GLuint vbo = 0; GLuint ibo = 0; int nElements = 64; } sphere; struct { GLuint vao = 0; } empty; }; namespace detail { Shaders& gShadersConstructor(); VertexObjects& gVertexObjectsConstructor(); } // namespace detail static Shaders& shaders = detail::gShadersConstructor(); static VertexObjects& vertexObjects = detail::gVertexObjectsConstructor(); struct Vertex { GLfloat xyz[3]; GLfloat uv[2]; GLfloat rgba[4]; }; struct VertexXYZ { GLfloat xyz[3]; }; struct VertexXYZNormal { GLfloat xyz[3]; GLfloat normal[3]; }; VertexXYZ convertToXYZ(const Vertex& v); std::vector convert(std::vector v); std::vector createRing(int nSegments, float radius, glm::vec4 colors = glm::vec4(1.f)); std::pair, std::vector> createSphere(int nSegments, glm::vec3 radii, glm::vec4 colors = glm::vec4(1.f)); /** * Data structure that can be used for rendering using multiple light directions */ struct LightSourceRenderData { unsigned int nLightSources = 0; // Buffers for uniform uploading std::vector intensitiesBuffer; std::vector directionsViewSpaceBuffer; void updateBasedOnLightSources(const RenderData& renderData, const std::vector>& sources); }; } // namespace openspace::rendering::helper #endif // __OPENSPACE_CORE___HELPER___H__