diff options
Diffstat (limited to 'indra/newview/llcylinder.cpp')
-rw-r--r-- | indra/newview/llcylinder.cpp | 260 |
1 files changed, 19 insertions, 241 deletions
diff --git a/indra/newview/llcylinder.cpp b/indra/newview/llcylinder.cpp index 4901e29691..2adc071d7a 100644 --- a/indra/newview/llcylinder.cpp +++ b/indra/newview/llcylinder.cpp @@ -37,261 +37,39 @@ #include "llgl.h" #include "llglheaders.h" -LLCylinder gCylinder; LLCone gCone; -GLUquadricObj* gQuadObj = NULL; - -static const GLint SLICES[] = { 30, 20, 12, 6 }; // same as sphere slices -static const GLint STACKS = 2; -static const GLfloat RADIUS = 0.5f; - -// draws a cylinder or cone -// returns approximate number of triangles required -U32 draw_cylinder_side(GLint slices, GLint stacks, GLfloat base_radius, GLfloat top_radius) -{ - U32 triangles = 0; - GLfloat height = 1.0f; - - if (!gQuadObj) - { - gQuadObj = gluNewQuadric(); - if (!gQuadObj) llerror("draw_cylindrical_body couldn't allocated quadric", 0); - } - - gluQuadricDrawStyle(gQuadObj, GLU_FILL); - gluQuadricNormals(gQuadObj, GLU_SMOOTH); - gluQuadricOrientation(gQuadObj, GLU_OUTSIDE); - gluQuadricTexture(gQuadObj, GL_TRUE); - gluCylinder(gQuadObj, base_radius, top_radius, height, slices, stacks); - triangles += stacks * (slices * 2); - - - return triangles; -} - - -// Returns number of triangles required to draw -// Need to know if top or not to set lighting normals -const BOOL TOP = TRUE; -const BOOL BOTTOM = FALSE; -U32 draw_cylinder_cap(GLint slices, GLfloat base_radius, BOOL is_top) -{ - U32 triangles = 0; - - if (!gQuadObj) - { - gQuadObj = gluNewQuadric(); - if (!gQuadObj) llerror("draw_cylinder_base couldn't allocated quadric", 0); - } - - gluQuadricDrawStyle(gQuadObj, GLU_FILL); - gluQuadricNormals(gQuadObj, GLU_SMOOTH); - gluQuadricOrientation(gQuadObj, GLU_OUTSIDE); - gluQuadricTexture(gQuadObj, GL_TRUE); - - // no hole in the middle of the disk, and just one ring - GLdouble inner_radius = 0.0; - GLint rings = 1; - - // normals point in +z for top, -z for base - if (is_top) - { - gluQuadricOrientation(gQuadObj, GLU_OUTSIDE); - } - else - { - gluQuadricOrientation(gQuadObj, GLU_INSIDE); - } - gluDisk(gQuadObj, inner_radius, base_radius, slices, rings); - triangles += slices; - - return triangles; -} - -void LLCylinder::drawSide(S32 detail) -{ - draw_cylinder_side(SLICES[detail], STACKS, RADIUS, RADIUS); -} - -void LLCylinder::drawTop(S32 detail) -{ - draw_cylinder_cap(SLICES[detail], RADIUS, TOP); -} - -void LLCylinder::drawBottom(S32 detail) -{ - draw_cylinder_cap(SLICES[detail], RADIUS, BOTTOM); -} - -void LLCylinder::prerender() -{ -} - -void LLCylinder::cleanupGL() -{ - if (gQuadObj) - { - gluDeleteQuadric(gQuadObj); - gQuadObj = NULL; - } -} - -void LLCylinder::render(F32 pixel_area) -{ - renderface(pixel_area, 0); - renderface(pixel_area, 1); - renderface(pixel_area, 2); -} - - -void LLCylinder::renderface(F32 pixel_area, S32 face) -{ - if (face < 0 || face > 2) - { - llerror("LLCylinder::renderface() invalid face number", face); - return; - } - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - S32 level_of_detail; - - if (pixel_area > 20000.f) - { - level_of_detail = 0; - } - else if (pixel_area > 1600.f) - { - level_of_detail = 1; - } - else if (pixel_area > 200.f) - { - level_of_detail = 2; - } - else - { - level_of_detail = 3; - } - - if (level_of_detail < 0 || CYLINDER_LEVELS_OF_DETAIL <= level_of_detail) - { - llerror("LLCylinder::renderface() invalid level of detail", level_of_detail); - return; - } - - LLVertexBuffer::unbind(); - - switch(face) - { - case 0: - glTranslatef(0.f, 0.f, -0.5f); - drawSide(level_of_detail); - break; - case 1: - glTranslatef(0.0f, 0.f, 0.5f); - drawTop(level_of_detail); - break; - case 2: - glTranslatef(0.0f, 0.f, -0.5f); - drawBottom(level_of_detail); - break; - default: - llerror("LLCylinder::renderface() fell out of switch", 0); - break; - } - - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); -} - - // // Cones // -void LLCone::prerender() +void LLCone::render(S32 sides) { -} + gGL.begin(LLRender::TRIANGLE_FAN); + gGL.vertex3f(0,0,0); -void LLCone::cleanupGL() -{ - if (gQuadObj) + for (U32 i = 0; i < sides; i++) { - gluDeleteQuadric(gQuadObj); - gQuadObj = NULL; + F32 a = (F32) i/sides * F_PI*2.f; + F32 x = cosf(a)*0.5f; + F32 y = sinf(a)*0.5f; + gGL.vertex3f(x,y,0.f); } -} + gGL.vertex3f(cosf(0.f)*0.5f, sinf(0.f)*0.5f, 0.f); -void LLCone::drawSide(S32 detail) -{ - draw_cylinder_side( SLICES[detail], STACKS, RADIUS, 0.f ); -} - -void LLCone::drawBottom(S32 detail) -{ - draw_cylinder_cap( SLICES[detail], RADIUS, BOTTOM ); -} - -void LLCone::render(S32 level_of_detail) -{ - GLfloat height = 1.0f; + gGL.end(); - if (level_of_detail < 0 || CONE_LEVELS_OF_DETAIL <= level_of_detail) + gGL.begin(LLRender::TRIANGLE_FAN); + gGL.vertex3f(0.f, 0.f, 1.f); + for (U32 i = 0; i < sides; i++) { - llerror("LLCone::render() invalid level of detail", level_of_detail); - return; + F32 a = (F32) i/sides * F_PI*2.f; + F32 x = cosf(a)*0.5f; + F32 y = sinf(a)*0.5f; + gGL.vertex3f(x,y,0.f); } + gGL.vertex3f(cosf(0.f)*0.5f, sinf(0.f)*0.5f, 0.f); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - // center object at 0 - glTranslatef(0.f, 0.f, - height / 2.0f); - - drawSide(level_of_detail); - drawBottom(level_of_detail); - - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); + gGL.end(); } - -void LLCone::renderface(S32 level_of_detail, S32 face) -{ - if (face < 0 || face > 1) - { - llerror("LLCone::renderface() invalid face number", face); - return; - } - - if (level_of_detail < 0 || CONE_LEVELS_OF_DETAIL <= level_of_detail) - { - llerror("LLCone::renderface() invalid level of detail", level_of_detail); - return; - } - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - LLVertexBuffer::unbind(); - - switch(face) - { - case 0: - glTranslatef(0.f, 0.f, -0.5f); - drawSide(level_of_detail); - break; - case 1: - glTranslatef(0.f, 0.f, -0.5f); - drawBottom(level_of_detail); - break; - default: - llerror("LLCylinder::renderface() fell out of switch", 0); - break; - } - - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); -} |