implement heightmap grid

This commit is contained in:
2018-08-07 19:45:38 +02:00
parent 16c04c433f
commit f941fc4254
11 changed files with 257 additions and 65 deletions

View File

@@ -1,4 +1,5 @@
#pragma once
#include "image.h"
enum class kShapeType : uint16_t
{
@@ -17,10 +18,13 @@ protected:
GLuint arrays[2]{ 0, 0 };
GLuint count[2]{ 0, 0 };
GLvoid* ioff[2]{ 0, 0 };
GLenum index_type = 0;
bool use_idx = true;
bool create_buffers_imp(GLvoid* idx, GLvoid* vertices, int isize, int vsize);
public:
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; glm::vec2 uvs2; };
bool create_buffers(GLvoid* idx, GLvoid* vertices, int isize, int vsize);
bool create_buffers(GLushort* idx, GLvoid* vertices, int isize, int vsize);
bool create_buffers(GLuint* idx, GLvoid* vertices, int isize, int vsize);
bool create_buffers(GLvoid* vertices, int vsize);
void draw_fill() const;
void draw_stroke() const;
@@ -116,31 +120,12 @@ public:
return create_buffers(idx.get(), vertices.get(), sizeof(GLushort) * idx_size, sizeof(vertex_t) * vertices_size);
}
void update_vertices(const glm::vec4* data, const glm::vec2* uvs = nullptr, const glm::vec2* uvs2 = nullptr);
/*
bool create(att::Divisions divisions, att::Width w, att::Height h)
{
const int div = divisions.value;
auto idx = std::make_unique<GLushort[]>(div * div * 6 + 8);
auto vertices = std::make_unique<vertex_t[]>((div + 1)*(div + 1));
create_impl(w.value, h.value, div, idx.get(), vertices.get());
return create_buffers(idx.get(), vertices.get(), sizeof(idx), sizeof(vertices));
}
template<typename T>
T get_attribute(T def_val)
{
auto ret = attribs.find(def_val.id);
if (ret == attribs.end())
return def_val;
return *reinterpret_cast<T*>(ret->second.get());
}
bool create_attrib() override
{
const auto w = get_attribute(att::Width(0));
const auto h = get_attribute(att::Height(0));
const auto d = get_attribute(att::Divisions(1));
return create(d, w, h);
}
*/
};
class HeightmapPlane : public Shape
{
public:
bool create(float w, float h, const Image& img, float scale);
};
class RectShape : public Shape