PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llbox.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 125 lines | 52 code | 12 blank | 61 comment | 0 complexity | fec38995bd5a96a787c3eb6abe7458c4 MD5 | raw file
  1/** 
  2 * @file llbox.cpp
  3 * @brief Draws a box using display lists for speed.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llbox.h"
 30
 31#include "llgl.h"
 32#include "llrender.h"
 33#include "llglheaders.h"
 34
 35LLBox		gBox;
 36
 37// These routines support multiple textures on a box
 38void LLBox::prerender()
 39{
 40	F32 size = 1.f;
 41
 42	mTriangleCount = 6 * 2;
 43
 44	mVertex[0][0] = mVertex[1][0] = mVertex[2][0] = mVertex[3][0] = -size / 2;
 45	mVertex[4][0] = mVertex[5][0] = mVertex[6][0] = mVertex[7][0] =  size / 2;
 46	mVertex[0][1] = mVertex[1][1] = mVertex[4][1] = mVertex[5][1] = -size / 2;
 47	mVertex[2][1] = mVertex[3][1] = mVertex[6][1] = mVertex[7][1] =  size / 2;
 48	mVertex[0][2] = mVertex[3][2] = mVertex[4][2] = mVertex[7][2] = -size / 2;
 49	mVertex[1][2] = mVertex[2][2] = mVertex[5][2] = mVertex[6][2] =  size / 2;
 50}
 51
 52// These routines support multiple textures on a box
 53void LLBox::cleanupGL()
 54{
 55	// No GL state, a noop.
 56}
 57
 58void LLBox::renderface(S32 which_face)
 59{
 60	/*static F32 normals[6][3] =
 61	{
 62		{-1.0f,  0.0f,  0.0f},
 63		{ 0.0f,  1.0f,  0.0f},
 64		{ 1.0f,  0.0f,  0.0f},
 65		{ 0.0f, -1.0f,  0.0f},
 66		{ 0.0f,  0.0f,  1.0f},
 67		{ 0.0f,  0.0f, -1.0f}
 68		};*/
 69	static S32 faces[6][4] =
 70	{
 71		{0, 1, 2, 3},
 72		{3, 2, 6, 7},
 73		{7, 6, 5, 4},
 74		{4, 5, 1, 0},
 75		{5, 6, 2, 1},
 76		{7, 4, 0, 3}
 77	};
 78
 79	gGL.begin(LLRender::QUADS);
 80		//gGL.normal3fv(&normals[which_face][0]);
 81		gGL.texCoord2f(1,0);
 82		gGL.vertex3fv(&mVertex[ faces[which_face][0] ][0]);
 83		gGL.texCoord2f(1,1);
 84		gGL.vertex3fv(&mVertex[ faces[which_face][1] ][0]);
 85		gGL.texCoord2f(0,1);
 86		gGL.vertex3fv(&mVertex[ faces[which_face][2] ][0]);
 87		gGL.texCoord2f(0,0);
 88		gGL.vertex3fv(&mVertex[ faces[which_face][3] ][0]);
 89	gGL.end();
 90}
 91
 92void LLBox::render()
 93{
 94    // This is a flattend representation of the box as render here
 95    //                                       .
 96    //              (-++)        (+++)      /|\t
 97    //                +------------+         | (texture coordinates)
 98    //                |2          1|         |
 99    //                |     4      |        (*) --->s
100    //                |    TOP     |
101    //                |            |
102    // (-++)     (--+)|3          0|(+-+)     (+++)        (-++)
103    //   +------------+------------+------------+------------+
104    //   |2          1|2          1|2          1|2          1|
105    //   |     0      |     1      |     2      |     3      |
106    //   |   BACK     |   RIGHT    |   FRONT    |   LEFT     |
107    //   |            |            |            |            |
108    //   |3          0|3          0|3          0|3          0|
109    //   +------------+------------+------------+------------+
110    // (-+-)     (---)|2          1|(+--)     (++-)        (-+-)
111    //                |     5      |
112    //                |   BOTTOM   |
113    //                |            |
114    //                |3          0|
115    //                +------------+
116    //              (-+-)        (++-)
117
118	renderface(5);
119	renderface(4);
120	renderface(3);
121	renderface(2);
122	renderface(1);
123	renderface(0);
124	gGL.flush();
125}