Finish OpenGL 2 to OpenGL 3 renaming started in ecb6550b.

pull/348/head
whitequark 2018-07-31 21:01:28 +00:00
parent 4d1bd55cc2
commit 80c111bf75
1 changed files with 53 additions and 53 deletions

View File

@ -40,7 +40,7 @@ public:
};
// A canvas that uses the core OpenGL 3 profile, for desktop systems.
class OpenGl2Renderer final : public ViewportCanvas {
class OpenGl3Renderer final : public ViewportCanvas {
public:
struct SEdgeListItem {
hStroke h;
@ -88,7 +88,7 @@ public:
std::weak_ptr<const Pixmap> texture;
} current;
OpenGl2Renderer() :
OpenGl3Renderer() :
lines(), meshes(), points(), pixmapCache(), masks(),
initialized(), atlas(), meshRenderer(), imeshRenderer(),
edgeRenderer(), outlineRenderer(), camera(), lighting(),
@ -193,7 +193,7 @@ static void ssglDepthRange(Canvas::Layer layer, int zIndex) {
// A simple OpenGL state tracker to group consecutive draw calls.
//-----------------------------------------------------------------------------
Canvas::Stroke *OpenGl2Renderer::SelectStroke(hStroke hcs) {
Canvas::Stroke *OpenGl3Renderer::SelectStroke(hStroke hcs) {
if(current.hcs.v == hcs.v) return current.stroke;
Stroke *stroke = strokes.FindById(hcs);
@ -207,7 +207,7 @@ Canvas::Stroke *OpenGl2Renderer::SelectStroke(hStroke hcs) {
return stroke;
}
void OpenGl2Renderer::SelectMask(FillPattern pattern) {
void OpenGl3Renderer::SelectMask(FillPattern pattern) {
if(!masks[0]) {
masks[0] = Pixmap::Create(Pixmap::Format::A, 32, 32);
masks[1] = Pixmap::Create(Pixmap::Format::A, 32, 32);
@ -239,7 +239,7 @@ void OpenGl2Renderer::SelectMask(FillPattern pattern) {
}
}
Canvas::Fill *OpenGl2Renderer::SelectFill(hFill hcf) {
Canvas::Fill *OpenGl3Renderer::SelectFill(hFill hcf) {
if(current.hcf.v == hcf.v) return current.fill;
Fill *fill = fills.FindById(hcf);
@ -263,7 +263,7 @@ static bool IsPowerOfTwo(size_t n) {
return (n & (n - 1)) == 0;
}
void OpenGl2Renderer::InvalidatePixmap(std::shared_ptr<const Pixmap> pm) {
void OpenGl3Renderer::InvalidatePixmap(std::shared_ptr<const Pixmap> pm) {
GLuint id;
pixmapCache.Lookup(pm, &id);
glBindTexture(GL_TEXTURE_2D, id);
@ -294,7 +294,7 @@ void OpenGl2Renderer::InvalidatePixmap(std::shared_ptr<const Pixmap> pm) {
format, GL_UNSIGNED_BYTE, &pm->data[0]);
}
void OpenGl2Renderer::SelectTexture(std::shared_ptr<const Pixmap> pm) {
void OpenGl3Renderer::SelectTexture(std::shared_ptr<const Pixmap> pm) {
if(current.texture.lock() == pm) return;
GLuint id;
@ -307,7 +307,7 @@ void OpenGl2Renderer::SelectTexture(std::shared_ptr<const Pixmap> pm) {
current.texture = pm;
}
void OpenGl2Renderer::DoLine(const Vector &a, const Vector &b, hStroke hcs) {
void OpenGl3Renderer::DoLine(const Vector &a, const Vector &b, hStroke hcs) {
SEdgeListItem *eli = lines.FindByIdNoOops(hcs);
if(eli == NULL) {
SEdgeListItem item = {};
@ -319,7 +319,7 @@ void OpenGl2Renderer::DoLine(const Vector &a, const Vector &b, hStroke hcs) {
eli->lines.AddEdge(a, b);
}
void OpenGl2Renderer::DoPoint(Vector p, hStroke hs) {
void OpenGl3Renderer::DoPoint(Vector p, hStroke hs) {
SPointListItem *pli = points.FindByIdNoOops(hs);
if(pli == NULL) {
SPointListItem item = {};
@ -331,7 +331,7 @@ void OpenGl2Renderer::DoPoint(Vector p, hStroke hs) {
pli->points.AddPoint(p);
}
void OpenGl2Renderer::DoStippledLine(const Vector &a, const Vector &b, hStroke hcs) {
void OpenGl3Renderer::DoStippledLine(const Vector &a, const Vector &b, hStroke hcs) {
Stroke *stroke = strokes.FindById(hcs);
if(stroke->stipplePattern != StipplePattern::FREEHAND &&
stroke->stipplePattern != StipplePattern::ZIGZAG)
@ -431,7 +431,7 @@ void OpenGl2Renderer::DoStippledLine(const Vector &a, const Vector &b, hStroke h
// A canvas implemented using OpenGL 3 vertex buffer objects.
//-----------------------------------------------------------------------------
void OpenGl2Renderer::Init() {
void OpenGl3Renderer::Init() {
atlas.Init();
edgeRenderer.Init(&atlas);
outlineRenderer.Init(&atlas);
@ -446,17 +446,17 @@ void OpenGl2Renderer::Init() {
UpdateProjection();
}
void OpenGl2Renderer::DrawLine(const Vector &a, const Vector &b, hStroke hcs) {
void OpenGl3Renderer::DrawLine(const Vector &a, const Vector &b, hStroke hcs) {
DoStippledLine(a, b, hcs);
}
void OpenGl2Renderer::DrawEdges(const SEdgeList &el, hStroke hcs) {
void OpenGl3Renderer::DrawEdges(const SEdgeList &el, hStroke hcs) {
for(const SEdge &e : el.l) {
DoStippledLine(e.a, e.b, hcs);
}
}
void OpenGl2Renderer::DrawOutlines(const SOutlineList &ol, hStroke hcs, DrawOutlinesAs mode) {
void OpenGl3Renderer::DrawOutlines(const SOutlineList &ol, hStroke hcs, DrawOutlinesAs mode) {
if(ol.l.n == 0) return;
Stroke *stroke = SelectStroke(hcs);
@ -468,7 +468,7 @@ void OpenGl2Renderer::DrawOutlines(const SOutlineList &ol, hStroke hcs, DrawOutl
outlineRenderer.Draw(ol, mode);
}
void OpenGl2Renderer::DrawVectorText(const std::string &text, double height,
void OpenGl3Renderer::DrawVectorText(const std::string &text, double height,
const Vector &o, const Vector &u, const Vector &v,
hStroke hcs) {
SEdgeListItem *eli = lines.FindByIdNoOops(hcs);
@ -483,7 +483,7 @@ void OpenGl2Renderer::DrawVectorText(const std::string &text, double height,
VectorFont::Builtin()->Trace(height, o, u, v, text, traceEdge, camera);
}
void OpenGl2Renderer::DrawQuad(const Vector &a, const Vector &b, const Vector &c, const Vector &d,
void OpenGl3Renderer::DrawQuad(const Vector &a, const Vector &b, const Vector &c, const Vector &d,
hFill hcf) {
SMeshListItem *li = meshes.FindByIdNoOops(hcf);
if(li == NULL) {
@ -495,11 +495,11 @@ void OpenGl2Renderer::DrawQuad(const Vector &a, const Vector &b, const Vector &c
li->mesh.AddQuad(a, b, c, d);
}
void OpenGl2Renderer::DrawPoint(const Vector &o, hStroke hs) {
void OpenGl3Renderer::DrawPoint(const Vector &o, hStroke hs) {
DoPoint(o, hs);
}
void OpenGl2Renderer::DrawPolygon(const SPolygon &p, hFill hcf) {
void OpenGl3Renderer::DrawPolygon(const SPolygon &p, hFill hcf) {
Fill *fill = SelectFill(hcf);
SMesh m = {};
@ -509,11 +509,11 @@ void OpenGl2Renderer::DrawPolygon(const SPolygon &p, hFill hcf) {
m.Clear();
}
void OpenGl2Renderer::DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack) {
void OpenGl3Renderer::DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack) {
ssassert(false, "Not implemented");
}
void OpenGl2Renderer::DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) {
void OpenGl3Renderer::DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) {
if(faces.empty()) return;
Fill *fill = SelectFill(hcf);
@ -531,7 +531,7 @@ void OpenGl2Renderer::DrawFaces(const SMesh &m, const std::vector<uint32_t> &fac
facesMesh.Clear();
}
void OpenGl2Renderer::DrawPixmap(std::shared_ptr<const Pixmap> pm,
void OpenGl3Renderer::DrawPixmap(std::shared_ptr<const Pixmap> pm,
const Vector &o, const Vector &u, const Vector &v,
const Point2d &ta, const Point2d &tb, hFill hcf) {
Fill fill = *fills.FindById(hcf);
@ -549,7 +549,7 @@ void OpenGl2Renderer::DrawPixmap(std::shared_ptr<const Pixmap> pm,
mli->mesh.AddPixmap(o, u, v, ta, tb);
}
void OpenGl2Renderer::UpdateProjection() {
void OpenGl3Renderer::UpdateProjection() {
glViewport(0, 0,
(int)(camera.width * camera.pixelRatio),
(int)(camera.height * camera.pixelRatio));
@ -616,7 +616,7 @@ void OpenGl2Renderer::UpdateProjection() {
glClear(GL_DEPTH_BUFFER_BIT);
}
void OpenGl2Renderer::NewFrame() {
void OpenGl3Renderer::NewFrame() {
if(!initialized) {
Init();
initialized = true;
@ -637,7 +637,7 @@ void OpenGl2Renderer::NewFrame() {
glPolygonOffset(2.0, 1.0);
}
void OpenGl2Renderer::FlushFrame() {
void OpenGl3Renderer::FlushFrame() {
for(SMeshListItem &li : meshes) {
Fill *fill = SelectFill(li.h);
@ -673,12 +673,12 @@ void OpenGl2Renderer::FlushFrame() {
}
}
void OpenGl2Renderer::Clear() {
void OpenGl3Renderer::Clear() {
ViewportCanvas::Clear();
pixmapCache.CleanupUnused();
}
std::shared_ptr<Pixmap> OpenGl2Renderer::ReadFrame() {
std::shared_ptr<Pixmap> OpenGl3Renderer::ReadFrame() {
std::shared_ptr<Pixmap> pixmap =
Pixmap::Create(Pixmap::Format::RGB, (size_t)camera.width, (size_t)camera.height);
glReadPixels(0, 0, (int)camera.width, (int)camera.height,
@ -686,20 +686,20 @@ std::shared_ptr<Pixmap> OpenGl2Renderer::ReadFrame() {
return pixmap;
}
void OpenGl2Renderer::GetIdent(const char **vendor, const char **renderer, const char **version) {
void OpenGl3Renderer::GetIdent(const char **vendor, const char **renderer, const char **version) {
*vendor = (const char *)glGetString(GL_VENDOR);
*renderer = (const char *)glGetString(GL_RENDERER);
*version = (const char *)glGetString(GL_VERSION);
}
void OpenGl2Renderer::SetCamera(const Camera &c) {
void OpenGl3Renderer::SetCamera(const Camera &c) {
camera = c;
if(initialized) {
UpdateProjection();
}
}
void OpenGl2Renderer::SetLighting(const Lighting &l) {
void OpenGl3Renderer::SetLighting(const Lighting &l) {
lighting = l;
}
@ -712,8 +712,8 @@ public:
virtual Canvas::Layer GetLayer() const = 0;
virtual int GetZIndex() const = 0;
virtual void Draw(OpenGl2Renderer *renderer) = 0;
virtual void Remove(OpenGl2Renderer *renderer) = 0;
virtual void Draw(OpenGl3Renderer *renderer) = 0;
virtual void Remove(OpenGl3Renderer *renderer) = 0;
};
class EdgeDrawCall final : public DrawCall {
@ -726,7 +726,7 @@ public:
virtual Canvas::Layer GetLayer() const override { return stroke.layer; };
virtual int GetZIndex() const override { return stroke.zIndex; };
static std::shared_ptr<DrawCall> Create(OpenGl2Renderer *renderer, const SEdgeList &el,
static std::shared_ptr<DrawCall> Create(OpenGl3Renderer *renderer, const SEdgeList &el,
Canvas::Stroke *stroke) {
EdgeDrawCall *dc = new EdgeDrawCall();
dc->stroke = *stroke;
@ -734,13 +734,13 @@ public:
return std::shared_ptr<DrawCall>(dc);
}
void Draw(OpenGl2Renderer *renderer) override {
void Draw(OpenGl3Renderer *renderer) override {
ssglDepthRange(stroke.layer, stroke.zIndex);
renderer->edgeRenderer.SetStroke(stroke, 1.0 / renderer->camera.scale);
renderer->edgeRenderer.Draw(handle);
}
void Remove(OpenGl2Renderer *renderer) override {
void Remove(OpenGl3Renderer *renderer) override {
renderer->edgeRenderer.Remove(handle);
}
};
@ -756,7 +756,7 @@ public:
virtual Canvas::Layer GetLayer() const override { return stroke.layer; };
virtual int GetZIndex() const override { return stroke.zIndex; };
static std::shared_ptr<DrawCall> Create(OpenGl2Renderer *renderer, const SOutlineList &ol,
static std::shared_ptr<DrawCall> Create(OpenGl3Renderer *renderer, const SOutlineList &ol,
Canvas::Stroke *stroke,
Canvas::DrawOutlinesAs drawAs) {
OutlineDrawCall *dc = new OutlineDrawCall();
@ -766,13 +766,13 @@ public:
return std::shared_ptr<DrawCall>(dc);
}
void Draw(OpenGl2Renderer *renderer) override {
void Draw(OpenGl3Renderer *renderer) override {
ssglDepthRange(stroke.layer, stroke.zIndex);
renderer->outlineRenderer.SetStroke(stroke, 1.0 / renderer->camera.scale);
renderer->outlineRenderer.Draw(handle, drawAs);
}
void Remove(OpenGl2Renderer *renderer) override {
void Remove(OpenGl3Renderer *renderer) override {
renderer->outlineRenderer.Remove(handle);
}
};
@ -787,7 +787,7 @@ public:
virtual Canvas::Layer GetLayer() const override { return stroke.layer; };
virtual int GetZIndex() const override { return stroke.zIndex; };
static std::shared_ptr<DrawCall> Create(OpenGl2Renderer *renderer, const SIndexedMesh &mesh,
static std::shared_ptr<DrawCall> Create(OpenGl3Renderer *renderer, const SIndexedMesh &mesh,
Canvas::Stroke *stroke) {
PointDrawCall *dc = new PointDrawCall();
dc->stroke = *stroke;
@ -795,13 +795,13 @@ public:
return std::shared_ptr<DrawCall>(dc);
}
void Draw(OpenGl2Renderer *renderer) override {
void Draw(OpenGl3Renderer *renderer) override {
ssglDepthRange(stroke.layer, stroke.zIndex);
renderer->imeshRenderer.UsePoint(stroke, 1.0 / renderer->camera.scale);
renderer->imeshRenderer.Draw(handle);
}
void Remove(OpenGl2Renderer *renderer) override {
void Remove(OpenGl3Renderer *renderer) override {
renderer->imeshRenderer.Remove(handle);
}
};
@ -816,7 +816,7 @@ public:
virtual Canvas::Layer GetLayer() const override { return fill.layer; };
virtual int GetZIndex() const override { return fill.zIndex; };
static std::shared_ptr<DrawCall> Create(OpenGl2Renderer *renderer, const SIndexedMesh &mesh,
static std::shared_ptr<DrawCall> Create(OpenGl3Renderer *renderer, const SIndexedMesh &mesh,
Canvas::Fill *fill) {
PixmapDrawCall *dc = new PixmapDrawCall();
dc->fill = *fill;
@ -824,7 +824,7 @@ public:
return std::shared_ptr<DrawCall>(dc);
}
void Draw(OpenGl2Renderer *renderer) override {
void Draw(OpenGl3Renderer *renderer) override {
ssglDepthRange(fill.layer, fill.zIndex);
if(fill.pattern != Canvas::FillPattern::SOLID) {
renderer->SelectMask(fill.pattern);
@ -837,7 +837,7 @@ public:
renderer->imeshRenderer.Draw(handle);
}
void Remove(OpenGl2Renderer *renderer) override {
void Remove(OpenGl3Renderer *renderer) override {
renderer->imeshRenderer.Remove(handle);
}
};
@ -855,7 +855,7 @@ public:
virtual Canvas::Layer GetLayer() const override { return fillFront.layer; };
virtual int GetZIndex() const override { return fillFront.zIndex; };
static std::shared_ptr<DrawCall> Create(OpenGl2Renderer *renderer, const SMesh &m,
static std::shared_ptr<DrawCall> Create(OpenGl3Renderer *renderer, const SMesh &m,
Canvas::Fill *fillFront, Canvas::Fill *fillBack = NULL,
bool isShaded = false) {
MeshDrawCall *dc = new MeshDrawCall();
@ -867,7 +867,7 @@ public:
return std::shared_ptr<DrawCall>(dc);
}
void DrawFace(OpenGl2Renderer *renderer, GLenum cullFace, const Canvas::Fill &fill) {
void DrawFace(OpenGl3Renderer *renderer, GLenum cullFace, const Canvas::Fill &fill) {
glCullFace(cullFace);
ssglDepthRange(fill.layer, fill.zIndex);
if(fill.pattern != Canvas::FillPattern::SOLID) {
@ -885,7 +885,7 @@ public:
renderer->meshRenderer.Draw(handle, /*useColors=*/fill.color.IsEmpty(), fill.color);
}
void Draw(OpenGl2Renderer *renderer) override {
void Draw(OpenGl3Renderer *renderer) override {
glEnable(GL_POLYGON_OFFSET_FILL);
glEnable(GL_CULL_FACE);
@ -897,7 +897,7 @@ public:
glDisable(GL_CULL_FACE);
}
void Remove(OpenGl2Renderer *renderer) override {
void Remove(OpenGl3Renderer *renderer) override {
renderer->meshRenderer.Remove(handle);
}
};
@ -924,7 +924,7 @@ struct CompareDrawCall {
}
};
class OpenGl2RendererBatch final : public BatchCanvas {
class OpenGl3RendererBatch final : public BatchCanvas {
public:
struct EdgeBuffer {
hStroke h;
@ -944,14 +944,14 @@ public:
}
};
OpenGl2Renderer *renderer;
OpenGl3Renderer *renderer;
IdList<EdgeBuffer, hStroke> edgeBuffer;
IdList<PointBuffer, hStroke> pointBuffer;
std::multiset<std::shared_ptr<DrawCall>, CompareDrawCall> drawCalls;
OpenGl2RendererBatch() : renderer(), edgeBuffer(), pointBuffer() {}
OpenGl3RendererBatch() : renderer(), edgeBuffer(), pointBuffer() {}
void DrawLine(const Vector &a, const Vector &b, hStroke hcs) override {
EdgeBuffer *eb = edgeBuffer.FindByIdNoOops(hcs);
@ -1077,14 +1077,14 @@ public:
// Factory functions.
//-----------------------------------------------------------------------------
std::shared_ptr<BatchCanvas> OpenGl2Renderer::CreateBatch() {
OpenGl2RendererBatch *batch = new OpenGl2RendererBatch();
std::shared_ptr<BatchCanvas> OpenGl3Renderer::CreateBatch() {
OpenGl3RendererBatch *batch = new OpenGl3RendererBatch();
batch->renderer = this;
return std::shared_ptr<BatchCanvas>(batch);
}
std::shared_ptr<ViewportCanvas> CreateRenderer() {
return std::shared_ptr<ViewportCanvas>(new OpenGl2Renderer());
return std::shared_ptr<ViewportCanvas>(new OpenGl3Renderer());
}
}