LCOV - code coverage report
Current view: top level - source/renderer - ModelVertexRenderer.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 1 2 50.0 %
Date: 2026-12-03 01:19:39 Functions: 0 0 -

          Line data    Source code
       1             : /* Copyright (C) 2025 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             : /*
      19             :  * Definition of ModelVertexRenderer, the abstract base class for model
      20             :  * vertex transformation implementations.
      21             :  */
      22             : 
      23             : #ifndef INCLUDED_MODELVERTEXRENDERER
      24             : #define INCLUDED_MODELVERTEXRENDERER
      25             : 
      26             : #include "graphics/MeshManager.h"
      27             : 
      28             : #include <span>
      29             : 
      30             : class CModel;
      31             : class CModelDef;
      32             : class CModelRData;
      33             : namespace Renderer::Backend { class IDeviceCommandContext; }
      34             : namespace Renderer::Backend { class IShaderProgram; }
      35             : 
      36             : /**
      37             :  * Class ModelVertexRenderer: Normal ModelRenderer implementations delegate
      38             :  * vertex array management and vertex transformation to an implementation of
      39             :  * ModelVertexRenderer.
      40             :  *
      41             :  * ModelVertexRenderer implementations should be designed so that one
      42             :  * instance of the implementation can be used with more than one ModelRenderer
      43             :  * simultaneously.
      44             :  */
      45          20 : class ModelVertexRenderer
      46             : {
      47             : public:
      48           0 :     virtual ~ModelVertexRenderer() { }
      49             : 
      50             : 
      51             :     /**
      52             :      * CreateModelData: Create internal data for one model.
      53             :      *
      54             :      * ModelRenderer implementations must call this once for every
      55             :      * model that will later be rendered, with @p key set to a value
      56             :      * that's unique to that ModelRenderer.
      57             :      *
      58             :      * ModelVertexRenderer implementations should use this function to
      59             :      * create per-CModel and per-CModelDef data like vertex arrays.
      60             :      *
      61             :      * @param key An opaque pointer to pass to the CModelRData constructor
      62             :      * @param model The model.
      63             :      *
      64             :      * @return A new CModelRData that will be passed into other
      65             :      * ModelVertexRenderer functions whenever the same CModel is used again.
      66             :      */
      67             :     virtual CModelRData* CreateModelData(const void* key, CModel* model) = 0;
      68             : 
      69             : 
      70             :     /**
      71             :      * UpdateModelData: Calculate per-model data for each frame.
      72             :      *
      73             :      * ModelRenderer implementations must call this once per frame for
      74             :      * every model that is to be rendered in this frame, even if the
      75             :      * value of updateflags will be zero.
      76             :      * This implies that this function will also be called at least once
      77             :      * between a call to CreateModelData and a call to RenderModel.
      78             :      *
      79             :      * ModelVertexRenderer implementations should use this function to
      80             :      * perform software vertex transforms and potentially other per-frame
      81             :      * calculations.
      82             :      *
      83             :      * @param deviceCommandContext context for backend commands (f.e. uploading).
      84             :      * @param models models.
      85             :      */
      86             :     virtual void UpdateModelsData(
      87             :         Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
      88             :         std::span<CModel*> models) = 0;
      89             : 
      90             :     /**
      91             :      * Upload per-model data to backend.
      92             :      *
      93             :      * ModelRenderer implementations must call this after UpdateModelData once
      94             :      * per frame for every model that is to be rendered in this frame.
      95             :      *
      96             :      * ModelVertexRenderer implementations should use this function to
      97             :      * upload all needed data to backend.
      98             :      *
      99             :      * @param deviceCommandContext context for backend commands (f.e. uploading).
     100             :      * @param models models.
     101             :      */
     102             :     virtual void UploadModelsData(
     103             :         Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
     104             :         std::span<CModel*> models) = 0;
     105             : 
     106             :     /**
     107             :      * PrepareModelDef: Setup backend state for rendering of models that
     108             :      * use the given CModelDef object as base.
     109             :      *
     110             :      * ModelRenderer implementations must call this function before
     111             :      * rendering a sequence of models based on the given CModelDef.
     112             :      * When a ModelRenderer switches back and forth between CModelDefs,
     113             :      * it must call PrepareModelDef for every switch.
     114             :      *
     115             :      * @param def The model definition.
     116             :      */
     117             :     virtual void PrepareModelDef(
     118             :         Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
     119             :         const CModelDef& def) = 0;
     120             : 
     121             : 
     122             :     /**
     123             :      * RenderModel: Invoke the rendering commands for the given model.
     124             :      *
     125             :      * ModelRenderer implementations must call this function to perform
     126             :      * the actual rendering.
     127             :      *
     128             :      * preconditions  : The most recent call to PrepareModelDef since
     129             :      * BeginPass has been for model->GetModelDef().
     130             :      *
     131             :      * @param model The model that should be rendered.
     132             :      * @param data Private data for the model as returned by CreateModelData.
     133             :      *
     134             :      * postconditions : Subsequent calls to RenderModel for models
     135             :      * that use the same CModelDef object and the same texture must
     136             :      * succeed.
     137             :      */
     138             :     virtual void RenderModel(
     139             :         Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
     140             :         Renderer::Backend::IShaderProgram* shader, CModel* model, CModelRData* data) = 0;
     141             : };
     142             : 
     143             : 
     144             : #endif // INCLUDED_MODELVERTEXRENDERER

Generated by: LCOV version 1.16