Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

143 строки
4.1 KiB

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