temp commit
[SARndbox.git] / WaterRenderer.h
blob7b3e9765c2df8af96ffd660e8bf75c98cb3db36d
1 /***********************************************************************
2 WaterRenderer - Class to render a water surface defined by regular grids
3 of vertex-centered bathymetry and cell-centered water level values.
4 Copyright (c) 2014 Oliver Kreylos
6 This file is part of the Augmented Reality Sandbox (SARndbox).
8 The Augmented Reality Sandbox is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The Augmented Reality Sandbox is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with the Augmented Reality Sandbox; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ***********************************************************************/
23 #ifndef WATERRENDERER_INCLUDED
24 #define WATERRENDERER_INCLUDED
26 #include <GL/gl.h>
27 #include <GL/Extensions/GLARBShaderObjects.h>
28 #include <GL/GLObject.h>
29 #include <GL/GLGeometryVertex.h>
31 #include "Types.h"
33 /* Forward declarations: */
34 class WaterTable2;
36 class WaterRenderer: public GLObject {
37 /* Embedded classes: */
38 private:
39 typedef GLGeometry::Vertex<void, 0, void, 0, void, GLfloat, 2>
40 Vertex; // Type for template vertices
42 struct DataItem: public GLObject::DataItem { // Structure storing per-context OpenGL state
43 /* Elements: */
44 public:
46 /* OpenGL state management: */
47 GLuint vertexBuffer; // ID of vertex buffer object holding water surface's template vertices
48 GLuint indexBuffer; // ID of index buffer object holding water surface's triangles
50 /* GLSL shader management: */
51 GLhandleARB waterShader; // Shader program to render the water surface
52 GLint waterShaderUniforms[5]; // Locations of the water shader's uniform variables
54 /* Constructors and destructors: */
55 DataItem(void);
56 virtual ~DataItem(void);
59 /* Elements: */
60 const WaterTable2* waterTable; // Water table whose water surface is rendered
61 unsigned int bathymetryGridSize[2]; // Size of vertex-centered bathymetry grid
62 unsigned int
63 waterGridSize[2]; // Size of cell-centered water level grid; one cell larger than bathymetry grid
64 GLfloat cellSize[2]; // Cell size of the bathymetry and water level grids in world coordinate units
65 PTransform gridTransform; // Vertex transformation from grid space to world space
66 PTransform
67 tangentGridTransform; // Transposed tangent plane transformation from grid space to world space
69 /* Constructors and destructors: */
70 public:
71 WaterRenderer(const WaterTable2*
72 sWaterTable); // Creates a water renderer for the given water table
74 /* Methods from GLObject: */
75 virtual void initContext(GLContextData& contextData) const;
77 /* New methods: */
78 void render(const PTransform& projection, const OGTransform& modelview,
79 GLContextData& contextData) const; // Renders the water surface
82 #endif