| 37 | }; |
| 38 | |
| 39 | void InitializeDebugRenderer(dmRender::HRenderContext render_context, uint32_t max_vertex_count, const void* sp_desc, uint32_t sp_desc_size) |
| 40 | { |
| 41 | DebugRenderer& debug_renderer = render_context->m_DebugRenderer; |
| 42 | debug_renderer.m_MaxVertexCount = max_vertex_count; |
| 43 | |
| 44 | debug_renderer.m_RenderContext = render_context; |
| 45 | const uint32_t buffer_size = max_vertex_count * sizeof(DebugVertex); |
| 46 | const uint32_t total_buffer_size = MAX_DEBUG_RENDER_TYPE_COUNT * buffer_size; |
| 47 | debug_renderer.m_VertexBuffer = dmGraphics::NewVertexBuffer(render_context->m_GraphicsContext, total_buffer_size, 0x0, dmGraphics::BUFFER_USAGE_STREAM_DRAW); |
| 48 | |
| 49 | dmGraphics::HVertexStreamDeclaration stream_declaration = dmGraphics::NewVertexStreamDeclaration(render_context->m_GraphicsContext); |
| 50 | |
| 51 | dmGraphics::AddVertexStream(stream_declaration, "position", 4, dmGraphics::TYPE_FLOAT, false); |
| 52 | dmGraphics::AddVertexStream(stream_declaration, "color", 4, dmGraphics::TYPE_FLOAT, false); |
| 53 | |
| 54 | debug_renderer.m_VertexDeclaration = dmGraphics::NewVertexDeclaration(render_context->m_GraphicsContext, stream_declaration); |
| 55 | |
| 56 | dmGraphics::DeleteVertexStreamDeclaration(stream_declaration); |
| 57 | |
| 58 | dmGraphics::HProgram program = dmGraphics::INVALID_PROGRAM_HANDLE; |
| 59 | |
| 60 | if (sp_desc_size > 0) |
| 61 | { |
| 62 | dmGraphics::ShaderDesc* shader_desc; |
| 63 | dmDDF::Result e = dmDDF::LoadMessage(sp_desc, sp_desc_size, &dmGraphics_ShaderDesc_DESCRIPTOR, (void**) &shader_desc); |
| 64 | if (e != dmDDF::RESULT_OK) |
| 65 | { |
| 66 | dmLogWarning("Failed to create DebugRenderer shader (%d)", e); |
| 67 | } |
| 68 | else |
| 69 | { |
| 70 | program = dmGraphics::NewProgram(render_context->m_GraphicsContext, shader_desc, 0, 0); |
| 71 | dmDDF::FreeMessage(shader_desc); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | HMaterial material3d = NewMaterial(render_context, program); |
| 76 | SetMaterialProgramConstantType(material3d, dmHashString64("view_proj"), dmRenderDDF::MaterialDesc::CONSTANT_TYPE_VIEWPROJ); |
| 77 | dmhash_t debug_tag_3d = dmHashString64(DEBUG_3D_NAME); |
| 78 | SetMaterialTags(material3d, 1, &debug_tag_3d); |
| 79 | |
| 80 | dmGraphics::PrimitiveType primitive_types[MAX_DEBUG_RENDER_TYPE_COUNT] = {dmGraphics::PRIMITIVE_TRIANGLES, dmGraphics::PRIMITIVE_LINES}; |
| 81 | HMaterial materials[MAX_DEBUG_RENDER_TYPE_COUNT] = {material3d, material3d}; |
| 82 | |
| 83 | for (uint32_t i = 0; i < MAX_DEBUG_RENDER_TYPE_COUNT; ++i) |
| 84 | { |
| 85 | RenderObject ro; |
| 86 | ro.m_Material = materials[i]; |
| 87 | ro.m_PrimitiveType = primitive_types[i]; |
| 88 | ro.m_VertexBuffer = debug_renderer.m_VertexBuffer; |
| 89 | ro.m_VertexDeclaration = debug_renderer.m_VertexDeclaration; |
| 90 | ro.m_VertexCount = 0; |
| 91 | DebugRenderTypeData& type_data = debug_renderer.m_TypeData[i]; |
| 92 | type_data.m_RenderObject = ro; |
| 93 | type_data.m_ClientBuffer = new char[buffer_size]; |
| 94 | } |
| 95 | |
| 96 | debug_renderer.m_3dPredicate.m_Tags[0] = dmHashString64(DEBUG_3D_NAME); |
no test coverage detected