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
27 #include <GL/Extensions/GLARBShaderObjects.h>
28 #include <GL/GLObject.h>
29 #include <GL/GLGeometryVertex.h>
33 /* Forward declarations: */
36 class WaterRenderer
: public GLObject
{
37 /* Embedded classes: */
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
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: */
56 virtual ~DataItem(void);
60 const WaterTable2
* waterTable
; // Water table whose water surface is rendered
61 unsigned int bathymetryGridSize
[2]; // Size of vertex-centered bathymetry grid
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
67 tangentGridTransform
; // Transposed tangent plane transformation from grid space to world space
69 /* Constructors and destructors: */
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;
78 void render(const PTransform
& projection
, const OGTransform
& modelview
,
79 GLContextData
& contextData
) const; // Renders the water surface