summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/tilebuf.h
diff options
context:
space:
mode:
authorEnne Walker <ennewalker@users.sourceforge.net>2010-01-17 19:33:07 -0500
committerEnne Walker <ennewalker@users.sourceforge.net>2010-01-17 19:53:13 -0500
commit227420e531ae481224410978e01c834507cc61d2 (patch)
tree93b0bbe0f909bb20820a61e1836df1bb03736636 /crawl-ref/source/tilebuf.h
parentf903462645b80653998fe987732752038be862d4 (diff)
downloadcrawl-ref-227420e531ae481224410978e01c834507cc61d2.tar.gz
crawl-ref-227420e531ae481224410978e01c834507cc61d2.zip
Tile transparency in water without overlays.
In order for jpeg's waves to work on deep water as well as shallow, we need to not use partially transparent overlays to simulate an actor or an item being submerged. Now, non-flying objects on water will be drawn transparently to blend with the water below. This should mostly look the same, except it will now work on top of waves and will not require a mask for each water type. As a nice side-effect, ghosts are now transparent again and the water on top of submerged objects now animates properly. See the comments in tilebuf.cc for details. The mask tile itself can be adjusted to change the water level, but the parameters to SubmergedTileBuffer will need to be changed to compensate depending on what the new art looks like.
Diffstat (limited to 'crawl-ref/source/tilebuf.h')
-rw-r--r--crawl-ref/source/tilebuf.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/crawl-ref/source/tilebuf.h b/crawl-ref/source/tilebuf.h
index c13e9cec91..ee315a6eca 100644
--- a/crawl-ref/source/tilebuf.h
+++ b/crawl-ref/source/tilebuf.h
@@ -8,6 +8,34 @@
#include "tiles.h"
+// This struct defines all of the state that any particular rendering needs.
+// If other rendering states are needed, they should be added here so that
+// they do not introduce unneeded side effects for other parts of the code
+// that have not thought about turning that new state off.
+struct GLState
+{
+ GLState();
+
+ // vertex arrays
+ bool array_vertex;
+ bool array_texcoord;
+ bool array_colour;
+
+ // render state
+ bool blend;
+ bool texture;
+ bool depthtest;
+ bool alphatest;
+ unsigned char alpharef;
+};
+
+class GLStateManager
+{
+public:
+ static void init();
+ static void set(const GLState& state);
+};
+
class FTFont;
class formatted_string;
class GenericTexture;
@@ -41,6 +69,16 @@ struct PTCVert
VColour col;
};
+struct P3TCVert
+{
+ float pos_x;
+ float pos_y;
+ float pos_z;
+ float tex_x;
+ float tex_y;
+ VColour col;
+};
+
struct PTVert
{
float pos_x;
@@ -70,9 +108,14 @@ public:
V& get_next();
void draw() const;
+ GLState &state() { return m_state; }
+
protected:
+ void init_state();
+
const GenericTexture *m_tex;
int m_prim;
+ GLState m_state;
};
class FontBuffer : public VertBuffer<PTCVert>
@@ -99,6 +142,51 @@ public:
void set_tex(const TilesTexture *tex);
};
+class ColouredTileBuffer : public VertBuffer<P3TCVert>
+{
+public:
+ ColouredTileBuffer(const TilesTexture *tex = NULL);
+
+ void add(int idx, int x, int y, int z,
+ int ox, int oy, int ymin, int ymax,
+ int alpha_top, int alpha_bottom);
+};
+
+// Helper class for tiles submerged in water.
+class SubmergedTileBuffer
+{
+public:
+ // mask_idx is the tile index in tex of the mask texture
+ // It should be opaque white for water and fully transparent above.
+ //
+ // above_max is the maximum height (from the top of the tile) where
+ // there are still pixels above water.
+ //
+ // below_min is the minimum height (from the top of the tile) where
+ // there are still pixels below water.
+ //
+ // All heights are from 0 (top of the tile) to TILE_Y-1 (bottom of the tile)
+ SubmergedTileBuffer(const TilesTexture *tex,
+ int mask_idx, int above_max, int below_min);
+
+ void add(int idx, int x, int y, int z = 0, bool submerged = false,
+ bool ghost = false, int ox = 0, int oy = 0, int ymax = -1);
+
+ void draw() const;
+ void clear();
+
+protected:
+ int m_mask_idx;
+ int m_above_max;
+ int m_below_min;
+
+ int m_max_z;
+
+ ColouredTileBuffer m_below_water;
+ ColouredTileBuffer m_mask;
+ ColouredTileBuffer m_above_water;
+};
+
class ShapeBuffer : public VertBuffer<PCVert>
{
public:
@@ -121,6 +209,7 @@ template<class V>
inline VertBuffer<V>::VertBuffer(const GenericTexture *tex, int prim) :
m_tex(tex), m_prim(prim)
{
+ init_state();
}
template<class V>