Start using C++ in-place member initialization.
We should make good use of in-place member initialization. Many new classes have constructors that effectively do nothing but default-initialize POD members, and when adding new members, it is very easy to miss initializing them. With in-place initialization, the code is more compact, the diffs are nicer, and it's harder to miss them. This commit only converts render/ and platform/ to use in-place member initialization, since there was a bug in CairoRenderer, but we should convert the entire codebase.pull/307/merge
parent
501a4829c7
commit
28f94dcd0a
|
@ -67,7 +67,7 @@ public:
|
||||||
|
|
||||||
class Shader {
|
class Shader {
|
||||||
public:
|
public:
|
||||||
GLuint program;
|
GLuint program = 0;
|
||||||
|
|
||||||
void Init(const std::string &vertexRes,
|
void Init(const std::string &vertexRes,
|
||||||
const std::string &fragmentRes,
|
const std::string &fragmentRes,
|
||||||
|
@ -104,7 +104,7 @@ public:
|
||||||
|
|
||||||
Shader lightShader;
|
Shader lightShader;
|
||||||
Shader fillShader;
|
Shader fillShader;
|
||||||
Shader *selectedShader;
|
Shader *selectedShader = NULL;
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void Clear();
|
void Clear();
|
||||||
|
@ -152,8 +152,8 @@ public:
|
||||||
|
|
||||||
Shader shader;
|
Shader shader;
|
||||||
|
|
||||||
const StippleAtlas *atlas;
|
const StippleAtlas *atlas = NULL;
|
||||||
StipplePattern pattern;
|
StipplePattern pattern = StipplePattern::CONTINUOUS;
|
||||||
|
|
||||||
void Init(const StippleAtlas *atlas);
|
void Init(const StippleAtlas *atlas);
|
||||||
void Clear();
|
void Clear();
|
||||||
|
@ -192,8 +192,8 @@ public:
|
||||||
|
|
||||||
Shader shader;
|
Shader shader;
|
||||||
|
|
||||||
const StippleAtlas *atlas;
|
const StippleAtlas *atlas = NULL;
|
||||||
StipplePattern pattern;
|
StipplePattern pattern = StipplePattern::CONTINUOUS;
|
||||||
|
|
||||||
void Init(const StippleAtlas *atlas);
|
void Init(const StippleAtlas *atlas);
|
||||||
void Clear();
|
void Clear();
|
||||||
|
@ -242,7 +242,7 @@ public:
|
||||||
Shader colShader;
|
Shader colShader;
|
||||||
Shader pointShader;
|
Shader pointShader;
|
||||||
|
|
||||||
Shader *selectedShader;
|
Shader *selectedShader = NULL;
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
|
@ -135,11 +135,10 @@ public:
|
||||||
bool Equals(const Fill &other) const;
|
bool Equals(const Fill &other) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
IdList<Stroke, hStroke> strokes;
|
IdList<Stroke, hStroke> strokes = {};
|
||||||
IdList<Fill, hFill> fills;
|
IdList<Fill, hFill> fills = {};
|
||||||
BitmapFont bitmapFont;
|
BitmapFont bitmapFont = {};
|
||||||
|
|
||||||
Canvas() : strokes(), fills(), bitmapFont() {}
|
|
||||||
virtual void Clear();
|
virtual void Clear();
|
||||||
|
|
||||||
hStroke GetStroke(const Stroke &stroke);
|
hStroke GetStroke(const Stroke &stroke);
|
||||||
|
@ -197,7 +196,7 @@ public:
|
||||||
class UiCanvas {
|
class UiCanvas {
|
||||||
public:
|
public:
|
||||||
std::shared_ptr<Canvas> canvas;
|
std::shared_ptr<Canvas> canvas;
|
||||||
bool flip;
|
bool flip = false;
|
||||||
|
|
||||||
void DrawLine(int x1, int y1, int x2, int y2, RgbaColor color, int width = 1,
|
void DrawLine(int x1, int y1, int x2, int y2, RgbaColor color, int width = 1,
|
||||||
int zIndex = 0);
|
int zIndex = 0);
|
||||||
|
@ -216,17 +215,14 @@ public:
|
||||||
// A canvas that performs picking against drawn geometry.
|
// A canvas that performs picking against drawn geometry.
|
||||||
class ObjectPicker : public Canvas {
|
class ObjectPicker : public Canvas {
|
||||||
public:
|
public:
|
||||||
Camera camera;
|
Camera camera = {};
|
||||||
// Configuration.
|
// Configuration.
|
||||||
Point2d point;
|
Point2d point = {};
|
||||||
double selRadius;
|
double selRadius = 0.0;
|
||||||
// Picking state.
|
// Picking state.
|
||||||
double minDistance;
|
double minDistance = 0.0;
|
||||||
int maxZIndex;
|
int maxZIndex = 0;
|
||||||
uint32_t position;
|
uint32_t position = 0;
|
||||||
|
|
||||||
ObjectPicker() : camera(), point(), selRadius(),
|
|
||||||
minDistance(), maxZIndex(), position() {}
|
|
||||||
|
|
||||||
const Camera &GetCamera() const override { return camera; }
|
const Camera &GetCamera() const override { return camera; }
|
||||||
|
|
||||||
|
@ -261,18 +257,17 @@ public:
|
||||||
// on the CPU.
|
// on the CPU.
|
||||||
class SurfaceRenderer : public Canvas {
|
class SurfaceRenderer : public Canvas {
|
||||||
public:
|
public:
|
||||||
Camera camera;
|
Camera camera = {};
|
||||||
Lighting lighting;
|
Lighting lighting = {};
|
||||||
// Chord tolerance, for converting beziers to pwl.
|
// Chord tolerance, for converting beziers to pwl.
|
||||||
double chordTolerance;
|
double chordTolerance = 0.0;
|
||||||
// Render lists.
|
// Render lists.
|
||||||
handle_map<hStroke, SEdgeList> edges;
|
handle_map<hStroke, SEdgeList> edges;
|
||||||
handle_map<hStroke, SBezierList> beziers;
|
handle_map<hStroke, SBezierList> beziers;
|
||||||
SMesh mesh;
|
SMesh mesh = {};
|
||||||
// State.
|
// State.
|
||||||
BBox bbox;
|
BBox bbox = {};
|
||||||
|
|
||||||
SurfaceRenderer() : camera(), lighting(), chordTolerance(), mesh(), bbox() {}
|
|
||||||
void Clear() override;
|
void Clear() override;
|
||||||
|
|
||||||
// Canvas interface.
|
// Canvas interface.
|
||||||
|
@ -323,15 +318,13 @@ public:
|
||||||
|
|
||||||
class CairoRenderer : public SurfaceRenderer {
|
class CairoRenderer : public SurfaceRenderer {
|
||||||
public:
|
public:
|
||||||
cairo_t *context;
|
cairo_t *context = NULL;
|
||||||
// Renderer configuration.
|
// Renderer configuration.
|
||||||
bool antialias;
|
bool antialias = false;
|
||||||
// Renderer state.
|
// Renderer state.
|
||||||
struct {
|
struct {
|
||||||
hStroke hcs;
|
hStroke hcs;
|
||||||
} current;
|
} current = {};
|
||||||
|
|
||||||
CairoRenderer() : context(), current() {}
|
|
||||||
|
|
||||||
void SelectStroke(hStroke hcs);
|
void SelectStroke(hStroke hcs);
|
||||||
void MoveTo(Vector p);
|
void MoveTo(Vector p);
|
||||||
|
@ -353,8 +346,9 @@ public:
|
||||||
// An offscreen renderer based on OpenGL framebuffers.
|
// An offscreen renderer based on OpenGL framebuffers.
|
||||||
class GlOffscreen {
|
class GlOffscreen {
|
||||||
public:
|
public:
|
||||||
unsigned int framebuffer;
|
unsigned int framebuffer = 0;
|
||||||
unsigned int colorRenderbuffer, depthRenderbuffer;
|
unsigned int colorRenderbuffer = 0;
|
||||||
|
unsigned int depthRenderbuffer = 0;
|
||||||
std::vector<uint8_t> data;
|
std::vector<uint8_t> data;
|
||||||
|
|
||||||
bool Render(int width, int height, std::function<void()> renderFn);
|
bool Render(int width, int height, std::function<void()> renderFn);
|
||||||
|
|
Loading…
Reference in New Issue