LCOV - code coverage report
Current view: top level - source/renderer/backend/gl - Buffer.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 1 22 4.5 %
Date: 2023-01-19 00:18:29 Functions: 2 6 33.3 %

          Line data    Source code
       1             : /* Copyright (C) 2023 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "precompiled.h"
      19             : 
      20             : #include "Buffer.h"
      21             : 
      22             : #include "lib/code_annotation.h"
      23             : #include "lib/config2.h"
      24             : #include "ps/CLogger.h"
      25             : #include "ps/ConfigDB.h"
      26             : #include "renderer/backend/gl/Device.h"
      27             : #include "renderer/backend/gl/Texture.h"
      28             : 
      29             : namespace Renderer
      30             : {
      31             : 
      32             : namespace Backend
      33             : {
      34             : 
      35             : namespace GL
      36             : {
      37             : 
      38             : // static
      39           0 : std::unique_ptr<CBuffer> CBuffer::Create(
      40             :     CDevice* device, const char* name,
      41             :     const Type type, const uint32_t size, const bool dynamic)
      42             : {
      43           0 :     ENSURE(type == Type::VERTEX || type == Type::INDEX);
      44           0 :     std::unique_ptr<CBuffer> buffer(new CBuffer());
      45           0 :     buffer->m_Device = device;
      46           0 :     buffer->m_Type = type;
      47           0 :     buffer->m_Size = size;
      48           0 :     buffer->m_Dynamic = dynamic;
      49           0 :     glGenBuffersARB(1, &buffer->m_Handle);
      50           0 :     const GLenum target = type == Type::INDEX ? GL_ELEMENT_ARRAY_BUFFER : GL_ARRAY_BUFFER;
      51           0 :     glBindBufferARB(target, buffer->m_Handle);
      52           0 :     glBufferDataARB(target, size, nullptr, dynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW);
      53             : #if !CONFIG2_GLES
      54           0 :     if (buffer->m_Device->GetCapabilities().debugLabels)
      55             :     {
      56           0 :         glObjectLabel(GL_BUFFER, buffer->m_Handle, -1, name);
      57             :     }
      58             : #else
      59             :     UNUSED2(name);
      60             : #endif
      61           0 :     glBindBufferARB(target, 0);
      62           0 :     return buffer;
      63             : }
      64             : 
      65             : CBuffer::CBuffer() = default;
      66             : 
      67           0 : CBuffer::~CBuffer()
      68             : {
      69           0 :     if (m_Handle)
      70           0 :         glDeleteBuffersARB(1, &m_Handle);
      71           0 : }
      72             : 
      73           0 : IDevice* CBuffer::GetDevice()
      74             : {
      75           0 :     return m_Device;
      76             : }
      77             : 
      78             : } // namespace GL
      79             : 
      80             : } // namespace Backend
      81             : 
      82           3 : } // namespace Renderer

Generated by: LCOV version 1.13