Stellarium 0.12.3
StelViewportEffect.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2010 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (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 General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELVIEWPORTEFFECT_HPP_
21 #define _STELVIEWPORTEFFECT_HPP_
22 
23 
24 #include <QSizeF>
25 
26 #include "VecMath.hpp"
27 #include "StelProjector.hpp"
28 #include "renderer/StelVertexAttribute.hpp"
29 #include "renderer/StelVertexBuffer.hpp"
30 
31 class QGLFramebufferObject;
32 
36 {
37 public:
38  virtual ~StelViewportEffect() {;}
39  virtual QString getName() = 0;
40 
45  virtual void drawToViewport(class StelRenderer* renderer) = 0;
48  virtual void distortXY(float& x, float& y) const {Q_UNUSED(x); Q_UNUSED(y);}
49 };
50 
51 
53 {
54 public:
55  StelViewportDistorterFisheyeToSphericMirror(int screenWidth, int screenHeight,
56  class StelRenderer* renderer);
58  virtual QString getName() {return "sphericMirrorDistorter";}
59  virtual void drawToViewport(class StelRenderer* renderer);
60  virtual void distortXY(float& x, float& y) const;
61 private:
62 
63  struct Vertex
64  {
65  Vec2f position;
66  Vec2f texCoord;
67  Vec4f color;
68 
69  VERTEX_ATTRIBUTES(Vec2f Position, Vec2f TexCoord, Vec4f Color);
70  };
71  const int screenWidth;
72  const int screenHeight;
73  const StelProjector::StelProjectorParams originalProjectorParams;
74  StelProjector::StelProjectorParams newProjectorParams;
75  // Dimensions of the auxiliary mirror texture (used to be texture_wh,
76  // because the texture used to be square); now used for convenience. --BM
77  int texture_w;
78  int texture_h;
79 
84  QSizeF maxTexCoords;
85 
90  Vec2f* texCoordGrid;
91 
92  int maxGridX,maxGridY;
93  double stepX,stepY;
94 
96  StelVertexBuffer<Vertex>* vertexGrid;
98  QVector<class StelIndexBuffer*> stripBuffers;
99 
100  void constructVertexBuffer(StelRenderer* renderer);
101  void generateDistortion(const class QSettings& conf, const StelProjectorP& proj,
102  const double distorterMaxFOV, class StelRenderer* renderer);
103 
110  void loadGenerationParameters(const QSettings& conf, double& gamma);
111  bool loadDistortionFromFile(const QString & fileName, class StelRenderer *renderer);
112 
123  void recalculateTexCoords(const QSizeF newMaxTexCoords);
124 };
125 #endif // _STELVIEWPORTEFFECT_HPP_
126