6 #include <unordered_map>
35 using std::unique_ptr;
36 using std::unordered_map;
100 xAxis.
set(matrix[0], matrix[1], matrix[2]);
101 yAxis.
set(matrix[4], matrix[5], matrix[6]);
102 zAxis.
set(matrix[8], matrix[9], matrix[10]);
104 return Vector3::computeDotProduct(Vector3::computeCrossProduct(
xAxis,
yAxis),
zAxis) < 0.0f;
130 std::size_t
operator()(
const tuple<Model*, ObjectNode*, int32_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, int32_t, const Material*, bool, uint8_t>& k)
const {
131 std::hash<uint64_t> hashVal;
133 reinterpret_cast<uint64_t
>(get<0>(k)) ^
134 reinterpret_cast<uint64_t
>(get<1>(k)) ^
135 static_cast<uint64_t
>(get<2>(k)) ^
136 static_cast<uint64_t
>(get<3>(k)) ^
137 static_cast<uint64_t
>(get<4>(k)) ^
138 static_cast<uint64_t
>(get<5>(k)) ^
139 static_cast<uint64_t
>(get<6>(k)) ^
140 static_cast<uint64_t
>(get<7>(k)) ^
141 static_cast<uint64_t
>(get<8>(k)) ^
142 static_cast<uint64_t
>(get<9>(k)) ^
143 static_cast<uint64_t
>(get<10>(k)) ^
144 reinterpret_cast<uint64_t
>(get<11>(k)) ^
145 static_cast<uint64_t
>(get<12>(k)) ^
146 static_cast<uint64_t
>(get<13>(k))
150 unordered_map<tuple<Model*, ObjectNode*, int32_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, int32_t, const Material*, bool, uint8_t>,
TransparentRenderFacesGroup*,
TransparentRenderFacesGroup_Hash>
transparentRenderFacesGroups;
229 void setupMaterial(
int contextIdx,
ObjectNode* objectNode, int32_t facesEntityIdx, int32_t renderTypes,
bool updateOnly,
string& materialKey,
const string& currentMaterialKey =
string());
248 const vector<Object*>& objects,
254 if (objects.empty() ==
true)
return;
262 auto maxObjectUniqueId = -1;
263 for (
auto objectIdx = 0; objectIdx < objects.size(); objectIdx++) {
264 auto object = objects[objectIdx];
265 if (object->enabledInstances == 0)
continue;
266 if (effectPass != 0 && object->excludeFromEffectPass == effectPass)
continue;
267 if (object->renderPass != renderPass)
continue;
268 auto uniqueModelId =
object->getUniqueModelId();
271 if (objectsByModel.empty() ==
true) {
272 minObjectUniqueId = Math::min(uniqueModelId, minObjectUniqueId);
273 maxObjectUniqueId = Math::max(uniqueModelId, maxObjectUniqueId);
275 objectsByModel.push_back(
object);
281 auto& context =
contexts[threadIdx];
282 for (
auto i = minObjectUniqueId; i < maxObjectUniqueId; i++) {
284 if (objectsByModel.size() == 0) {
287 if (objectsByModel.size() > 0) {
289 for (
auto object: objectsByModel) {
290 if (context.objectsByModelToRender.size() == 0 ||
291 (object->instances == context.objectsByModelToRender[0]->instances &&
292 object->enabledInstances == context.objectsByModelToRender[0]->enabledInstances)) {
293 context.objectsByModelToRender.push_back(
object);
295 context.objectsByModelNotRendered.push_back(
object);
299 objectsByModel = context.objectsByModelNotRendered;
300 context.objectsByModelToRender.clear();
301 context.objectsByModelNotRendered.clear();
302 }
while (objectsByModel.size() > 0);
304 objectsByModel.clear();
Color 4 definition class.
static constexpr int UNIQUEMODELID_NONE
static constexpr int UNIQUEMODELID_MAX
Fog particle system entity to be used with engine class.
Lines entity to be used with engine class.
Object to be used with engine class.
Point particle system entity to be used with engine class.
Representation of a 3D model.
int32_t getEffectPass()
Get effect pass.
virtual bool isInstancedRenderingAvailable()=0
Checks if instanced rendering is available.
void setShader(int contextIdx, const string &id)
Set shader.
Batch renderer for points.
Batch renderer for transparent triangles.
Simple class to determine if a transform matrix is right handed.
RightHandedMatrix4x4()
Public constructor.
bool isRightHanded(Matrix4x4 &matrix)
Check if matrix is right handed.
EntityRenderer(Engine *engine, Renderer *renderer)
Public constructor.
static constexpr int32_t RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY
static constexpr int32_t INSTANCEDRENDERING_OBJECTS_MAX
void prepareTransparentFaces(const vector< TransparentRenderFace * > &transparentRenderFaces)
Renders transparent faces TODO: guess this should be optimized regarding GL commands skinned mesh is ...
bool checkMaterialChangable(ObjectNode *objectNode, int32_t facesEntityIdx, int32_t renderTypes)
Checks if a material could change when having multiple objects but same model.
void render(Entity::RenderPass renderPass, const vector< Object * > &objects, bool renderTransparentFaces, int32_t renderTypes)
Renders all given objects.
unique_ptr< RenderTransparentRenderPointsPool > renderTransparentRenderPointsPool
static constexpr int32_t RENDERTYPE_TEXTUREARRAYS
void renderFunction(int threadIdx, Entity::RenderPass renderPass, const vector< Object * > &objects, array< vector< Object * >, Engine::UNIQUEMODELID_MAX > &objectsByModels, bool renderTransparentFaces, int renderTypes, TransparentRenderFacesPool *transparentRenderFacesPool)
Render function.
unique_ptr< EntityRenderer_TransparentRenderFacesGroupPool > transparentRenderFacesGroupPool
array< vector< Object * >, Engine::UNIQUEMODELID_MAX > objectsByModels
static constexpr int32_t RENDERTYPE_NORMALS
BatchRendererTriangles * acquireTrianglesBatchRenderer()
static constexpr int32_t RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY
void renderObjectsOfSameType(int threadIdx, const vector< Object * > &objects, bool collectTransparentFaces, int32_t renderTypes, TransparentRenderFacesPool *transparentRenderFacesPool)
Renders multiple objects of same type(with same model)
static constexpr int32_t RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY
static constexpr int32_t RENDERTYPE_ALL
unique_ptr< TransparentRenderFacesPool > transparentRenderFacesPool
static constexpr int32_t RENDERTYPE_TEXTURES
static constexpr int32_t RENDERTYPE_MATERIALS
static constexpr int32_t RENDERTYPE_SHADOWMAPPING
void setupMaterial(int contextIdx, ObjectNode *objectNode, int32_t facesEntityIdx, int32_t renderTypes, bool updateOnly, string &materialKey, const string ¤tMaterialKey=string())
Set ups a material for rendering.
void renderObjectsOfSameTypeInstanced(int threadIdx, const vector< Object * > &objects, bool collectTransparentFaces, int32_t renderTypes, TransparentRenderFacesPool *transparentRenderFacesPool)
Renders multiple objects of same type(with same model) using instancing.
void releaseTransparentFacesGroups()
Release transparent faces groups.
static constexpr int32_t RENDERTYPE_RENDERGROUP_OBJECTORIGIN
unordered_map< tuple< Model *, ObjectNode *, int32_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, int32_t, const Material *, bool, uint8_t >, TransparentRenderFacesGroup *, TransparentRenderFacesGroup_Hash > transparentRenderFacesGroups
vector< ObjectRenderContext > contexts
static constexpr int32_t RENDERTYPE_LIGHTS
vector< unique_ptr< BatchRendererTriangles > > trianglesBatchRenderers
static constexpr int32_t RENDERTYPE_EFFECTCOLORS
unique_ptr< BatchRendererPoints > psePointBatchRenderer
void renderTransparentFacesGroups(int contextIdx)
Render transparent faces groups.
vector< TransparentRenderFace * > nodeTransparentRenderFaces
void clearMaterial(int contextIdx)
Clear material for rendering.
static constexpr int32_t BATCHRENDERER_MAX
void reset()
Resets the object renderer.
~EntityRenderer()
Destructor.
void renderObjectsOfSameTypeNonInstanced(const vector< Object * > &objects, bool collectTransparentFaces, int32_t renderTypes)
Renders multiple objects of same type(with same model) not using instancing.
void renderTransparentFaces()
Renders collected transparent faces.
Object node VBO renderer.
Object node specifically for rendering.
vector< int32_t > specularMaterialDynamicDiffuseTextureIdsByEntities
static constexpr int32_t TEXTUREID_NONE
Transparent render faces group.
Transparent render faces pool.
Transparent render points pool.
Matrix3x3 class representing matrix3x3 mathematical structure and operations for 2d space.
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Vector2 class representing vector2 mathematical structure and operations with x, y components.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
vector< Object * > objectsNotRendered
vector< Object * > objectsToRender
vector< Object * > objectsByModelToRender
RightHandedMatrix4x4 rightHandedMatrix
vector< int32_t > * vboInstancedRenderingIds
unique_ptr< ByteBuffer > bbMvMatrices
unique_ptr< ByteBuffer > bbEffectColorAdds
unique_ptr< ByteBuffer > bbEffectColorMuls
vector< Object * > objectsByModelNotRendered
std::size_t operator()(const tuple< Model *, ObjectNode *, int32_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, int32_t, const Material *, bool, uint8_t > &k) const
#define FORBID_CLASS_COPY(CLASS)