Skip to content

Commit 5beb65e

Browse files
committed
Warp mesh fixes
- Check that the contents of the map file represent a grid with monotonically increasing x- and y-coordinates. This is slightly more lenient than the existing code that assumed uniform grid spacing without verification. A fully general implementation would need to use the triangles directly. - Use an index buffer to hold the triangle coordinates, rather than duplicating the vertex data. This significantly reduces the amount of memory used, particularly when the vertex count is small enough to fit into a GLushort. - As there is only one warp mesh, and changing this should be an infrequent operation (existing code loads one warp mesh at startup), do not use the resource manager machinery. This removes the possibility to use a wildcard extension, but only one extension was supported anyway. - Use smart pointers to track resources rather than manual new/delete.
1 parent 1d0c608 commit 5beb65e

File tree

10 files changed

+430
-309
lines changed

10 files changed

+430
-309
lines changed

src/celengine/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ set(CELENGINE_SOURCES
5454
location.h
5555
lodspheremesh.cpp
5656
lodspheremesh.h
57-
mapmanager.cpp
58-
mapmanager.h
5957
marker.cpp
6058
marker.h
6159
meshmanager.cpp
@@ -155,6 +153,8 @@ set(CELENGINE_SOURCES
155153
virtualtex.h
156154
visibleregion.cpp
157155
visibleregion.h
156+
warpmesh.cpp
157+
warpmesh.h
158158
)
159159

160160
add_library(celengine OBJECT ${CELENGINE_SOURCES})

src/celengine/mapmanager.cpp

Lines changed: 0 additions & 193 deletions
This file was deleted.

src/celengine/mapmanager.h

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/celengine/viewporteffect.cpp

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "framebuffer.h"
1414
#include "render.h"
1515
#include "shadermanager.h"
16-
#include "mapmanager.h"
16+
#include "warpmesh.h"
1717

1818
namespace gl = celestia::gl;
1919
namespace util = celestia::util;
@@ -70,7 +70,7 @@ void PassthroughViewportEffect::initialize()
7070
return;
7171
initialized = true;
7272

73-
static std::array quadVertices = {
73+
static constexpr std::array quadVertices = {
7474
// positions // texCoords
7575
-1.0f, 1.0f, 0.0f, 1.0f,
7676
-1.0f, -1.0f, 0.0f, 0.0f,
@@ -103,12 +103,13 @@ void PassthroughViewportEffect::initialize()
103103
2 * sizeof(float));
104104
}
105105

106-
WarpMeshViewportEffect::WarpMeshViewportEffect(WarpMesh *mesh) :
107-
ViewportEffect(),
108-
mesh(mesh)
106+
WarpMeshViewportEffect::WarpMeshViewportEffect(std::unique_ptr<WarpMesh>&& _mesh) :
107+
mesh(std::move(_mesh))
109108
{
110109
}
111110

111+
WarpMeshViewportEffect::~WarpMeshViewportEffect() = default;
112+
112113
bool WarpMeshViewportEffect::prerender(Renderer* renderer, FramebufferObject* fbo)
113114
{
114115
if (mesh == nullptr)
@@ -143,35 +144,9 @@ void WarpMeshViewportEffect::initialize()
143144
initialized = true;
144145

145146
vo = gl::VertexObject();
146-
bo = gl::Buffer();
147-
148-
bo.setData(mesh->scopedDataForRendering(), gl::Buffer::BufferUsage::StaticDraw);
147+
bo = gl::Buffer(gl::Buffer::TargetHint::Array);
149148

150-
vo.setCount(mesh->count());
151-
vo.addVertexBuffer(
152-
bo,
153-
CelestiaGLProgram::VertexCoordAttributeIndex,
154-
2,
155-
gl::VertexObject::DataType::Float,
156-
false,
157-
5 * sizeof(float),
158-
0);
159-
vo.addVertexBuffer(
160-
bo,
161-
CelestiaGLProgram::TextureCoord0AttributeIndex,
162-
2,
163-
gl::VertexObject::DataType::Float,
164-
false,
165-
5 * sizeof(float),
166-
2 * sizeof(float));
167-
vo.addVertexBuffer(
168-
bo,
169-
CelestiaGLProgram::IntensityAttributeIndex,
170-
1,
171-
gl::VertexObject::DataType::Float,
172-
false,
173-
5 * sizeof(float),
174-
4 * sizeof(float));
149+
mesh->setUpVertexObject(vo, bo);
175150
}
176151

177152
bool WarpMeshViewportEffect::distortXY(float &x, float &y)
@@ -181,7 +156,7 @@ bool WarpMeshViewportEffect::distortXY(float &x, float &y)
181156

182157
float u;
183158
float v;
184-
if (!mesh->mapVertex(x * 2.0f, y * 2.0f, &u, &v))
159+
if (!mesh->mapVertex(x * 2.0f, y * 2.0f, u, v))
185160
return false;
186161

187162
x = u / 2.0f;

src/celengine/viewporteffect.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#pragma once
1212

13+
#include <memory>
14+
1315
#include <celrender/gl/buffer.h>
1416
#include <celrender/gl/vertexobject.h>
1517

@@ -52,8 +54,8 @@ class PassthroughViewportEffect : public ViewportEffect
5254
class WarpMeshViewportEffect : public ViewportEffect
5355
{
5456
public:
55-
WarpMeshViewportEffect(WarpMesh *mesh);
56-
~WarpMeshViewportEffect() override = default;
57+
explicit WarpMeshViewportEffect(std::unique_ptr<WarpMesh>&& mesh);
58+
~WarpMeshViewportEffect() override;
5759

5860
bool prerender(Renderer*, FramebufferObject* fbo) override;
5961
bool render(Renderer*, FramebufferObject*, int width, int height) override;
@@ -63,7 +65,7 @@ class WarpMeshViewportEffect : public ViewportEffect
6365
celestia::gl::VertexObject vo{ celestia::util::NoCreateT{} };
6466
celestia::gl::Buffer bo{ celestia::util::NoCreateT{} };
6567

66-
WarpMesh *mesh;
68+
std::unique_ptr<WarpMesh> mesh;
6769

6870
void initialize();
6971

0 commit comments

Comments
 (0)