diff options
Diffstat (limited to 'linden/indra/newview/llcylinder.cpp')
-rw-r--r-- | linden/indra/newview/llcylinder.cpp | 108 |
1 files changed, 40 insertions, 68 deletions
diff --git a/linden/indra/newview/llcylinder.cpp b/linden/indra/newview/llcylinder.cpp index b3eaa44..9f76648 100644 --- a/linden/indra/newview/llcylinder.cpp +++ b/linden/indra/newview/llcylinder.cpp | |||
@@ -34,7 +34,7 @@ | |||
34 | #include "llmath.h" | 34 | #include "llmath.h" |
35 | #include "noise.h" | 35 | #include "noise.h" |
36 | #include "v3math.h" | 36 | #include "v3math.h" |
37 | 37 | #include "llvertexbuffer.h" | |
38 | #include "llgl.h" | 38 | #include "llgl.h" |
39 | #include "llglheaders.h" | 39 | #include "llglheaders.h" |
40 | 40 | ||
@@ -43,6 +43,10 @@ LLCone gCone; | |||
43 | 43 | ||
44 | GLUquadricObj* gQuadObj = NULL; | 44 | GLUquadricObj* gQuadObj = NULL; |
45 | 45 | ||
46 | static const GLint SLICES[] = { 30, 20, 12, 6 }; // same as sphere slices | ||
47 | static const GLint STACKS = 2; | ||
48 | static const GLfloat RADIUS = 0.5f; | ||
49 | |||
46 | // draws a cylinder or cone | 50 | // draws a cylinder or cone |
47 | // returns approximate number of triangles required | 51 | // returns approximate number of triangles required |
48 | U32 draw_cylinder_side(GLint slices, GLint stacks, GLfloat base_radius, GLfloat top_radius) | 52 | U32 draw_cylinder_side(GLint slices, GLint stacks, GLfloat base_radius, GLfloat top_radius) |
@@ -106,46 +110,27 @@ U32 draw_cylinder_cap(GLint slices, GLfloat base_radius, BOOL is_top) | |||
106 | return triangles; | 110 | return triangles; |
107 | } | 111 | } |
108 | 112 | ||
113 | void LLCylinder::drawSide(S32 detail) | ||
114 | { | ||
115 | draw_cylinder_side(SLICES[detail], STACKS, RADIUS, RADIUS); | ||
116 | } | ||
109 | 117 | ||
110 | void LLCylinder::prerender() | 118 | void LLCylinder::drawTop(S32 detail) |
111 | { | 119 | { |
112 | GLint stacks = 2; | 120 | draw_cylinder_cap(SLICES[detail], RADIUS, TOP); |
113 | GLfloat radius = 0.5f; | 121 | } |
114 | GLint slices[CYLINDER_LEVELS_OF_DETAIL] = { 30, 20, 12, 6 }; // same as sphere slices | ||
115 | 122 | ||
116 | for (S32 detail = 0; detail < CYLINDER_LEVELS_OF_DETAIL; detail++) | 123 | void LLCylinder::drawBottom(S32 detail) |
117 | { | 124 | { |
118 | mTriangleCount[detail] = 0; | 125 | draw_cylinder_cap(SLICES[detail], RADIUS, BOTTOM); |
119 | |||
120 | mDisplayListSide[detail] = glGenLists(1); | ||
121 | glNewList(mDisplayListSide[detail], GL_COMPILE); | ||
122 | mTriangleCount[detail] += draw_cylinder_side( slices[detail], stacks, radius, radius ); | ||
123 | glEndList(); | ||
124 | |||
125 | mDisplayListTop[detail] = glGenLists(1); | ||
126 | glNewList( mDisplayListTop[detail], GL_COMPILE); | ||
127 | mTriangleCount[detail] += draw_cylinder_cap( slices[detail], radius, TOP ); | ||
128 | glEndList(); | ||
129 | |||
130 | mDisplayListBottom[detail] = glGenLists(1); | ||
131 | glNewList( mDisplayListBottom[detail], GL_COMPILE); | ||
132 | mTriangleCount[detail] += draw_cylinder_cap( slices[detail], radius, BOTTOM ); | ||
133 | glEndList(); | ||
134 | } | ||
135 | } | 126 | } |
136 | 127 | ||
137 | void LLCylinder::cleanupGL() | 128 | void LLCylinder::prerender() |
138 | { | 129 | { |
139 | for (S32 detail = 0; detail < CYLINDER_LEVELS_OF_DETAIL; detail++) | 130 | } |
140 | { | ||
141 | glDeleteLists(mDisplayListSide[detail], 1); | ||
142 | mDisplayListSide[detail] = 0; | ||
143 | glDeleteLists(mDisplayListTop[detail], 1); | ||
144 | mDisplayListTop[detail] = 0; | ||
145 | glDeleteLists(mDisplayListBottom[detail], 1); | ||
146 | mDisplayListBottom[detail] = 0; | ||
147 | } | ||
148 | 131 | ||
132 | void LLCylinder::cleanupGL() | ||
133 | { | ||
149 | if (gQuadObj) | 134 | if (gQuadObj) |
150 | { | 135 | { |
151 | gluDeleteQuadric(gQuadObj); | 136 | gluDeleteQuadric(gQuadObj); |
@@ -197,19 +182,21 @@ void LLCylinder::renderface(F32 pixel_area, S32 face) | |||
197 | return; | 182 | return; |
198 | } | 183 | } |
199 | 184 | ||
185 | LLVertexBuffer::unbind(); | ||
186 | |||
200 | switch(face) | 187 | switch(face) |
201 | { | 188 | { |
202 | case 0: | 189 | case 0: |
203 | glTranslatef(0.f, 0.f, -0.5f); | 190 | glTranslatef(0.f, 0.f, -0.5f); |
204 | glCallList(mDisplayListSide[level_of_detail]); | 191 | drawSide(level_of_detail); |
205 | break; | 192 | break; |
206 | case 1: | 193 | case 1: |
207 | glTranslatef(0.0f, 0.f, 0.5f); | 194 | glTranslatef(0.0f, 0.f, 0.5f); |
208 | glCallList(mDisplayListTop[level_of_detail]); | 195 | drawTop(level_of_detail); |
209 | break; | 196 | break; |
210 | case 2: | 197 | case 2: |
211 | glTranslatef(0.0f, 0.f, -0.5f); | 198 | glTranslatef(0.0f, 0.f, -0.5f); |
212 | glCallList(mDisplayListBottom[level_of_detail]); | 199 | drawBottom(level_of_detail); |
213 | break; | 200 | break; |
214 | default: | 201 | default: |
215 | llerror("LLCylinder::renderface() fell out of switch", 0); | 202 | llerror("LLCylinder::renderface() fell out of switch", 0); |
@@ -227,37 +214,10 @@ void LLCylinder::renderface(F32 pixel_area, S32 face) | |||
227 | 214 | ||
228 | void LLCone::prerender() | 215 | void LLCone::prerender() |
229 | { | 216 | { |
230 | GLint stacks = 2; | ||
231 | GLfloat radius = 0.5f; | ||
232 | GLint slices[CONE_LEVELS_OF_DETAIL] = { 32, 18, 12, 6 }; | ||
233 | |||
234 | for (S32 detail = 0; detail < CONE_LEVELS_OF_DETAIL; detail++) | ||
235 | { | ||
236 | mTriangleCount[detail] = 0; | ||
237 | |||
238 | mDisplayListSide[detail] = glGenLists(1); | ||
239 | glNewList(mDisplayListSide[detail], GL_COMPILE); | ||
240 | mTriangleCount[detail] += draw_cylinder_side( slices[detail], stacks, radius, 0.f ); | ||
241 | glEndList(); | ||
242 | |||
243 | mDisplayListBottom[detail] = glGenLists(1); | ||
244 | glNewList( mDisplayListBottom[detail], GL_COMPILE); | ||
245 | mTriangleCount[detail] += draw_cylinder_cap( slices[detail], radius, BOTTOM ); | ||
246 | glEndList(); | ||
247 | } | ||
248 | } | 217 | } |
249 | 218 | ||
250 | void LLCone::cleanupGL() | 219 | void LLCone::cleanupGL() |
251 | { | 220 | { |
252 | for (S32 detail = 0; detail < CYLINDER_LEVELS_OF_DETAIL; detail++) | ||
253 | { | ||
254 | glDeleteLists(mDisplayListSide[detail], 1); | ||
255 | mDisplayListSide[detail] = 0; | ||
256 | |||
257 | glDeleteLists(mDisplayListBottom[detail], 1); | ||
258 | mDisplayListBottom[detail] = 0; | ||
259 | } | ||
260 | |||
261 | if (gQuadObj) | 221 | if (gQuadObj) |
262 | { | 222 | { |
263 | gluDeleteQuadric(gQuadObj); | 223 | gluDeleteQuadric(gQuadObj); |
@@ -265,6 +225,15 @@ void LLCone::cleanupGL() | |||
265 | } | 225 | } |
266 | } | 226 | } |
267 | 227 | ||
228 | void LLCone::drawSide(S32 detail) | ||
229 | { | ||
230 | draw_cylinder_side( SLICES[detail], STACKS, RADIUS, 0.f ); | ||
231 | } | ||
232 | |||
233 | void LLCone::drawBottom(S32 detail) | ||
234 | { | ||
235 | draw_cylinder_cap( SLICES[detail], RADIUS, BOTTOM ); | ||
236 | } | ||
268 | 237 | ||
269 | void LLCone::render(S32 level_of_detail) | 238 | void LLCone::render(S32 level_of_detail) |
270 | { | 239 | { |
@@ -282,8 +251,9 @@ void LLCone::render(S32 level_of_detail) | |||
282 | // center object at 0 | 251 | // center object at 0 |
283 | glTranslatef(0.f, 0.f, - height / 2.0f); | 252 | glTranslatef(0.f, 0.f, - height / 2.0f); |
284 | 253 | ||
285 | glCallList(mDisplayListSide[level_of_detail]); | 254 | LLVertexBuffer::unbind(); |
286 | glCallList(mDisplayListBottom[level_of_detail]); | 255 | drawSide(level_of_detail); |
256 | drawBottom(level_of_detail); | ||
287 | 257 | ||
288 | glMatrixMode(GL_MODELVIEW); | 258 | glMatrixMode(GL_MODELVIEW); |
289 | glPopMatrix(); | 259 | glPopMatrix(); |
@@ -307,15 +277,17 @@ void LLCone::renderface(S32 level_of_detail, S32 face) | |||
307 | glMatrixMode(GL_MODELVIEW); | 277 | glMatrixMode(GL_MODELVIEW); |
308 | glPushMatrix(); | 278 | glPushMatrix(); |
309 | 279 | ||
280 | LLVertexBuffer::unbind(); | ||
281 | |||
310 | switch(face) | 282 | switch(face) |
311 | { | 283 | { |
312 | case 0: | 284 | case 0: |
313 | glTranslatef(0.f, 0.f, -0.5f); | 285 | glTranslatef(0.f, 0.f, -0.5f); |
314 | glCallList(mDisplayListSide[level_of_detail]); | 286 | drawSide(level_of_detail); |
315 | break; | 287 | break; |
316 | case 1: | 288 | case 1: |
317 | glTranslatef(0.f, 0.f, -0.5f); | 289 | glTranslatef(0.f, 0.f, -0.5f); |
318 | glCallList(mDisplayListBottom[level_of_detail]); | 290 | drawBottom(level_of_detail); |
319 | break; | 291 | break; |
320 | default: | 292 | default: |
321 | llerror("LLCylinder::renderface() fell out of switch", 0); | 293 | llerror("LLCylinder::renderface() fell out of switch", 0); |