@@ -21,6 +21,9 @@ public class AbstractSkyDome : IDisposable
21
21
private int PrimCount ;
22
22
private float LastSkyPos ;
23
23
24
+ private VertexPositionTexture [ ] VertexData ;
25
+ private int [ ] IndexData ;
26
+
24
27
public AbstractSkyDome ( GraphicsDevice GD , float time )
25
28
{
26
29
float ? customSky = DynamicTuning . Global ? . GetTuning ( "city" , 0 , 2 ) ;
@@ -29,7 +32,8 @@ public AbstractSkyDome(GraphicsDevice GD, float time)
29
32
{
30
33
TryLoadSkyColor ( GD , DefaultSkyCol ) ;
31
34
}
32
-
35
+
36
+ InitArrays ( ) ;
33
37
BuildSkyDome ( GD , time ) ;
34
38
}
35
39
@@ -94,12 +98,23 @@ public bool Night(float tod)
94
98
return night ;
95
99
}
96
100
101
+ private void InitArrays ( )
102
+ {
103
+ var subdivs = 65 ;
104
+
105
+ int vertCount = ( subdivs - 1 ) * ( subdivs + 1 ) + 1 ;
106
+ int indexCount = ( ( subdivs - 1 ) * ( subdivs * 6 - 3 ) ) - 3 ;
107
+
108
+ VertexData = new VertexPositionTexture [ vertCount ] ;
109
+ IndexData = new int [ indexCount ] ;
110
+ }
111
+
97
112
public void BuildSkyDome ( GraphicsDevice GD , float time )
98
113
{
99
114
//generate sky dome geometry
100
115
var subdivs = 65 ;
101
- List < VertexPositionTexture > verts = new List < VertexPositionTexture > ( ) ;
102
- var indices = new List < int > ( ) ;
116
+ VertexPositionTexture [ ] verts = VertexData ;
117
+ int [ ] indices = IndexData ;
103
118
var skyCol = new Color ( 0x00 , 0x80 , 0xFF , 0xFF ) ;
104
119
105
120
float skyPos = OutsideSkyP ( time ) ;
@@ -112,11 +127,14 @@ public void BuildSkyDome(GraphicsDevice GD, float time)
112
127
var topRange = 0.9f * range ;
113
128
var btmRange = 0.1f * range ;
114
129
115
- verts . Add ( new VertexPositionTexture ( new Vector3 ( 0 , 1 , 0 ) , new Vector2 ( skyPos , yGap ) ) ) ;
130
+ int vi = 0 ;
131
+ int ii = 0 ;
132
+
133
+ verts [ vi ++ ] = new VertexPositionTexture ( new Vector3 ( 0 , 1 , 0 ) , new Vector2 ( skyPos , yGap ) ) ;
116
134
117
135
for ( int y = 1 ; y < subdivs ; y ++ )
118
136
{
119
- int start = verts . Count ;
137
+ int start = vi ;
120
138
var angley = ( float ) Math . PI * y / ( ( float ) subdivs - 1 ) ;
121
139
var radius = ( float ) Math . Sin ( angley ) ;
122
140
var height = Math . Cos ( angley ) ;
@@ -129,32 +147,32 @@ public void BuildSkyDome(GraphicsDevice GD, float time)
129
147
{
130
148
var anglex = ( float ) Math . PI * x * 2 / ( float ) subdivs ;
131
149
var colLerp = Math . Min ( 1 , Math . Abs ( ( ( y - 2 ) / ( float ) subdivs ) - 0.60f ) * 4 ) ;
132
- verts . Add ( new VertexPositionTexture ( new Vector3 ( ( float ) Math . Sin ( anglex ) * radius , ( float ) height , ( float ) Math . Cos ( anglex ) * radius ) , new Vector2 ( skyPos , tpos ) ) ) ;
150
+ verts [ vi ++ ] = new VertexPositionTexture ( new Vector3 ( ( float ) Math . Sin ( anglex ) * radius , ( float ) height , ( float ) Math . Cos ( anglex ) * radius ) , new Vector2 ( skyPos , tpos ) ) ;
133
151
if ( x < subdivs )
134
152
{
135
153
if ( y != 1 )
136
154
{
137
- indices . Add ( vertLastStart + x % vertLastLength ) ;
138
- indices . Add ( vertLastStart + ( x + 1 ) % vertLastLength ) ;
139
- indices . Add ( verts . Count - 1 ) ;
155
+ indices [ ii ++ ] = vertLastStart + x % vertLastLength ;
156
+ indices [ ii ++ ] = vertLastStart + ( x + 1 ) % vertLastLength ;
157
+ indices [ ii ++ ] = vi - 1 ;
140
158
}
141
159
142
- indices . Add ( vertLastStart + ( x + 1 ) % vertLastLength ) ;
143
- indices . Add ( verts . Count ) ;
144
- indices . Add ( verts . Count - 1 ) ;
160
+ indices [ ii ++ ] = vertLastStart + ( x + 1 ) % vertLastLength ;
161
+ indices [ ii ++ ] = vi ;
162
+ indices [ ii ++ ] = vi - 1 ;
145
163
}
146
164
}
147
165
vertLastStart = start ;
148
166
vertLastLength = subdivs + 1 ;
149
167
}
150
168
151
- if ( Verts == null ) Verts = new VertexBuffer ( GD , typeof ( VertexPositionTexture ) , verts . Count , BufferUsage . None ) ;
152
- Verts . SetData ( verts . ToArray ( ) ) ;
169
+ if ( Verts == null ) Verts = new VertexBuffer ( GD , typeof ( VertexPositionTexture ) , vi , BufferUsage . None ) ;
170
+ Verts . SetData ( verts ) ;
153
171
if ( Indices == null )
154
172
{
155
- Indices = new IndexBuffer ( GD , IndexElementSize . ThirtyTwoBits , indices . Count , BufferUsage . None ) ;
156
- Indices . SetData ( indices . ToArray ( ) ) ;
157
- PrimCount = indices . Count / 3 ;
173
+ Indices = new IndexBuffer ( GD , IndexElementSize . ThirtyTwoBits , ii , BufferUsage . None ) ;
174
+ Indices . SetData ( indices ) ;
175
+ PrimCount = ii / 3 ;
158
176
}
159
177
}
160
178
0 commit comments