1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 /* MeshSceneNode:
14  *  Encapsulates information for rendering a mesh fragment
15  *      (a collection of faces with the same material properties).
16  *  Does not support level of detail.
17  */
18 
19 #ifndef BZF_MESH_SCENE_NODE_H
20 #define BZF_MESH_SCENE_NODE_H
21 
22 // Inherits
23 #include "SceneNode.h"
24 
25 // Common headers
26 #include "bzfgl.h"
27 //
28 // NOTES:
29 //
30 // - Make sure that "noPlane" is set to true, for Mesh can not be
31 //   used as occluders, and can not be culled as a simple plane
32 //
33 // - All accesses are done through indices
34 //
35 
36 class MeshObstacle;
37 class MeshDrawInfo;
38 class MeshDrawMgr;
39 class BzMaterial;
40 class OpenGLGState;
41 class SceneRenderer;
42 class ViewFrustum;
43 class RenderNode;
44 
45 
46 class MeshSceneNode : public SceneNode
47 {
48 public:
49     MeshSceneNode(const MeshObstacle* mesh);
50     ~MeshSceneNode();
51 
52     // virtual functions from SceneNode
53 
54     void notifyStyleChange();
55 
56     bool cull(const ViewFrustum&) const;
57     bool inAxisBox(const Extents& exts) const;
58 
59     void addShadowNodes(SceneRenderer&);
60     void addRenderNodes(SceneRenderer&);
61     void renderRadar();
62 
63     void getRenderNodes(std::vector<RenderSet>& rnodes);
64 
65     void makeXFormList();
66     static void initContext(void* data);
67     static void freeContext(void* data);
68 
69     static void setLodScale(int pixelsX, float fovx,
70                             int pixelsY, float fovy);
71     static void setRadarLodScale(float lengthPerPixel);
72 
73 private:
74     const MeshObstacle* mesh;
75 
76     MeshDrawMgr* drawMgr;
77     const MeshDrawInfo* drawInfo;
78 
79     bool animRepos;
80 
81     // transform display list
82     GLfloat xformMatrix[16];
83 
84     struct MeshMaterial
85     {
86         const BzMaterial* bzmat;
87         OpenGLGState gstate;
88         GLfloat color[4];
89         const GLfloat* colorPtr;
90         bool drawRadar;
91         bool drawShadow;
92         bool needsSorting;
93         bool animRepos;
94     };
95 
96     struct SetNode
97     {
98         int set;
99         MeshMaterial meshMat;
100         // basic render nodes
101         RenderNode* node;
102         RenderNode* radarNode;
103     };
104 
105     struct LodNode
106     {
107         int count;
108         SetNode* sets;
109     };
110 
111     // Level Of Detail (LOD) information
112     int lodCount;
113     LodNode* lods;
114     float* lodLengths;
115 
116     // Radar LODs
117     int radarCount;
118     LodNode* radarLods;
119     float* radarLengths;
120 
121     static float LodScale;
122     static float RadarLodScale;
123 
124 private:
125     void updateMaterial(MeshMaterial* mat);
126     const BzMaterial* convertMaterial(const BzMaterial* bzmat);
127     int calcNormalLod(const ViewFrustum&);
128     int calcRadarLod();
129 
130     friend class MeshSceneNodeMgr;
131 };
132 
133 
134 #endif // BZF_MESH_SCENE_NODE_H
135 
136 // Local Variables: ***
137 // mode: C++ ***
138 // tab-width: 4 ***
139 // c-basic-offset: 4 ***
140 // indent-tabs-mode: nil ***
141 // End: ***
142 // ex: shiftwidth=4 tabstop=4
143