aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llrender/llvertexbuffer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llrender/llvertexbuffer.cpp')
-rw-r--r--linden/indra/llrender/llvertexbuffer.cpp176
1 files changed, 160 insertions, 16 deletions
diff --git a/linden/indra/llrender/llvertexbuffer.cpp b/linden/indra/llrender/llvertexbuffer.cpp
index f3c6997..d165c01 100644
--- a/linden/indra/llrender/llvertexbuffer.cpp
+++ b/linden/indra/llrender/llvertexbuffer.cpp
@@ -38,6 +38,7 @@
38#include "llglheaders.h" 38#include "llglheaders.h"
39#include "llmemory.h" 39#include "llmemory.h"
40#include "llmemtype.h" 40#include "llmemtype.h"
41#include "llglimmediate.h"
41 42
42//============================================================================ 43//============================================================================
43 44
@@ -76,6 +77,141 @@ S32 LLVertexBuffer::sTypeOffsets[LLVertexBuffer::TYPE_MAX] =
76 sizeof(LLVector4), // TYPE_CLOTHWEIGHT, 77 sizeof(LLVector4), // TYPE_CLOTHWEIGHT,
77}; 78};
78 79
80U32 LLVertexBuffer::sGLMode[LLVertexBuffer::NUM_MODES] =
81{
82 GL_TRIANGLES,
83 GL_TRIANGLE_STRIP,
84 GL_TRIANGLE_FAN,
85 GL_POINTS,
86 GL_LINES,
87 GL_LINE_STRIP
88};
89
90//static
91void LLVertexBuffer::setupClientArrays(U32 data_mask)
92{
93 if (LLGLImmediate::sStarted)
94 {
95 llerrs << "Cannot use LLGLImmediate and LLVertexBuffer simultaneously!" << llendl;
96 }
97
98 if (sLastMask != data_mask)
99 {
100 U32 mask[] =
101 {
102 MAP_VERTEX,
103 MAP_NORMAL,
104 MAP_TEXCOORD,
105 MAP_COLOR
106 };
107
108 GLenum array[] =
109 {
110 GL_VERTEX_ARRAY,
111 GL_NORMAL_ARRAY,
112 GL_TEXTURE_COORD_ARRAY,
113 GL_COLOR_ARRAY
114 };
115
116 for (U32 i = 0; i < 4; ++i)
117 {
118 if (sLastMask & mask[i])
119 { //was enabled
120 if (!(data_mask & mask[i]) && i > 0)
121 { //needs to be disabled
122 glDisableClientState(array[i]);
123 }
124 else
125 { //needs to be enabled, make sure it was (DEBUG TEMPORARY)
126 if (i > 0 && !glIsEnabled(array[i]))
127 {
128 llerrs << "Bad client state! " << array[i] << " disabled." << llendl;
129 }
130 }
131 }
132 else
133 { //was disabled
134 if (data_mask & mask[i])
135 { //needs to be enabled
136 glEnableClientState(array[i]);
137 }
138 else if (glIsEnabled(array[i]))
139 { //needs to be disabled, make sure it was (DEBUG TEMPORARY)
140 llerrs << "Bad client state! " << array[i] << " enabled." << llendl;
141 }
142 }
143 }
144
145 if (sLastMask & MAP_TEXCOORD2)
146 {
147 if (!(data_mask & MAP_TEXCOORD2))
148 {
149 glClientActiveTextureARB(GL_TEXTURE1_ARB);
150 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
151 glClientActiveTextureARB(GL_TEXTURE0_ARB);
152 }
153 }
154 else if (data_mask & MAP_TEXCOORD2)
155 {
156 glClientActiveTextureARB(GL_TEXTURE1_ARB);
157 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
158 glClientActiveTextureARB(GL_TEXTURE0_ARB);
159 }
160
161 sLastMask = data_mask;
162 }
163}
164
165void LLVertexBuffer::drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const
166{
167 if (start >= (U32) mRequestedNumVerts ||
168 end >= (U32) mRequestedNumVerts)
169 {
170 llerrs << "Bad vertex buffer draw range: [" << start << ", " << end << "]" << llendl;
171 }
172
173 if (indices_offset >= (U32) mRequestedNumIndices ||
174 indices_offset + count > (U32) mRequestedNumIndices)
175 {
176 llerrs << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << llendl;
177 }
178
179 if (mGLIndices != sGLRenderIndices)
180 {
181 llerrs << "Wrong index buffer bound." << llendl;
182 }
183
184 if (mGLBuffer != sGLRenderBuffer)
185 {
186 llerrs << "Wrong vertex buffer bound." << llendl;
187 }
188
189 glDrawRangeElements(sGLMode[mode], start, end, count, GL_UNSIGNED_SHORT,
190 ((U16*) getIndicesPointer()) + indices_offset);
191}
192
193void LLVertexBuffer::draw(U32 mode, U32 count, U32 indices_offset) const
194{
195 if (indices_offset >= (U32) mRequestedNumIndices ||
196 indices_offset + count > (U32) mRequestedNumIndices)
197 {
198 llerrs << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << llendl;
199 }
200
201 if (mGLIndices != sGLRenderIndices)
202 {
203 llerrs << "Wrong index buffer bound." << llendl;
204 }
205
206 if (mGLBuffer != sGLRenderBuffer)
207 {
208 llerrs << "Wrong vertex buffer bound." << llendl;
209 }
210
211 glDrawElements(sGLMode[mode], count, GL_UNSIGNED_SHORT,
212 ((U16*) getIndicesPointer()) + indices_offset);
213}
214
79//static 215//static
80void LLVertexBuffer::initClass(bool use_vbo) 216void LLVertexBuffer::initClass(bool use_vbo)
81{ 217{
@@ -102,7 +238,8 @@ void LLVertexBuffer::unbind()
102 238
103 sGLRenderBuffer = 0; 239 sGLRenderBuffer = 0;
104 sGLRenderIndices = 0; 240 sGLRenderIndices = 0;
105 sLastMask = 0; 241
242 setupClientArrays(0);
106} 243}
107 244
108//static 245//static
@@ -118,22 +255,14 @@ void LLVertexBuffer::cleanupClass()
118void LLVertexBuffer::startRender() 255void LLVertexBuffer::startRender()
119{ 256{
120 LLMemType mt(LLMemType::MTYPE_VERTEX_DATA); 257 LLMemType mt(LLMemType::MTYPE_VERTEX_DATA);
121 if (sEnableVBOs) 258
122 { 259 unbind();
123 glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
124 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
125 sVBOActive = FALSE;
126 sIBOActive = FALSE;
127 }
128
129 sRenderActive = TRUE; 260 sRenderActive = TRUE;
130 sGLRenderBuffer = 0;
131 sGLRenderIndices = 0;
132 sLastMask = 0;
133} 261}
134 262
135void LLVertexBuffer::stopRender() 263void LLVertexBuffer::stopRender()
136{ 264{
265 unbind();
137 sRenderActive = FALSE; 266 sRenderActive = FALSE;
138} 267}
139 268
@@ -615,6 +744,16 @@ U8* LLVertexBuffer::mapBuffer(S32 access)
615 llerrs << "Mapped two VBOs at the same time!" << llendl; 744 llerrs << "Mapped two VBOs at the same time!" << llendl;
616 } 745 }
617 sMapped = TRUE;*/ 746 sMapped = TRUE;*/
747 if (!mMappedData)
748 {
749 llerrs << "glMapBuffer returned NULL (no vertex data)" << llendl;
750 }
751
752 if (!mMappedIndexData)
753 {
754 llerrs << "glMapBuffer returned NULL (no index data)" << llendl;
755 }
756
618 sMappedCount++; 757 sMappedCount++;
619 } 758 }
620 759
@@ -666,7 +805,12 @@ template <class T,S32 type> struct VertexBufferStrider
666 strider_t& strider, 805 strider_t& strider,
667 S32 index) 806 S32 index)
668 { 807 {
669 vbo.mapBuffer(); 808 if (vbo.mapBuffer() == NULL)
809 {
810 llwarns << "mapBuffer failed!" << llendl;
811 return FALSE;
812 }
813
670 if (type == LLVertexBuffer::TYPE_INDEX) 814 if (type == LLVertexBuffer::TYPE_INDEX)
671 { 815 {
672 S32 stride = sizeof(T); 816 S32 stride = sizeof(T);
@@ -828,6 +972,8 @@ void LLVertexBuffer::setBuffer(U32 data_mask)
828 sIBOActive = FALSE; 972 sIBOActive = FALSE;
829 } 973 }
830 } 974 }
975
976 setupClientArrays(data_mask);
831 977
832 if (mGLIndices) 978 if (mGLIndices)
833 { 979 {
@@ -846,8 +992,6 @@ void LLVertexBuffer::setBuffer(U32 data_mask)
846 sSetCount++; 992 sSetCount++;
847 } 993 }
848 } 994 }
849
850 sLastMask = data_mask;
851} 995}
852 996
853// virtual (default) 997// virtual (default)
@@ -871,10 +1015,10 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) const
871 { 1015 {
872 glClientActiveTextureARB(GL_TEXTURE1_ARB); 1016 glClientActiveTextureARB(GL_TEXTURE1_ARB);
873 glTexCoordPointer(2,GL_FLOAT, stride, (void*)(base + mOffsets[TYPE_TEXCOORD2])); 1017 glTexCoordPointer(2,GL_FLOAT, stride, (void*)(base + mOffsets[TYPE_TEXCOORD2]));
1018 glClientActiveTextureARB(GL_TEXTURE0_ARB);
874 } 1019 }
875 if (data_mask & MAP_TEXCOORD) 1020 if (data_mask & MAP_TEXCOORD)
876 { 1021 {
877 glClientActiveTextureARB(GL_TEXTURE0_ARB);
878 glTexCoordPointer(2,GL_FLOAT, stride, (void*)(base + mOffsets[TYPE_TEXCOORD])); 1022 glTexCoordPointer(2,GL_FLOAT, stride, (void*)(base + mOffsets[TYPE_TEXCOORD]));
879 } 1023 }
880 if (data_mask & MAP_COLOR) 1024 if (data_mask & MAP_COLOR)