You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.6 KiB

  1. //
  2. // Lol Engine
  3. //
  4. // Copyright: (c) 2009-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
  5. // (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
  6. // (c) 2009-2013 Cédric Lecacheur <jordx@free.fr>
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the Do What The Fuck You Want To
  9. // Public License, Version 2, as published by Sam Hocevar. See
  10. // http://www.wtfpl.net/ for more details.
  11. //
  12. #pragma once
  13. //
  14. // The EasyMesh class
  15. // ------------------
  16. //
  17. namespace lol
  18. {
  19. // Utility enum for renderers
  20. LOL_SAFE_ENUM(MeshRender,
  21. NeedData,
  22. NeedConvert,
  23. CanRender,
  24. IgnoreRender,
  25. );
  26. //Vertex datas for easymesh vertex list.
  27. //TODO : <COORD, NORM, COLOR, UV>
  28. struct VertexData
  29. {
  30. vec3 m_coord;
  31. vec3 m_normal;
  32. vec4 m_color;
  33. vec4 m_texcoord;
  34. ivec4 m_bone_id;
  35. vec4 m_bone_weight;
  36. VertexData(vec3 new_coord = vec3(0.f),
  37. vec3 new_normal = vec3(0.f, 1.f, 0.f),
  38. vec4 new_color = vec4(0.f),
  39. vec4 new_texcoord = vec4(0.f),
  40. ivec4 new_bone_id = ivec4(0),
  41. vec4 new_bone_weight= vec4(0.f))
  42. {
  43. m_coord = new_coord;
  44. m_normal = new_normal;
  45. m_color = new_color;
  46. m_texcoord = new_texcoord;
  47. m_bone_id = new_bone_id;
  48. m_bone_weight = new_bone_weight;
  49. }
  50. };
  51. //Base class to declare shader datas
  52. class GpuShaderData
  53. {
  54. friend class GpuEasyMeshData;
  55. protected:
  56. GpuShaderData();
  57. public:
  58. //--
  59. GpuShaderData(uint16_t vert_decl_flags, Shader* shader, DebugRenderMode render_mode);
  60. virtual ~GpuShaderData();
  61. //--
  62. void AddUniform(const lol::String &new_uniform);
  63. void AddAttribute(VertexUsage usage, int index);
  64. ShaderUniform const *GetUniform(const lol::String &uniform);
  65. ShaderAttrib const *GetAttribute(VertexUsage usage, int index);
  66. //--
  67. virtual void SetupShaderDatas(mat4 const &model) { UNUSED(model); }
  68. //--
  69. protected:
  70. uint16_t m_vert_decl_flags;
  71. Shader* m_shader;
  72. int m_render_mode;
  73. array<lol::String, ShaderUniform> m_shader_uniform;
  74. array<ShaderAttrib> m_shader_attrib;
  75. };
  76. class DefaultShaderData : public GpuShaderData
  77. {
  78. public:
  79. //---
  80. DefaultShaderData(DebugRenderMode render_mode);
  81. DefaultShaderData(uint16_t vert_decl_flags, Shader* shader, bool with_UV);
  82. virtual ~DefaultShaderData() {}
  83. void StoreUniformNames();
  84. //---
  85. void SetupDefaultData(bool with_UV);
  86. virtual void SetupShaderDatas(mat4 const &model);
  87. //--
  88. array<String> m_uniform_names;
  89. };
  90. class GpuEasyMeshData
  91. {
  92. friend class EasyMesh;
  93. public:
  94. //---
  95. GpuEasyMeshData();
  96. ~GpuEasyMeshData();
  97. //---
  98. void AddGpuData(GpuShaderData* gpudata, class EasyMesh* src_mesh);
  99. void RenderMeshData(mat4 const &model, int render_mode=Video::GetDebugRenderMode());
  100. bool HasData(int render_mode) { return (0 <= render_mode && render_mode < m_gpudatas.Count() && !!m_gpudatas[render_mode]); }
  101. private:
  102. void SetupVertexData(uint16_t vdecl_flags, EasyMesh* src_mesh);
  103. array<GpuShaderData*> m_gpudatas;
  104. //uint16_t are the vdecl/vbo flags to avoid copy same vdecl several times.
  105. array<uint16_t, VertexDeclaration*,
  106. VertexBuffer*> m_vdatas;
  107. int m_vertexcount;
  108. //We only need only one ibo for the whole mesh
  109. IndexBuffer * m_ibo;
  110. int m_indexcount;
  111. };
  112. } /* namespace lol */