RayZaler 0.1
The free opto-mechanical simulation framework
Obstruction.h
1//
2// Copyright (c) 2024 Gonzalo José Carracedo Carballal
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Lesser General Public License as
6// published by the Free Software Foundation, either version 3 of the
7// License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Lesser General Public License for more details.
13//
14// You should have received a copy of the GNU Lesser General Public
15// License along with this program. If not, see
16// <http://www.gnu.org/licenses/>
17//
18
19#ifndef _OBSTRUCTION_H
20#define _OBSTRUCTION_H
21
22#include <OpticalElement.h>
23#include <MediumBoundaries/Obstruction.h>
24#include <GLHelpers.h>
25
26namespace RZ {
27 class TranslatedFrame;
28
29 struct Vertex {
30 float vertexCoords[3];
31 float texCoords[2];
32 };
33
34 class Obstruction : public OpticalElement {
35 ObstructionBoundary *m_boundary;
36 GLDisc m_disc;
37 TranslatedFrame *m_stopSurface = nullptr;
38 std::vector<Real> m_obstructionMap;
39 GLShader *m_alphaTestShader = nullptr;
40 GLuint m_verCoordAttrib = 0;
41 GLuint m_texCoordAttrib = 0;
42 GLuint m_textureUniformId = 0;
43 GLuint m_colorUniformId = 0;
44
45 std::string m_path;
46 bool m_openGlInitilized = false;
47 unsigned int m_cols = 0;
48 unsigned int m_rows = 0;
49 unsigned int m_stride = 0;
50
51 Real m_halfMapWidth = 0;
52 Real m_halfMapHeight = 0;
53 Real m_radius = 1e-2;
54
55 Vertex m_obsVertices[4];
56 uint16_t m_obsIndices[12] = {0, 1, 2, 2, 3, 0, 0, 3, 2, 2, 1, 0};
57 std::vector<uint8_t> m_textureData;
58 GLuint m_textureId;
59 GLuint m_vaoId;
60 GLuint m_vboId;
61 GLuint m_iboId;
62 bool m_texDirty = false;
63
64 void recalcModel();
65 void setFromPNG(std::string const &path);
66 void rebuildTexture();
67 void initOpenGLObjects();
68 void uploadAll();
69
70 protected:
71 virtual bool propertyChanged(std::string const &, PropertyValue const &) override;
72
73 public:
76 std::string const &,
78 Element *parent = nullptr);
79
80 virtual ~Obstruction() override;
81
82 virtual void nativeMaterialOpenGL(std::string const &) override;
83 virtual void renderOpenGL() override;
84 virtual void enterOpenGL() override;
85 };
86
87 RZ_DECLARE_OPTICAL_ELEMENT(Obstruction);
88}
89
90#endif // _OBSTRUCTION_H
Definition: Element.h:393
Definition: Element.h:173
Definition: GLHelpers.h:100
Definition: GLHelpers.h:45
Definition: Obstruction.h:27
Definition: Obstruction.h:34
Definition: OpticalElement.h:87
Definition: Element.h:58
Definition: ReferenceFrame.h:59
Definition: TranslatedFrame.h:25
Definition: Obstruction.h:29