2022-02-18 18:33:12 +01:00
|
|
|
/* Copyright (C) 2022 Wildfire Games.
|
2023-07-27 22:54:46 +02:00
|
|
|
* This file is part of 0 A.D.
|
2009-04-18 19:00:33 +02:00
|
|
|
*
|
2023-07-27 22:54:46 +02:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-04-18 19:00:33 +02:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2023-07-27 22:54:46 +02:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-04-18 19:00:33 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-07-27 22:54:46 +02:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-18 19:00:33 +02:00
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* Definition of ModelVertexRenderer, the abstract base class for model
|
|
|
|
* vertex transformation implementations.
|
2005-11-06 00:15:23 +01:00
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_MODELVERTEXRENDERER
|
|
|
|
#define INCLUDED_MODELVERTEXRENDERER
|
2005-11-06 00:15:23 +01:00
|
|
|
|
|
|
|
#include "graphics/MeshManager.h"
|
2014-07-03 00:36:45 +02:00
|
|
|
#include "graphics/ShaderProgramPtr.h"
|
2022-05-09 00:02:46 +02:00
|
|
|
#include "renderer/backend/IDeviceCommandContext.h"
|
2022-05-02 22:57:22 +02:00
|
|
|
#include "renderer/backend/IShaderProgram.h"
|
2005-11-06 00:15:23 +01:00
|
|
|
|
|
|
|
class CModel;
|
2012-04-03 20:44:46 +02:00
|
|
|
class CModelRData;
|
2005-11-06 00:15:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ModelVertexRenderer: Normal ModelRenderer implementations delegate
|
|
|
|
* vertex array management and vertex transformation to an implementation of
|
|
|
|
* ModelVertexRenderer.
|
2006-03-26 01:54:20 +01:00
|
|
|
*
|
2005-11-06 00:15:23 +01:00
|
|
|
* ModelVertexRenderer implementations should be designed so that one
|
|
|
|
* instance of the implementation can be used with more than one ModelRenderer
|
|
|
|
* simultaneously.
|
|
|
|
*/
|
|
|
|
class ModelVertexRenderer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ModelVertexRenderer() { }
|
2006-03-26 01:54:20 +01:00
|
|
|
|
|
|
|
|
2005-11-06 00:15:23 +01:00
|
|
|
/**
|
|
|
|
* CreateModelData: Create internal data for one model.
|
|
|
|
*
|
|
|
|
* ModelRenderer implementations must call this once for every
|
2012-04-03 20:44:46 +02:00
|
|
|
* model that will later be rendered, with @p key set to a value
|
|
|
|
* that's unique to that ModelRenderer.
|
2006-03-26 01:54:20 +01:00
|
|
|
*
|
2005-11-06 00:15:23 +01:00
|
|
|
* ModelVertexRenderer implementations should use this function to
|
|
|
|
* create per-CModel and per-CModelDef data like vertex arrays.
|
|
|
|
*
|
2012-04-03 20:44:46 +02:00
|
|
|
* @param key An opaque pointer to pass to the CModelRData constructor
|
2005-11-06 00:15:23 +01:00
|
|
|
* @param model The model.
|
|
|
|
*
|
2012-04-03 20:44:46 +02:00
|
|
|
* @return A new CModelRData that will be passed into other
|
|
|
|
* ModelVertexRenderer functions whenever the same CModel is used again.
|
2005-11-06 00:15:23 +01:00
|
|
|
*/
|
2012-04-03 20:44:46 +02:00
|
|
|
virtual CModelRData* CreateModelData(const void* key, CModel* model) = 0;
|
2005-11-06 00:15:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UpdateModelData: Calculate per-model data for each frame.
|
|
|
|
*
|
|
|
|
* ModelRenderer implementations must call this once per frame for
|
|
|
|
* every model that is to be rendered in this frame, even if the
|
|
|
|
* value of updateflags will be zero.
|
|
|
|
* This implies that this function will also be called at least once
|
|
|
|
* between a call to CreateModelData and a call to RenderModel.
|
2006-03-26 01:54:20 +01:00
|
|
|
*
|
2005-11-06 00:15:23 +01:00
|
|
|
* ModelVertexRenderer implementations should use this function to
|
|
|
|
* perform software vertex transforms and potentially other per-frame
|
|
|
|
* calculations.
|
2006-03-26 01:54:20 +01:00
|
|
|
*
|
2005-11-06 00:15:23 +01:00
|
|
|
* @param model The model.
|
|
|
|
* @param data Private data as returned by CreateModelData.
|
|
|
|
* @param updateflags Flags indicating which data has changed during
|
|
|
|
* the frame. The value is the same as the value of the model's
|
|
|
|
* CRenderData::m_UpdateFlags.
|
|
|
|
*/
|
2012-04-03 20:44:46 +02:00
|
|
|
virtual void UpdateModelData(CModel* model, CModelRData* data, int updateflags) = 0;
|
2005-11-06 00:15:23 +01:00
|
|
|
|
|
|
|
/**
|
2022-10-30 01:20:04 +02:00
|
|
|
* Upload per-model data to backend.
|
2005-11-06 00:15:23 +01:00
|
|
|
*
|
2022-10-30 01:20:04 +02:00
|
|
|
* ModelRenderer implementations must call this after UpdateModelData once
|
|
|
|
* per frame for every model that is to be rendered in this frame.
|
2005-11-06 00:15:23 +01:00
|
|
|
*
|
2022-10-30 01:20:04 +02:00
|
|
|
* ModelVertexRenderer implementations should use this function to
|
|
|
|
* upload all needed data to backend.
|
2005-11-06 00:15:23 +01:00
|
|
|
*/
|
2022-10-30 01:20:04 +02:00
|
|
|
virtual void UploadModelData(
|
|
|
|
Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
|
|
|
|
CModel* model, CModelRData* data) = 0;
|
2006-03-26 01:54:20 +01:00
|
|
|
|
2005-11-06 00:15:23 +01:00
|
|
|
/**
|
2022-05-02 22:57:22 +02:00
|
|
|
* PrepareModelDef: Setup backend state for rendering of models that
|
2005-11-06 00:15:23 +01:00
|
|
|
* use the given CModelDef object as base.
|
2006-03-26 01:54:20 +01:00
|
|
|
*
|
2005-11-06 00:15:23 +01:00
|
|
|
* ModelRenderer implementations must call this function before
|
|
|
|
* rendering a sequence of models based on the given CModelDef.
|
|
|
|
* When a ModelRenderer switches back and forth between CModelDefs,
|
|
|
|
* it must call PrepareModelDef for every switch.
|
|
|
|
*
|
|
|
|
* @param def The model definition.
|
|
|
|
*/
|
2022-02-18 18:33:12 +01:00
|
|
|
virtual void PrepareModelDef(
|
2022-05-09 00:02:46 +02:00
|
|
|
Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
|
2022-05-02 22:57:22 +02:00
|
|
|
const CModelDef& def) = 0;
|
2005-11-06 00:15:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RenderModel: Invoke the rendering commands for the given model.
|
2006-03-26 01:54:20 +01:00
|
|
|
*
|
2005-11-06 00:15:23 +01:00
|
|
|
* ModelRenderer implementations must call this function to perform
|
|
|
|
* the actual rendering.
|
|
|
|
*
|
|
|
|
* preconditions : The most recent call to PrepareModelDef since
|
|
|
|
* BeginPass has been for model->GetModelDef().
|
|
|
|
*
|
|
|
|
* @param model The model that should be rendered.
|
|
|
|
* @param data Private data for the model as returned by CreateModelData.
|
|
|
|
*
|
|
|
|
* postconditions : Subsequent calls to RenderModel for models
|
|
|
|
* that use the same CModelDef object and the same texture must
|
|
|
|
* succeed.
|
|
|
|
*/
|
2022-02-18 18:33:12 +01:00
|
|
|
virtual void RenderModel(
|
2022-05-09 00:02:46 +02:00
|
|
|
Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
|
2022-05-02 22:57:22 +02:00
|
|
|
Renderer::Backend::IShaderProgram* shader, CModel* model, CModelRData* data) = 0;
|
2005-11-06 00:15:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // INCLUDED_MODELVERTEXRENDERER
|