Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfFlat3D.h
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
20/*
21Derived from Magnum with the following notice:
22
23 Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
24 2020, 2021 Vladimír Vondruš <mosra@centrum.cz>
25
26 Permission is hereby granted, free of charge, to any person obtaining a
27 copy of this software and associated documentation files (the "Software"),
28 to deal in the Software without restriction, including without limitation
29 the rights to use, copy, modify, merge, publish, distribute, sublicense,
30 and/or sell copies of the Software, and to permit persons to whom the
31 Software is furnished to do so, subject to the following conditions:
32
33 The above copyright notice and this permission notice shall be included
34 in all copies or substantial portions of the Software.
35
36 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
39 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
41 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
42 DEALINGS IN THE SOFTWARE.
43*/
44
45#ifndef _SOURCE_SHADERS_TFFLAT3D_H_
46#define _SOURCE_SHADERS_TFFLAT3D_H_
47
48#include <Magnum/DimensionTraits.h>
49#include <Magnum/GL/AbstractShaderProgram.h>
50#include <Magnum/Shaders/Generic.h>
51#include <Magnum/Shaders/visibility.h>
52
53
54using namespace Magnum;
55
56
58
59
60 class Flat3D: public GL::AbstractShaderProgram {
61 public:
65 typedef typename Magnum::Shaders::Generic3D::Position Position;
66
70 typedef typename Magnum::Shaders::Generic3D::TextureCoordinates TextureCoordinates;
71
75 typedef typename Magnum::Shaders::Generic3D::Color3 Color3;
76
80 typedef typename Magnum::Shaders::Generic3D::Color4 Color4;
81
82 #ifndef MAGNUM_TARGET_GLES2
86 typedef typename Magnum::Shaders::Generic3D::ObjectId ObjectId;
87 #endif
88
92 typedef typename Magnum::Shaders::Generic3D::TransformationMatrix TransformationMatrix;
93
97 typedef typename Magnum::Shaders::Generic3D::TextureOffset TextureOffset;
98
99 enum: UnsignedInt {
103 ColorOutput = Magnum::Shaders::Generic3D::ColorOutput,
104
105 #ifndef MAGNUM_TARGET_GLES2
109 ObjectIdOutput = Magnum::Shaders::Generic3D::ObjectIdOutput
110 #endif
111 };
112
113 enum class Flag: UnsignedByte {
114 Textured = 1 << 0,
115 AlphaMask = 1 << 1,
116 VertexColor = 1 << 2,
117 TextureTransformation = 1 << 3,
118 #ifndef MAGNUM_TARGET_GLES2
119 ObjectId = 1 << 4,
120 InstancedObjectId = (1 << 5)|ObjectId,
121 #endif
122 InstancedTransformation = 1 << 6,
123 InstancedTextureOffset = (1 << 7)|TextureTransformation
124 };
125
126 typedef Containers::EnumSet<Flag> Flags;
127
132 explicit Flat3D(Flags flags = {}, unsigned clipPlaneCount = 0);
133
137 explicit Flat3D(NoCreateT) noexcept: GL::AbstractShaderProgram{NoCreate} {}
138
140 Flat3D(const Flat3D&) = delete;
141
143 Flat3D(Flat3D&&) noexcept = default;
144
146 Flat3D& operator=(const Flat3D&) = delete;
147
149 Flat3D& operator=(Flat3D&&) noexcept = default;
150
152 Flags flags() const { return _flags; }
153
160 Flat3D& setTransformationProjectionMatrix(const MatrixTypeFor<3, Float>& matrix);
161
166 Flat3D& setTextureMatrix(const Matrix3& matrix);
167
172 Flat3D& setColor(const Magnum::Color4& color);
173
178 Flat3D& bindTexture(GL::Texture2D& texture);
179
184 Flat3D& setAlphaMask(Float mask);
185
190 Flat3D& setclipPlaneEquation(UnsignedInt id, const Vector4& position);
191
192 #ifndef MAGNUM_TARGET_GLES2
197 Flat3D& setObjectId(UnsignedInt id);
198 #endif
199
200 unsigned clipPlaneCount() const {
201 return _clipPlaneCount;
202 }
203
204 private:
205 /* Prevent accidentally calling irrelevant functions */
206 #ifndef MAGNUM_TARGET_GLES
207 using GL::AbstractShaderProgram::drawTransformFeedback;
208 #endif
209 #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
210 using GL::AbstractShaderProgram::dispatchCompute;
211 #endif
212
213 Flags _flags;
214 Int _transformationProjectionMatrixUniform{0},
215 _textureMatrixUniform{1},
216 _colorUniform{2},
217 _alphaMaskUniform{3};
218 #ifndef MAGNUM_TARGET_GLES2
219 Int _objectIdUniform{4};
220 #endif
221 Int _clipPlanesUniform{5};
222
223 UnsignedInt _clipPlaneCount{0};
224 };
225
226 MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, Flat3D::Flag value);
227 MAGNUM_SHADERS_EXPORT Debug& operator<<(Debug& debug, Flat3D::Flags value);
228 CORRADE_ENUMSET_OPERATORS(Flat3D::Flags)
229
230}
231
232#endif // _SOURCE_SHADERS_TFFLAT3D_H_
Definition tfFlat3D.h:60
Magnum::Shaders::Generic3D::Color3 Color3
Three-component vertex color.
Definition tfFlat3D.h:75
Flat3D(Flat3D &&) noexcept=default
Move constructor.
Magnum::Shaders::Generic3D::ObjectId ObjectId
(Instanced) object ID
Definition tfFlat3D.h:86
Flat3D & setclipPlaneEquation(UnsignedInt id, const Vector4 &position)
Set clip plane equation for given clip plane.
Flat3D(const Flat3D &)=delete
Copying is not allowed.
@ ColorOutput
Definition tfFlat3D.h:103
@ ObjectIdOutput
Definition tfFlat3D.h:109
Magnum::Shaders::Generic3D::TextureCoordinates TextureCoordinates
2D texture coordinates
Definition tfFlat3D.h:70
Flat3D(Flags flags={}, unsigned clipPlaneCount=0)
Constructor.
Flat3D & setTextureMatrix(const Matrix3 &matrix)
Set texture coordinate transformation matrix.
Magnum::Shaders::Generic3D::Color4 Color4
Four-component vertex color.
Definition tfFlat3D.h:80
Flags flags() const
Flags.
Definition tfFlat3D.h:152
Magnum::Shaders::Generic3D::TransformationMatrix TransformationMatrix
(Instanced) transformation matrix
Definition tfFlat3D.h:92
Flat3D(NoCreateT) noexcept
Construct without creating the underlying OpenGL object.
Definition tfFlat3D.h:137
Magnum::Shaders::Generic3D::Position Position
Vertex position.
Definition tfFlat3D.h:65
Flat3D & bindTexture(GL::Texture2D &texture)
Bind a color texture.
Magnum::Shaders::Generic3D::TextureOffset TextureOffset
(Instanced) texture offset
Definition tfFlat3D.h:97
Flat3D & setAlphaMask(Float mask)
Set alpha mask value.
Flat3D & setColor(const Magnum::Color4 &color)
Set color.
Flat3D & setObjectId(UnsignedInt id)
Set object ID.
Flat3D & setTransformationProjectionMatrix(const MatrixTypeFor< 3, Float > &matrix)
Set transformation and projection matrix.
Tissue Forge shaders.
Definition tfFlat3D.h:57