/***************************************************************************************** * * * OpenSpace * * * * Copyright (c) 2014-2025 * * * * 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. * ****************************************************************************************/ #include #include #include #include #include #include #include #include namespace openspace { documentation::Documentation RenderableTexturePlane::Documentation() { documentation::Documentation doc = RenderableTextureCygnet::Documentation(); doc.name = "RenderableTexturePlane"; doc.id = "iswa_renderable_textureplane"; return doc; } RenderableTexturePlane::RenderableTexturePlane(const ghoul::Dictionary& dictionary) : RenderableTextureCygnet(dictionary) {} void RenderableTexturePlane::initializeGL() { RenderableTextureCygnet::initializeGL(); if (!_shader) { _shader = global::renderEngine->buildRenderProgram( "PlaneProgram", absPath("${MODULE_ISWA}/shaders/textureplane_vs.glsl"), absPath("${MODULE_ISWA}/shaders/textureplane_fs.glsl") ); } } void RenderableTexturePlane::deinitializeGL() { _shader = nullptr; RenderableTextureCygnet::deinitializeGL(); } void RenderableTexturePlane::setUniforms() { ghoul::opengl::TextureUnit unit; unit.activate(); _textures[0]->bind(); _shader->setUniform("texture1", unit); _shader->setUniform("transparency", _alpha.value()); } bool RenderableTexturePlane::createGeometry() { glGenVertexArrays(1, &_quad); // generate array glGenBuffers(1, &_vertexPositionBuffer); // generate buffer // ============================ // GEOMETRY (quad) // ============================ float s = _data.spatialScale.x; const GLfloat x = s * _data.scale.x / 2.f; const GLfloat y = s * _data.scale.y / 2.f; const GLfloat z = s * _data.scale.z / 2.f; const GLfloat w = _data.spatialScale.w; const GLfloat vertex_data[] = { // square of two triangles (sigh) // x y z w s t -x, -y, -z, w, 0, 1, x, y, z, w, 1, 0, -x, ((x>0)?y:-y), z, w, 0, 0, -x, -y, -z, w, 0, 1, x, ((x>0)?-y:y), -z, w, 1, 1, x, y, z, w, 1, 0, }; glBindVertexArray(_quad); // bind array glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); // bind buffer glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, nullptr); glEnableVertexAttribArray(1); glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, reinterpret_cast(sizeof(GLfloat) * 4) ); return true; } bool RenderableTexturePlane::destroyGeometry() { glDeleteVertexArrays(1, &_quad); _quad = 0; glDeleteBuffers(1, &_vertexPositionBuffer); _vertexPositionBuffer = 0; return true; } void RenderableTexturePlane::renderGeometry() const { glBindVertexArray(_quad); glDrawArrays(GL_TRIANGLES, 0, 6); } } // namespace openspace