Browse Source

small tweaks in EZMesh shader compatibilities

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 11 years ago
parent
commit
accce03e6f
3 changed files with 55 additions and 15 deletions
  1. +48
    -10
      src/easymesh/easymesh.cpp
  2. +5
    -3
      src/easymesh/easymesh.h
  3. +2
    -2
      src/scene.cpp

+ 48
- 10
src/easymesh/easymesh.cpp View File

@@ -239,10 +239,13 @@ void GpuEasyMeshData::AddGpuData(GpuShaderData* gpudata, EasyMesh* src_mesh)
m_indexcount = indexlist.Count(); m_indexcount = indexlist.Count();
} }


if (m_gpudatas.Count() != DebugRenderMode::Max)
//init to a minimum of gpudata->m_render_mode size
if (m_gpudatas.Count() <= gpudata->m_render_mode)
{ {
m_gpudatas.Reserve(DebugRenderMode::Max);
for (int i = 0; i < DebugRenderMode::Max; i++)
int i = m_gpudatas.Count();
int max = gpudata->m_render_mode + 1;
m_gpudatas.Reserve(max);
for (; i < max; i++)
m_gpudatas << nullptr; m_gpudatas << nullptr;
} }
m_gpudatas[gpudata->m_render_mode] = gpudata; m_gpudatas[gpudata->m_render_mode] = gpudata;
@@ -373,10 +376,11 @@ void GpuEasyMeshData::SetupVertexData(uint16_t vflags, EasyMesh* src_mesh)
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void GpuEasyMeshData::RenderMeshData(mat4 const &model)
void GpuEasyMeshData::RenderMeshData(mat4 const &model, int render_mode)
{ {
DebugRenderMode d = Video::GetDebugRenderMode();
GpuShaderData& gpu_sd = *(m_gpudatas[d]);
ASSERT(0 <= render_mode && render_mode < m_gpudatas.Count(), "render mode is not in the defined range");
ASSERT(m_gpudatas[render_mode], "gpu datas for this render mode don't exist");
GpuShaderData& gpu_sd = *(m_gpudatas[render_mode]);


int vdecl_idx = 0; int vdecl_idx = 0;
for (; vdecl_idx < m_vdatas.Count(); ++vdecl_idx) for (; vdecl_idx < m_vdatas.Count(); ++vdecl_idx)
@@ -620,8 +624,9 @@ void EasyMesh::MeshConvert(GpuShaderData* new_gpu_sdata)
if (new_gpu_sdata) if (new_gpu_sdata)
{ {
m_gpu_data.AddGpuData(new_gpu_sdata, this); m_gpu_data.AddGpuData(new_gpu_sdata, this);
for (int i = DebugRenderMode::Default + 1; i < DebugRenderMode::Max; i++)
m_gpu_data.AddGpuData(new DefaultShaderData(DebugRenderMode(i)), this);
for (int i = DebugRenderMode::Default; i < DebugRenderMode::Max; i++)
if (!m_gpu_data.HasData(i))
m_gpu_data.AddGpuData(new DefaultShaderData(DebugRenderMode(i)), this);
} }
m_state = MeshRender::CanRender; m_state = MeshRender::CanRender;
} }
@@ -646,11 +651,11 @@ void EasyMesh::MeshConvert(Shader* provided_shader)
} }


//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool EasyMesh::Render(mat4 const &model)
bool EasyMesh::Render(mat4 const &model, int render_mode)
{ {
if (m_state == MeshRender::CanRender) if (m_state == MeshRender::CanRender)
{ {
m_gpu_data.RenderMeshData(model);
m_gpu_data.RenderMeshData(model, render_mode);
return true; return true;
} }
return false; return false;
@@ -834,6 +839,39 @@ void VertexDictionnary::AddVertex(const int vert_id, const vec3 vert_coord)
vertex_list.Push(vert_id, vert_coord, VDictType::Alone); vertex_list.Push(vert_id, vert_coord, VDictType::Alone);
} }


//-----------------------------------------------------------------------------
//Will update the given list with all the vertices on the same spot.
void VertexDictionnary::RemoveVertex(const int vert_id)
{
int j = 0;
for (; j < vertex_list.Count(); j++)
if (vertex_list[j].m1 == vert_id)
break;

if (vertex_list[j].m3 == VDictType::Master)
{
int jf = -1;
//change all the master ref in the list
for (int i = 0; i < vertex_list.Count(); i++)
{
if (vertex_list[i].m3 == j)
{
if (jf < 0)
{
jf = i;
vertex_list[i].m3 == VDictType::Master;
}
else
vertex_list[i].m3 == jf;
}
}
}
vertex_list.Remove(j);
for (int i = 0; i < master_list.Count(); i++)
if (master_list[j] == j)
break;
}

