1 /* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
19 * Definition of ModelVertexRenderer, the abstract base class for model
20 * vertex transformation implementations.
23 #ifndef INCLUDED_MODELVERTEXRENDERER
24 #define INCLUDED_MODELVERTEXRENDERER
26 #include "graphics/MeshManager.h"
27 #include "graphics/ShaderProgramPtr.h"
28 #include "renderer/backend/IDeviceCommandContext.h"
29 #include "renderer/backend/IShaderProgram.h"
35 * Class ModelVertexRenderer: Normal ModelRenderer implementations delegate
36 * vertex array management and vertex transformation to an implementation of
37 * ModelVertexRenderer.
39 * ModelVertexRenderer implementations should be designed so that one
40 * instance of the implementation can be used with more than one ModelRenderer
43 class ModelVertexRenderer
46 virtual ~ModelVertexRenderer() { }
50 * CreateModelData: Create internal data for one model.
52 * ModelRenderer implementations must call this once for every
53 * model that will later be rendered, with @p key set to a value
54 * that's unique to that ModelRenderer.
56 * ModelVertexRenderer implementations should use this function to
57 * create per-CModel and per-CModelDef data like vertex arrays.
59 * @param key An opaque pointer to pass to the CModelRData constructor
60 * @param model The model.
62 * @return A new CModelRData that will be passed into other
63 * ModelVertexRenderer functions whenever the same CModel is used again.
65 virtual CModelRData
* CreateModelData(const void* key
, CModel
* model
) = 0;
69 * UpdateModelData: Calculate per-model data for each frame.
71 * ModelRenderer implementations must call this once per frame for
72 * every model that is to be rendered in this frame, even if the
73 * value of updateflags will be zero.
74 * This implies that this function will also be called at least once
75 * between a call to CreateModelData and a call to RenderModel.
77 * ModelVertexRenderer implementations should use this function to
78 * perform software vertex transforms and potentially other per-frame
81 * @param model The model.
82 * @param data Private data as returned by CreateModelData.
83 * @param updateflags Flags indicating which data has changed during
84 * the frame. The value is the same as the value of the model's
85 * CRenderData::m_UpdateFlags.
87 virtual void UpdateModelData(CModel
* model
, CModelRData
* data
, int updateflags
) = 0;
90 * Upload per-model data to backend.
92 * ModelRenderer implementations must call this after UpdateModelData once
93 * per frame for every model that is to be rendered in this frame.
95 * ModelVertexRenderer implementations should use this function to
96 * upload all needed data to backend.
98 virtual void UploadModelData(
99 Renderer::Backend::IDeviceCommandContext
* deviceCommandContext
,
100 CModel
* model
, CModelRData
* data
) = 0;
103 * PrepareModelDef: Setup backend state for rendering of models that
104 * use the given CModelDef object as base.
106 * ModelRenderer implementations must call this function before
107 * rendering a sequence of models based on the given CModelDef.
108 * When a ModelRenderer switches back and forth between CModelDefs,
109 * it must call PrepareModelDef for every switch.
111 * @param def The model definition.
113 virtual void PrepareModelDef(
114 Renderer::Backend::IDeviceCommandContext
* deviceCommandContext
,
115 const CModelDef
& def
) = 0;
119 * RenderModel: Invoke the rendering commands for the given model.
121 * ModelRenderer implementations must call this function to perform
122 * the actual rendering.
124 * preconditions : The most recent call to PrepareModelDef since
125 * BeginPass has been for model->GetModelDef().
127 * @param model The model that should be rendered.
128 * @param data Private data for the model as returned by CreateModelData.
130 * postconditions : Subsequent calls to RenderModel for models
131 * that use the same CModelDef object and the same texture must
134 virtual void RenderModel(
135 Renderer::Backend::IDeviceCommandContext
* deviceCommandContext
,
136 Renderer::Backend::IShaderProgram
* shader
, CModel
* model
, CModelRData
* data
) = 0;
140 #endif // INCLUDED_MODELVERTEXRENDERER