aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llrender
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:49 -0500
committerJacek Antonelli2008-08-15 23:45:49 -0500
commit8538c0f35dc5fb780f02930256e627e5266ede4a (patch)
tree58950646aae6534fafe680a5cf879d01cd99d254 /linden/indra/llrender
parentSecond Life viewer sources 1.20.5 (diff)
downloadmeta-impy-8538c0f35dc5fb780f02930256e627e5266ede4a.zip
meta-impy-8538c0f35dc5fb780f02930256e627e5266ede4a.tar.gz
meta-impy-8538c0f35dc5fb780f02930256e627e5266ede4a.tar.bz2
meta-impy-8538c0f35dc5fb780f02930256e627e5266ede4a.tar.xz
Second Life viewer sources 1.20.6
Diffstat (limited to 'linden/indra/llrender')
-rw-r--r--linden/indra/llrender/llfontgl.cpp4
-rw-r--r--linden/indra/llrender/llglimmediate.cpp117
-rw-r--r--linden/indra/llrender/llglimmediate.h11
-rw-r--r--linden/indra/llrender/llvertexbuffer.cpp65
-rw-r--r--linden/indra/llrender/llvertexbuffer.h8
5 files changed, 83 insertions, 122 deletions
diff --git a/linden/indra/llrender/llfontgl.cpp b/linden/indra/llrender/llfontgl.cpp
index 53e8c2b..938dd73 100644
--- a/linden/indra/llrender/llfontgl.cpp
+++ b/linden/indra/llrender/llfontgl.cpp
@@ -845,7 +845,7 @@ S32 LLFontGL::render(const LLWString &wstr,
845 if (style & UNDERLINE) 845 if (style & UNDERLINE)
846 { 846 {
847 LLGLSNoTexture no_texture; 847 LLGLSNoTexture no_texture;
848 gGL.begin(GL_LINES); 848 gGL.begin(LLVertexBuffer::LINES);
849 gGL.vertex2f(start_x, cur_y - (mDescender)); 849 gGL.vertex2f(start_x, cur_y - (mDescender));
850 gGL.vertex2f(cur_x, cur_y - (mDescender)); 850 gGL.vertex2f(cur_x, cur_y - (mDescender));
851 gGL.end(); 851 gGL.end();
@@ -1340,7 +1340,7 @@ void LLFontGL::drawGlyph(const LLRectf& screen_rect, const LLRectf& uv_rect, con
1340 F32 slant_offset; 1340 F32 slant_offset;
1341 slant_offset = ((style & ITALIC) ? ( -mAscender * 0.2f) : 0.f); 1341 slant_offset = ((style & ITALIC) ? ( -mAscender * 0.2f) : 0.f);
1342 1342
1343 gGL.begin(GL_QUADS); 1343 gGL.begin(LLVertexBuffer::QUADS);
1344 { 1344 {
1345 //FIXME: bold and drop shadow are mutually exclusive only for convenience 1345 //FIXME: bold and drop shadow are mutually exclusive only for convenience
1346 //Allow both when we need them. 1346 //Allow both when we need them.
diff --git a/linden/indra/llrender/llglimmediate.cpp b/linden/indra/llrender/llglimmediate.cpp
index da9239d..edc694a 100644
--- a/linden/indra/llrender/llglimmediate.cpp
+++ b/linden/indra/llrender/llglimmediate.cpp
@@ -36,64 +36,19 @@
36 36
37LLGLImmediate gGL; 37LLGLImmediate gGL;
38 38
39#ifdef LL_RELEASE_FOR_DOWNLOAD
40#define IMM_ERRS llwarns
41#else
42#define IMM_ERRS llerrs
43#endif
44
45bool LLGLImmediate::sClever = false; 39bool LLGLImmediate::sClever = false;
46BOOL LLGLImmediate::sStarted = FALSE; 40
41const U32 immediate_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_TEXCOORD;
47 42
48LLGLImmediate::LLGLImmediate() 43LLGLImmediate::LLGLImmediate()
49{ 44{
50 mCount = 0; 45 mCount = 0;
51 mMode = GL_TRIANGLES; 46 mMode = LLVertexBuffer::TRIANGLES;
52 memset(mBuffer, 0, sizeof(Vertex)*4096); 47 mBuffer = new LLVertexBuffer(immediate_mask, 0);
53} 48 mBuffer->allocateBuffer(4096, 0, TRUE);
54 49 mBuffer->getVertexStrider(mVerticesp);
55void LLGLImmediate::start() 50 mBuffer->getTexCoordStrider(mTexcoordsp);
56{ 51 mBuffer->getColorStrider(mColorsp);
57 if(sClever)
58 {
59 if (sStarted)
60 {
61 llerrs << "Redundant start." << llendl;
62 }
63
64 LLVertexBuffer::unbind();
65 sStarted = TRUE;
66
67 glEnableClientState(GL_VERTEX_ARRAY);
68 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
69 glEnableClientState(GL_COLOR_ARRAY);
70
71 const U32 stride = sizeof(Vertex);
72
73 glVertexPointer(3, GL_FLOAT, stride, &(mBuffer[0].v));
74 glTexCoordPointer(2, GL_FLOAT, stride, &(mBuffer[0].uv));
75 glColorPointer(4, GL_UNSIGNED_BYTE, stride, &(mBuffer[0].c));
76
77 color4f(1,1,1,1);
78 }
79}
80
81void LLGLImmediate::stop()
82{
83 if (sClever)
84 {
85 if (!sStarted)
86 {
87 llerrs << "Redundant stop." << llendl;
88 }
89
90 flush();
91
92 sStarted = FALSE;
93
94 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
95 glDisableClientState(GL_COLOR_ARRAY);
96 }
97} 52}
98 53
99void LLGLImmediate::translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z) 54void LLGLImmediate::translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z)
@@ -116,10 +71,7 @@ void LLGLImmediate::popMatrix()
116 71
117void LLGLImmediate::blendFunc(GLenum sfactor, GLenum dfactor) 72void LLGLImmediate::blendFunc(GLenum sfactor, GLenum dfactor)
118{ 73{
119 if (sStarted) 74 flush();
120 {
121 flush();
122 }
123 glBlendFunc(sfactor, dfactor); 75 glBlendFunc(sfactor, dfactor);
124} 76}
125 77
@@ -129,10 +81,10 @@ void LLGLImmediate::begin(const GLuint& mode)
129 { 81 {
130 if (mode != mMode) 82 if (mode != mMode)
131 { 83 {
132 if (mMode == GL_QUADS || 84 if (mMode == LLVertexBuffer::QUADS ||
133 mMode == GL_LINES || 85 mMode == LLVertexBuffer::LINES ||
134 mMode == GL_TRIANGLES || 86 mMode == LLVertexBuffer::TRIANGLES ||
135 mMode == GL_POINTS) 87 mMode == LLVertexBuffer::POINTS)
136 { 88 {
137 flush(); 89 flush();
138 } 90 }
@@ -146,7 +98,7 @@ void LLGLImmediate::begin(const GLuint& mode)
146 } 98 }
147 else 99 else
148 { 100 {
149 glBegin(mode); 101 glBegin(LLVertexBuffer::sGLMode[mode]);
150 } 102 }
151} 103}
152 104
@@ -156,13 +108,14 @@ void LLGLImmediate::end()
156 { 108 {
157 if (mCount == 0) 109 if (mCount == 0)
158 { 110 {
159 IMM_ERRS << "GL begin and end called with no vertices specified." << llendl; 111 return;
112 //IMM_ERRS << "GL begin and end called with no vertices specified." << llendl;
160 } 113 }
161 114
162 if ((mMode != GL_QUADS && 115 if ((mMode != LLVertexBuffer::QUADS &&
163 mMode != GL_LINES && 116 mMode != LLVertexBuffer::LINES &&
164 mMode != GL_TRIANGLES && 117 mMode != LLVertexBuffer::TRIANGLES &&
165 mMode != GL_POINTS) || 118 mMode != LLVertexBuffer::POINTS) ||
166 mCount > 2048) 119 mCount > 2048)
167 { 120 {
168 flush(); 121 flush();
@@ -221,12 +174,13 @@ void LLGLImmediate::flush()
221 llerrs << "foo 6" << llendl; 174 llerrs << "foo 6" << llendl;
222 } 175 }
223#endif 176#endif
224 if (!sStarted) 177
225 { 178 mBuffer->setBuffer(immediate_mask);
226 llerrs << "Drawing call issued outside start/stop." << llendl; 179 mBuffer->drawArrays(mMode, 0, mCount);
227 } 180
228 glDrawArrays(mMode, 0, mCount); 181 mVerticesp[0] = mVerticesp[mCount];
229 mBuffer[0] = mBuffer[mCount]; 182 mTexcoordsp[0] = mTexcoordsp[mCount];
183 mColorsp[0] = mColorsp[mCount];
230 mCount = 0; 184 mCount = 0;
231 } 185 }
232 } 186 }
@@ -242,13 +196,13 @@ void LLGLImmediate::vertex3f(const GLfloat& x, const GLfloat& y, const GLfloat&
242 return; 196 return;
243 } 197 }
244 198
245 mBuffer[mCount].v[0] = x; 199 mVerticesp[mCount] = LLVector3(x,y,z);
246 mBuffer[mCount].v[1] = y;
247 mBuffer[mCount].v[2] = z;
248 mCount++; 200 mCount++;
249 if (mCount < 4096) 201 if (mCount < 4096)
250 { 202 {
251 mBuffer[mCount] = mBuffer[mCount-1]; 203 mVerticesp[mCount] = mVerticesp[mCount-1];
204 mColorsp[mCount] = mColorsp[mCount-1];
205 mTexcoordsp[mCount] = mTexcoordsp[mCount-1];
252 } 206 }
253 } 207 }
254 else 208 else
@@ -281,8 +235,7 @@ void LLGLImmediate::texCoord2f(const GLfloat& x, const GLfloat& y)
281{ 235{
282 if (sClever) 236 if (sClever)
283 { 237 {
284 mBuffer[mCount].uv[0] = x; 238 mTexcoordsp[mCount] = LLVector2(x,y);
285 mBuffer[mCount].uv[1] = y;
286 } 239 }
287 else 240 else
288 { 241 {
@@ -304,10 +257,7 @@ void LLGLImmediate::color4ub(const GLubyte& r, const GLubyte& g, const GLubyte&
304{ 257{
305 if (sClever) 258 if (sClever)
306 { 259 {
307 mBuffer[mCount].c[0] = r; 260 mColorsp[mCount] = LLColor4U(r,g,b,a);
308 mBuffer[mCount].c[1] = g;
309 mBuffer[mCount].c[2] = b;
310 mBuffer[mCount].c[3] = a;
311 } 261 }
312 else 262 else
313 { 263 {
@@ -345,7 +295,6 @@ void LLGLImmediate::color3fv(const GLfloat* c)
345 295
346void LLGLImmediate::setClever(bool do_clever) 296void LLGLImmediate::setClever(bool do_clever)
347{ 297{
348 llassert(!sStarted);
349 llassert(mCount == 0); 298 llassert(mCount == 0);
350 299
351 sClever = do_clever; 300 sClever = do_clever;
diff --git a/linden/indra/llrender/llglimmediate.h b/linden/indra/llrender/llglimmediate.h
index cf4dc4f..e0cddff 100644
--- a/linden/indra/llrender/llglimmediate.h
+++ b/linden/indra/llrender/llglimmediate.h
@@ -40,6 +40,7 @@
40#include "stdtypes.h" 40#include "stdtypes.h"
41#include "llgltypes.h" 41#include "llgltypes.h"
42#include "llglheaders.h" 42#include "llglheaders.h"
43#include "llvertexbuffer.h"
43 44
44class LLGLImmediate 45class LLGLImmediate
45{ 46{
@@ -50,8 +51,6 @@ public:
50 void pushMatrix(); 51 void pushMatrix();
51 void popMatrix(); 52 void popMatrix();
52 void blendFunc(GLenum sfactor, GLenum dfactor); 53 void blendFunc(GLenum sfactor, GLenum dfactor);
53 void start();
54 void stop();
55 void flush(); 54 void flush();
56 55
57 void begin(const GLuint& mode); 56 void begin(const GLuint& mode);
@@ -91,15 +90,15 @@ public:
91 GLfloat uv[2]; 90 GLfloat uv[2];
92 }; 91 };
93 92
94public:
95 static BOOL sStarted;
96
97private: 93private:
98 static bool sClever; 94 static bool sClever;
99 95
100 U32 mCount; 96 U32 mCount;
101 U32 mMode; 97 U32 mMode;
102 Vertex mBuffer[4096]; 98 LLPointer<LLVertexBuffer> mBuffer;
99 LLStrider<LLVector3> mVerticesp;
100 LLStrider<LLVector2> mTexcoordsp;
101 LLStrider<LLColor4U> mColorsp;
103}; 102};
104 103
105extern LLGLImmediate gGL; 104extern LLGLImmediate gGL;
diff --git a/linden/indra/llrender/llvertexbuffer.cpp b/linden/indra/llrender/llvertexbuffer.cpp
index ce80343..4c663e2 100644
--- a/linden/indra/llrender/llvertexbuffer.cpp
+++ b/linden/indra/llrender/llvertexbuffer.cpp
@@ -60,7 +60,6 @@ U32 LLVertexBuffer::sLastMask = 0;
60BOOL LLVertexBuffer::sVBOActive = FALSE; 60BOOL LLVertexBuffer::sVBOActive = FALSE;
61BOOL LLVertexBuffer::sIBOActive = FALSE; 61BOOL LLVertexBuffer::sIBOActive = FALSE;
62U32 LLVertexBuffer::sAllocatedBytes = 0; 62U32 LLVertexBuffer::sAllocatedBytes = 0;
63BOOL LLVertexBuffer::sRenderActive = FALSE;
64BOOL LLVertexBuffer::sMapped = FALSE; 63BOOL LLVertexBuffer::sMapped = FALSE;
65 64
66std::vector<U32> LLVertexBuffer::sDeleteList; 65std::vector<U32> LLVertexBuffer::sDeleteList;
@@ -84,16 +83,18 @@ U32 LLVertexBuffer::sGLMode[LLVertexBuffer::NUM_MODES] =
84 GL_TRIANGLE_FAN, 83 GL_TRIANGLE_FAN,
85 GL_POINTS, 84 GL_POINTS,
86 GL_LINES, 85 GL_LINES,
87 GL_LINE_STRIP 86 GL_LINE_STRIP,
87 GL_QUADS,
88 GL_LINE_LOOP,
88}; 89};
89 90
90//static 91//static
91void LLVertexBuffer::setupClientArrays(U32 data_mask) 92void LLVertexBuffer::setupClientArrays(U32 data_mask)
92{ 93{
93 if (LLGLImmediate::sStarted) 94 /*if (LLGLImmediate::sStarted)
94 { 95 {
95 llerrs << "Cannot use LLGLImmediate and LLVertexBuffer simultaneously!" << llendl; 96 llerrs << "Cannot use LLGLImmediate and LLVertexBuffer simultaneously!" << llendl;
96 } 97 }*/
97 98
98 if (sLastMask != data_mask) 99 if (sLastMask != data_mask)
99 { 100 {
@@ -186,6 +187,11 @@ void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indi
186 llerrs << "Wrong vertex buffer bound." << llendl; 187 llerrs << "Wrong vertex buffer bound." << llendl;
187 } 188 }
188 189
190 if (mode > NUM_MODES)
191 {
192 llerrs << "Invalid draw mode: " << mode << llendl;
193 }
194
189 glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT, 195 glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT,
190 ((U16*) getIndicesPointer()) + indices_offset); 196 ((U16*) getIndicesPointer()) + indices_offset);
191} 197}
@@ -208,10 +214,37 @@ void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const
208 llerrs << "Wrong vertex buffer bound." << llendl; 214 llerrs << "Wrong vertex buffer bound." << llendl;
209 } 215 }
210 216
217 if (mode > NUM_MODES)
218 {
219 llerrs << "Invalid draw mode: " << mode << llendl;
220 }
221
211 glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT, 222 glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT,
212 ((U16*) getIndicesPointer()) + indices_offset); 223 ((U16*) getIndicesPointer()) + indices_offset);
213} 224}
214 225
226void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const
227{
228
229 if (first >= (U32) mRequestedNumVerts ||
230 first + count > (U32) mRequestedNumVerts)
231 {
232 llerrs << "Bad vertex buffer draw range: [" << first << ", " << first+count << "]" << llendl;
233 }
234
235 if (mGLBuffer != sGLRenderBuffer)
236 {
237 llerrs << "Wrong vertex buffer bound." << llendl;
238 }
239
240 if (mode > NUM_MODES)
241 {
242 llerrs << "Invalid draw mode: " << mode << llendl;
243 }
244
245 glDrawArrays(sGLMode[mode], first, count);
246}
247
215//static 248//static
216void LLVertexBuffer::initClass(bool use_vbo) 249void LLVertexBuffer::initClass(bool use_vbo)
217{ 250{
@@ -246,24 +279,8 @@ void LLVertexBuffer::unbind()
246void LLVertexBuffer::cleanupClass() 279void LLVertexBuffer::cleanupClass()
247{ 280{
248 LLMemType mt(LLMemType::MTYPE_VERTEX_DATA); 281 LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
249 startRender();
250 stopRender();
251 clientCopy(); // deletes GL buffers
252}
253
254//static, call before rendering VBOs
255void LLVertexBuffer::startRender()
256{
257 LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
258
259 unbind();
260 sRenderActive = TRUE;
261}
262
263void LLVertexBuffer::stopRender()
264{
265 unbind(); 282 unbind();
266 sRenderActive = FALSE; 283 clientCopy(); // deletes GL buffers
267} 284}
268 285
269void LLVertexBuffer::clientCopy(F64 max_time) 286void LLVertexBuffer::clientCopy(F64 max_time)
@@ -717,7 +734,7 @@ BOOL LLVertexBuffer::useVBOs() const
717 return FALSE; 734 return FALSE;
718 } 735 }
719#endif 736#endif
720 return sEnableVBOs; // && (!sRenderActive || !mLocked); 737 return sEnableVBOs;
721} 738}
722 739
723//---------------------------------------------------------------------------- 740//----------------------------------------------------------------------------
@@ -1000,10 +1017,6 @@ void LLVertexBuffer::setBuffer(U32 data_mask)
1000 sGLRenderBuffer = mGLBuffer; 1017 sGLRenderBuffer = mGLBuffer;
1001 if (data_mask && setup) 1018 if (data_mask && setup)
1002 { 1019 {
1003 if (!sRenderActive)
1004 {
1005 llwarns << "Vertex buffer set for rendering outside of render frame." << llendl;
1006 }
1007 setupVertexBuffer(data_mask); // subclass specific setup (virtual function) 1020 setupVertexBuffer(data_mask); // subclass specific setup (virtual function)
1008 sSetCount++; 1021 sSetCount++;
1009 } 1022 }
diff --git a/linden/indra/llrender/llvertexbuffer.h b/linden/indra/llrender/llvertexbuffer.h
index 453f3ac..64a6f60 100644
--- a/linden/indra/llrender/llvertexbuffer.h
+++ b/linden/indra/llrender/llvertexbuffer.h
@@ -85,9 +85,7 @@ public:
85 static void initClass(bool use_vbo); 85 static void initClass(bool use_vbo);
86 static void cleanupClass(); 86 static void cleanupClass();
87 static void setupClientArrays(U32 data_mask); 87 static void setupClientArrays(U32 data_mask);
88 static void startRender(); //between start and stop render, no client copies will occur 88 static void clientCopy(F64 max_time = 0.005); //copy data from client to GL
89 static void stopRender(); //any buffer not copied to GL will be rendered from client memory
90 static void clientCopy(F64 max_time = 0.005); //copy data from client to GL
91 static void unbind(); //unbind any bound vertex buffer 89 static void unbind(); //unbind any bound vertex buffer
92 90
93 //get the size of a vertex with the given typemask 91 //get the size of a vertex with the given typemask
@@ -131,6 +129,8 @@ public:
131 POINTS, 129 POINTS,
132 LINES, 130 LINES,
133 LINE_STRIP, 131 LINE_STRIP,
132 QUADS,
133 LINE_LOOP,
134 NUM_MODES 134 NUM_MODES
135 }; 135 };
136protected: 136protected:
@@ -205,6 +205,7 @@ public:
205 void markDirty(U32 vert_index, U32 vert_count, U32 indices_index, U32 indices_count); 205 void markDirty(U32 vert_index, U32 vert_count, U32 indices_index, U32 indices_count);
206 206
207 void draw(U32 mode, U32 count, U32 indices_offset) const; 207 void draw(U32 mode, U32 count, U32 indices_offset) const;
208 void drawArrays(U32 mode, U32 offset, U32 count) const;
208 void drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const; 209 void drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const;
209 210
210protected: 211protected:
@@ -244,7 +245,6 @@ protected:
244 std::vector<DirtyRegion> mDirtyRegions; //vector of dirty regions to rebuild 245 std::vector<DirtyRegion> mDirtyRegions; //vector of dirty regions to rebuild
245 246
246public: 247public:
247 static BOOL sRenderActive;
248 static S32 sCount; 248 static S32 sCount;
249 static S32 sGLCount; 249 static S32 sGLCount;
250 static S32 sMappedCount; 250 static S32 sMappedCount;