//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void EasyMesh::MeshCsg(CSGUsage csg_operation) void EasyMesh::MeshCsg(CSGUsage csg_operation)
{ {


+ 5
- 3
src/easymesh/easymesh.h View File

@@ -150,7 +150,7 @@ public:
protected: protected:
uint16_t m_vert_decl_flags; uint16_t m_vert_decl_flags;
Shader* m_shader; Shader* m_shader;
DebugRenderMode m_render_mode;
int m_render_mode;
Array<lol::String, ShaderUniform> m_shader_uniform; Array<lol::String, ShaderUniform> m_shader_uniform;
Array<ShaderAttrib> m_shader_attrib; Array<ShaderAttrib> m_shader_attrib;
}; };
@@ -180,7 +180,8 @@ public:
~GpuEasyMeshData(); ~GpuEasyMeshData();
//--- //---
void AddGpuData(GpuShaderData* gpudata, class EasyMesh* src_mesh); void AddGpuData(GpuShaderData* gpudata, class EasyMesh* src_mesh);
void RenderMeshData(mat4 const &model);
void RenderMeshData(mat4 const &model, int render_mode=Video::GetDebugRenderMode());
bool HasData(int render_mode) { return (0 <= render_mode && render_mode < m_gpudatas.Count() && !!m_gpudatas[render_mode]); }


private: private:
void SetupVertexData(uint16_t vdecl_flags, EasyMesh* src_mesh); void SetupVertexData(uint16_t vdecl_flags, EasyMesh* src_mesh);
@@ -632,6 +633,7 @@ public:
bool FindConnectedTriangles(const ivec2 &search_idx, const Array<uint16_t> &tri_list, const int tri0, Array<int> &connected_tri, Array<int> const *ignored_tri = nullptr); bool FindConnectedTriangles(const ivec2 &search_idx, const Array<uint16_t> &tri_list, const int tri0, Array<int> &connected_tri, Array<int> const *ignored_tri = nullptr);
bool FindConnectedTriangles(const ivec3 &search_idx, const Array<uint16_t> &tri_list, const int tri0, Array<int> &connected_tri, Array<int> const *ignored_tri = nullptr); bool FindConnectedTriangles(const ivec3 &search_idx, const Array<uint16_t> &tri_list, const int tri0, Array<int> &connected_tri, Array<int> const *ignored_tri = nullptr);
void AddVertex(int vert_id, vec3 vert_coord); void AddVertex(int vert_id, vec3 vert_coord);
void RemoveVertex(int vert_id);
bool GetMasterList(Array<int> &ret_master_list) { ret_master_list = master_list; return ret_master_list.Count() > 0; } bool GetMasterList(Array<int> &ret_master_list) { ret_master_list = master_list; return ret_master_list.Count() > 0; }
void Clear() { vertex_list.Empty(); } void Clear() { vertex_list.Empty(); }
private: private:
@@ -669,7 +671,7 @@ public:
void ExecuteCmdStack(); void ExecuteCmdStack();
void MeshConvert(GpuShaderData* new_gpu_sdata); void MeshConvert(GpuShaderData* new_gpu_sdata);
void MeshConvert(Shader* ProvidedShader = nullptr); void MeshConvert(Shader* ProvidedShader = nullptr);
bool Render(mat4 const &model);
bool Render(mat4 const &model, int render_mode=Video::GetDebugRenderMode());
MeshRender GetMeshState() { return m_state; } MeshRender GetMeshState() { return m_state; }
bool SetRender(bool should_render); bool SetRender(bool should_render);




+ 2
- 2
src/scene.cpp View File

@@ -80,7 +80,7 @@ Scene::Scene(ivec2 size)
{ {
/* Create a default orthographic camera, in case the user doesn’t. */ /* Create a default orthographic camera, in case the user doesn’t. */
data->m_default_cam = new Camera(); data->m_default_cam = new Camera();
mat4 proj = mat4::ortho(0, size.x, 0, size.y, -1000.f, 1000.f);
mat4 proj = mat4::ortho(0.f, size.x, 0.f, size.y, -1000.f, 1000.f);
data->m_default_cam->SetProjection(proj); data->m_default_cam->SetProjection(proj);
PushCamera(data->m_default_cam); PushCamera(data->m_default_cam);


@@ -150,7 +150,7 @@ void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale)


Tile t; Tile t;
/* FIXME: this sorting only works for a 45-degree camera */ /* FIXME: this sorting only works for a 45-degree camera */
t.prio = -pos.y - 2 * 32 * pos.z + (o ? 0 : 32);
t.prio = -pos.y - 2 * 32 * pos.z + ((float)o ? 0 : 32);
t.tileset = tileset; t.tileset = tileset;
t.id = id; t.id = id;
t.pos = pos; t.pos = pos;


Loading…
Cancel
Save