2014-11-16 03:10:44 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Kai Jourdan. All rights reserved.
|
2016-01-01 11:11:04 +03:00
|
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
2014-11-16 03:10:44 +03:00
|
|
|
*/
|
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
#ifndef __VECTORDISPLAY_H__
|
|
|
|
#define __VECTORDISPLAY_H__
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2015-09-19 06:16:24 +03:00
|
|
|
#include <bgfx/bgfx.h>
|
2014-11-16 03:10:44 +03:00
|
|
|
|
|
|
|
#include <tinystl/allocator.h>
|
|
|
|
#include <tinystl/vector.h>
|
|
|
|
namespace stl = tinystl;
|
|
|
|
|
2016-04-20 06:31:37 +03:00
|
|
|
struct PosColorUvVertex
|
|
|
|
{
|
|
|
|
float m_x;
|
|
|
|
float m_y;
|
|
|
|
float m_z;
|
|
|
|
float m_u;
|
|
|
|
float m_v;
|
|
|
|
uint32_t m_abgr;
|
|
|
|
|
|
|
|
static void init();
|
2019-08-17 20:35:21 +03:00
|
|
|
static bgfx::VertexLayout ms_layout;
|
2016-04-20 06:31:37 +03:00
|
|
|
};
|
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
class VectorDisplay
|
2014-11-16 03:10:44 +03:00
|
|
|
{
|
2014-11-16 04:19:14 +03:00
|
|
|
public:
|
2017-06-16 23:10:30 +03:00
|
|
|
VectorDisplay();
|
2014-11-16 04:19:14 +03:00
|
|
|
|
|
|
|
~VectorDisplay()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-16 23:10:30 +03:00
|
|
|
void init(bool _originBottomLeft, float _texelHalf);
|
2019-02-08 05:04:28 +03:00
|
|
|
|
2017-03-13 04:25:23 +03:00
|
|
|
void setup(uint16_t _width, uint16_t _height, uint8_t _view = 2);
|
2014-11-16 04:19:14 +03:00
|
|
|
void resize(uint16_t _width, uint16_t _height);
|
|
|
|
void teardown();
|
|
|
|
|
|
|
|
void beginFrame();
|
|
|
|
void endFrame();
|
|
|
|
|
|
|
|
// Draw a series of connected line segments.
|
|
|
|
void beginDraw(float _x, float _y);
|
|
|
|
void drawTo(float _x, float _y);
|
|
|
|
void endDraw();
|
|
|
|
|
|
|
|
//HighLevel draw functions
|
|
|
|
void drawLine(float _x0, float _y0, float _x1, float _y1);
|
|
|
|
void drawBox(float _x, float _y, float _w, float _h);
|
|
|
|
void drawCircle(float _x, float _y, float _radius, float _steps);
|
|
|
|
void drawWheel(float _spokeangle, float _x, float _y, float _radius);
|
|
|
|
|
|
|
|
//Font Stuff (Simplex)
|
|
|
|
//void simplexMeasure(float _scale, const char *_string, float *_outWidth, float *_outHeight);
|
|
|
|
void drawSimplexFont(float _x, float _y, float _scale, const char* _string);
|
|
|
|
|
|
|
|
// Set the current drawing color
|
|
|
|
void setDrawColor(float _r, float _g, float _b, float _a = 1.0f);
|
|
|
|
|
|
|
|
// Set the number of frames of decay/fade to apply to the scene.
|
|
|
|
bool setDecaySteps(int _steps);
|
|
|
|
|
|
|
|
// Set the brightness multipler applied on each decay frame after the first.
|
|
|
|
bool setDecay(float _decay);
|
|
|
|
|
|
|
|
// Set the brightness multipler applied on the first decay frame.
|
|
|
|
bool setInitialDecay(float _initialDecay);
|
|
|
|
|
|
|
|
// Set a 2d transformation for the display.
|
|
|
|
//
|
|
|
|
// This relates logical coordinates, as passed to vector_display_begin_draw,
|
|
|
|
// vector_display_draw_to, and vector_display_draw, to coordinates from (0,0)
|
|
|
|
// to (width,height) in the destination framebuffer.
|
|
|
|
//
|
|
|
|
// The parameters impact coordinates as follows:
|
|
|
|
//
|
|
|
|
// framebuffer_x = x * scale + offset_x
|
|
|
|
// framebuffer_y = y * scale + offset_y
|
|
|
|
//
|
|
|
|
void setTransform(float _offsetX, float _offsetY, float _scale);
|
|
|
|
|
|
|
|
// Set the line thickness.
|
|
|
|
//
|
|
|
|
// The line thickness is measured in scene coordinates, and includes all pixels lit by
|
|
|
|
// the line before any post-processing. The apparent width of the line to the viewer
|
|
|
|
// is significantly narrower, since brightness decays exponentially to zero within the
|
|
|
|
// bounds of the line.
|
|
|
|
//
|
|
|
|
// Thickness, by default, is guessed based on width and height.
|
|
|
|
//
|
|
|
|
// This function clears the display.
|
|
|
|
bool setThickness(float _thickness);
|
|
|
|
void setDefaultThickness();
|
|
|
|
|
|
|
|
// Set the "brightness" of the display
|
|
|
|
//
|
|
|
|
// useful values range from [0.5, 1.5]. 0.0 disables all glow effects.
|
|
|
|
//
|
|
|
|
// Due to implementation details of the glow effect, glow is related to
|
|
|
|
// the pixel density of the framebuffer. It may require adjustment,
|
|
|
|
// particularly when moving between devices of very different pixel density.
|
|
|
|
//
|
|
|
|
void setBrightness(float _brightness);
|
|
|
|
|
|
|
|
// Get the size from a vector display.
|
|
|
|
void getSize(float* _outWidth, float* _outHeight);
|
|
|
|
|
2014-11-16 03:10:44 +03:00
|
|
|
protected:
|
2014-11-16 04:19:14 +03:00
|
|
|
void screenSpaceQuad(float _textureWidth, float _textureHeight, float _width = 1.0f, float _height = 1.0f);
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2016-04-20 06:31:37 +03:00
|
|
|
struct PendingPoint
|
2014-11-16 04:19:14 +03:00
|
|
|
{
|
|
|
|
float x, y;
|
2016-04-20 06:31:37 +03:00
|
|
|
};
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2016-04-20 06:31:37 +03:00
|
|
|
struct Line
|
2014-11-16 04:19:14 +03:00
|
|
|
{
|
|
|
|
float x0, y0, x1, y1; // nominal points
|
|
|
|
float a; // angle
|
|
|
|
float sin_a, cos_a; // precomputed trig
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
float xl0, yl0, xl1, yl1; // left side of the box
|
|
|
|
float xr0, yr0, xr1, yr1; // right side of the box
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
int is_first, is_last;
|
|
|
|
int has_next, has_prev; // booleans indicating whether this line connects to prev/next
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
float xlt0, ylt0, xlt1, ylt1; // coordinates of endcaps (if !has_prev/!has_next)
|
|
|
|
float xrt0, yrt0, xrt1, yrt1; // coordinates of endcaps (if !has_prev/!has_next)
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
float tl0, tl1, tr0, tr1;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
float s0, s1; // shorten line by this amount
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
float len;
|
2016-04-20 06:31:37 +03:00
|
|
|
};
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
float effectiveThickness();
|
|
|
|
void setupResDependent();
|
|
|
|
void teardownResDependent();
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
void appendTexpoint(float _x, float _y, float _u, float _v);
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
void drawFan(float _cx, float _cy, float _pa, float _a, float _t, float _s, float _e);
|
2016-04-20 06:31:37 +03:00
|
|
|
void drawLines(Line* _lines, int _numberLines);
|
2014-11-16 04:19:14 +03:00
|
|
|
void genLinetex();
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
bool m_originBottomLeft;
|
|
|
|
float m_texelHalf;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2015-05-29 01:27:00 +03:00
|
|
|
bgfx::ProgramHandle m_drawToScreenShader; // program for drawing to the framebuffer
|
|
|
|
bgfx::ProgramHandle m_blurShader; // program for gaussian blur
|
2014-11-16 04:19:14 +03:00
|
|
|
bgfx::ProgramHandle m_blitShader;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2015-05-29 01:27:00 +03:00
|
|
|
bgfx::UniformHandle u_params;
|
|
|
|
bgfx::UniformHandle s_texColor;
|
|
|
|
|
|
|
|
bgfx::FrameBufferHandle m_sceneFrameBuffer;
|
|
|
|
bgfx::FrameBufferHandle m_glow0FrameBuffer; // framebuffer for glow pass 0
|
|
|
|
bgfx::FrameBufferHandle m_glow1FrameBuffer; // framebuffer for glow pass 1
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2017-03-13 04:25:23 +03:00
|
|
|
uint8_t m_view;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
uint16_t m_screenWidth, m_screenHeight;
|
|
|
|
uint16_t m_glowWidth, m_glowHeight;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
int m_numberDecaySteps;
|
|
|
|
float m_decayValue;
|
2017-03-13 04:25:23 +03:00
|
|
|
uint8_t m_drawColorR;
|
|
|
|
uint8_t m_drawColorG;
|
|
|
|
uint8_t m_drawColorB;
|
|
|
|
uint8_t m_drawColorA;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2016-04-20 06:31:37 +03:00
|
|
|
stl::vector<PosColorUvVertex> m_points;
|
|
|
|
stl::vector<PendingPoint> m_pendingPoints;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
int m_currentDrawStep;
|
|
|
|
stl::vector<bgfx::DynamicVertexBufferHandle> m_vertexBuffers;
|
|
|
|
stl::vector<int> m_vertexBuffersSize;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
bgfx::TextureHandle m_lineTexId;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
float m_initialDecay;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
float m_thickness;
|
|
|
|
bool m_customThicknessEnabled;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
float m_brightness;
|
2014-11-16 03:10:44 +03:00
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
float m_drawOffsetX, m_drawOffsetY;
|
|
|
|
float m_drawScale;
|
2014-11-16 03:10:44 +03:00
|
|
|
};
|
|
|
|
|
2014-11-16 04:19:14 +03:00
|
|
|
#endif // __VECTORDISPLAY_H__
|