2023-07-10 15:23:19 +00:00
|
|
|
#ifndef BBGE_RENDERGRID_H
|
|
|
|
#define BBGE_RENDERGRID_H
|
|
|
|
|
|
|
|
#include "Vector.h"
|
|
|
|
#include "DataStructures.h"
|
2023-08-09 00:41:04 +00:00
|
|
|
#include "VertexBuffer.h"
|
|
|
|
#include "Texture.h" // TexCoordBox
|
2023-07-10 15:23:19 +00:00
|
|
|
|
|
|
|
struct RenderState;
|
|
|
|
|
|
|
|
enum GridDrawOrder
|
|
|
|
{
|
|
|
|
GRID_DRAW_LRTB = 0, // the default. ignores grid.z
|
|
|
|
GRID_DRAW_LRBT = 1, // Y axis inverted
|
2023-07-11 02:39:55 +00:00
|
|
|
GRID_DRAW_WORLDMAP = 2, // LRTB order, uses grid.z as alpha
|
2023-07-10 15:23:19 +00:00
|
|
|
|
|
|
|
GRID_DRAW_DEFAULT = GRID_DRAW_LRTB
|
|
|
|
};
|
|
|
|
|
|
|
|
enum GridType
|
|
|
|
{
|
2023-07-11 02:39:55 +00:00
|
|
|
GRID_UNDEFINED = 0,
|
|
|
|
GRID_WAVY = 1,
|
|
|
|
GRID_STRIP = 2, // quad is in strip mode
|
|
|
|
GRID_INTERP = 3, // quad is in grid mode
|
2023-07-10 15:23:19 +00:00
|
|
|
};
|
|
|
|
|
2023-08-09 00:41:04 +00:00
|
|
|
// simple render grid, must be manually uploaded to GPU if changed
|
2023-07-10 15:23:19 +00:00
|
|
|
class RenderGrid
|
|
|
|
{
|
|
|
|
public:
|
2023-08-09 00:41:04 +00:00
|
|
|
RenderGrid();
|
2023-07-10 15:23:19 +00:00
|
|
|
~RenderGrid();
|
2023-08-09 00:41:04 +00:00
|
|
|
void dropBuffers();
|
2023-07-10 15:23:19 +00:00
|
|
|
|
2023-08-25 12:07:11 +00:00
|
|
|
void init(size_t w, size_t h);
|
2023-08-09 00:41:04 +00:00
|
|
|
void init(size_t w, size_t h, const TexCoordBox& tc);
|
2023-08-25 19:49:16 +00:00
|
|
|
void reset01();
|
2023-07-10 15:23:19 +00:00
|
|
|
void reset();
|
|
|
|
void resetWithAlpha(float a);
|
2023-08-09 00:41:04 +00:00
|
|
|
void render(const RenderState& rs) const;
|
2023-07-10 15:23:19 +00:00
|
|
|
void renderDebugPoints(const RenderState& rs) const;
|
|
|
|
void setAlpha(size_t x, size_t y, float a);
|
2023-08-09 00:41:04 +00:00
|
|
|
void setDrawOrder(GridDrawOrder ord, bool force = false);
|
|
|
|
inline GridDrawOrder getDrawOrder() const { return GridDrawOrder(drawOrder); }
|
|
|
|
void setTexCoords(const TexCoordBox& tc);
|
|
|
|
const TexCoordBox& getTexCoords() const { return tc; }
|
2023-07-10 15:23:19 +00:00
|
|
|
|
2023-08-09 00:41:04 +00:00
|
|
|
bool empty() const { return !(width() | height()); }
|
2023-07-10 15:23:19 +00:00
|
|
|
size_t width() const { return grid.width(); }
|
|
|
|
size_t height() const { return grid.height(); }
|
|
|
|
size_t linearsize() const { return grid.linearsize(); }
|
|
|
|
const Vector *data() const { return grid.data(); }
|
|
|
|
Vector *data() { return grid.data(); }
|
|
|
|
Array2d<Vector>& array2d() { return grid; }
|
|
|
|
const Array2d<Vector>& array2d() const { return grid; }
|
2023-08-09 00:41:04 +00:00
|
|
|
const DynamicGPUBuffer& getVBO() const { return vbo; }
|
|
|
|
void updateVBO();
|
2023-08-25 12:07:11 +00:00
|
|
|
void updateVBOIfNecessary();
|
2023-07-10 15:23:19 +00:00
|
|
|
|
|
|
|
static void ResetWithAlpha(Vector* dst, size_t w, size_t h, float alpha);
|
|
|
|
|
|
|
|
protected:
|
2023-08-09 00:41:04 +00:00
|
|
|
DynamicGPUBuffer indexbuf, vbo;
|
|
|
|
size_t trisToDraw;
|
2023-07-10 15:23:19 +00:00
|
|
|
Array2d<Vector> grid;
|
2023-08-09 00:41:04 +00:00
|
|
|
TexCoordBox tc;
|
|
|
|
|
|
|
|
void render_Indexed(const RenderState& rs) const;
|
|
|
|
void render_WithAlpha(const RenderState& rs) const;
|
|
|
|
|
|
|
|
public:
|
2023-08-25 12:07:11 +00:00
|
|
|
bool needVBOUpdate;
|
2023-08-09 00:41:04 +00:00
|
|
|
GridDrawOrder drawOrder;
|
|
|
|
};
|
|
|
|
|
|
|
|
// supports animation and automatic upload
|
|
|
|
class DynamicRenderGrid : public RenderGrid
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DynamicRenderGrid();
|
|
|
|
~DynamicRenderGrid();
|
|
|
|
|
|
|
|
void update(float dt);
|
|
|
|
|
|
|
|
void setSegs(float dgox, float dgoy, float dgmx, float dgmy, float dgtm, bool dgo);
|
|
|
|
void setStripPoints(bool vert, const Vector *points, size_t n);
|
|
|
|
void setFromWavy(const float *wavy, size_t len, float width);
|
|
|
|
|
|
|
|
protected:
|
2023-07-10 15:23:19 +00:00
|
|
|
float gridTimer;
|
|
|
|
float drawGridOffsetX;
|
|
|
|
float drawGridOffsetY;
|
|
|
|
float drawGridModX;
|
|
|
|
float drawGridModY;
|
|
|
|
float drawGridTimeMultiplier;
|
|
|
|
bool drawGridOut;
|
|
|
|
public:
|
|
|
|
unsigned char gridType; // unsigned char to save space
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|