diff options
Diffstat (limited to 'linden/indra/newview/lldrawpooltree.cpp')
-rw-r--r-- | linden/indra/newview/lldrawpooltree.cpp | 112 |
1 files changed, 65 insertions, 47 deletions
diff --git a/linden/indra/newview/lldrawpooltree.cpp b/linden/indra/newview/lldrawpooltree.cpp index f5971be..fd1ca8e 100644 --- a/linden/indra/newview/lldrawpooltree.cpp +++ b/linden/indra/newview/lldrawpooltree.cpp | |||
@@ -41,8 +41,10 @@ | |||
41 | #include "pipeline.h" | 41 | #include "pipeline.h" |
42 | #include "llviewercamera.h" | 42 | #include "llviewercamera.h" |
43 | #include "llglslshader.h" | 43 | #include "llglslshader.h" |
44 | #include "llglimmediate.h" | ||
44 | 45 | ||
45 | S32 LLDrawPoolTree::sDiffTex = 0; | 46 | S32 LLDrawPoolTree::sDiffTex = 0; |
47 | static LLGLSLShader* shader = NULL; | ||
46 | 48 | ||
47 | LLDrawPoolTree::LLDrawPoolTree(LLViewerImage *texturep) : | 49 | LLDrawPoolTree::LLDrawPoolTree(LLViewerImage *texturep) : |
48 | LLFacePool(POOL_TREE), | 50 | LLFacePool(POOL_TREE), |
@@ -59,15 +61,34 @@ LLDrawPool *LLDrawPoolTree::instancePool() | |||
59 | 61 | ||
60 | void LLDrawPoolTree::prerender() | 62 | void LLDrawPoolTree::prerender() |
61 | { | 63 | { |
62 | mVertexShaderLevel = 0; | 64 | mVertexShaderLevel = LLShaderMgr::getVertexShaderLevel(LLShaderMgr::SHADER_OBJECT); |
63 | } | 65 | } |
64 | 66 | ||
65 | void LLDrawPoolTree::beginRenderPass(S32 pass) | 67 | void LLDrawPoolTree::beginRenderPass(S32 pass) |
66 | { | 68 | { |
69 | LLFastTimer t(LLFastTimer::FTM_RENDER_TREES); | ||
67 | glEnableClientState(GL_VERTEX_ARRAY); | 70 | glEnableClientState(GL_VERTEX_ARRAY); |
68 | glEnableClientState(GL_NORMAL_ARRAY); | 71 | glEnableClientState(GL_NORMAL_ARRAY); |
69 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); | 72 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
70 | glAlphaFunc(GL_GREATER, 0.5f); | 73 | glAlphaFunc(GL_GREATER, 0.5f); |
74 | |||
75 | if (LLPipeline::sUnderWaterRender) | ||
76 | { | ||
77 | shader = &gObjectSimpleWaterProgram; | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | shader = &gObjectSimpleProgram; | ||
82 | } | ||
83 | |||
84 | if (gPipeline.canUseWindLightShadersOnObjects()) | ||
85 | { | ||
86 | shader->bind(); | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | gPipeline.enableLightsDynamic(); | ||
91 | } | ||
71 | } | 92 | } |
72 | 93 | ||
73 | void LLDrawPoolTree::render(S32 pass) | 94 | void LLDrawPoolTree::render(S32 pass) |
@@ -79,8 +100,7 @@ void LLDrawPoolTree::render(S32 pass) | |||
79 | return; | 100 | return; |
80 | } | 101 | } |
81 | 102 | ||
82 | gPipeline.enableLightsDynamic(1.f); | 103 | LLGLEnable test(GL_ALPHA_TEST); |
83 | LLGLSPipelineAlpha gls_pipeline_alpha; | ||
84 | LLOverrideFaceColor color(this, 1.f, 1.f, 1.f, 1.f); | 104 | LLOverrideFaceColor color(this, 1.f, 1.f, 1.f, 1.f); |
85 | 105 | ||
86 | renderTree(); | 106 | renderTree(); |
@@ -88,9 +108,15 @@ void LLDrawPoolTree::render(S32 pass) | |||
88 | 108 | ||
89 | void LLDrawPoolTree::endRenderPass(S32 pass) | 109 | void LLDrawPoolTree::endRenderPass(S32 pass) |
90 | { | 110 | { |
111 | LLFastTimer t(LLFastTimer::FTM_RENDER_TREES); | ||
91 | glAlphaFunc(GL_GREATER, 0.01f); | 112 | glAlphaFunc(GL_GREATER, 0.01f); |
92 | glDisableClientState(GL_NORMAL_ARRAY); | 113 | glDisableClientState(GL_NORMAL_ARRAY); |
93 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | 114 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
115 | |||
116 | if (gPipeline.canUseWindLightShadersOnObjects()) | ||
117 | { | ||
118 | shader->unbind(); | ||
119 | } | ||
94 | } | 120 | } |
95 | 121 | ||
96 | void LLDrawPoolTree::renderForSelect() | 122 | void LLDrawPoolTree::renderForSelect() |
@@ -107,7 +133,7 @@ void LLDrawPoolTree::renderForSelect() | |||
107 | 133 | ||
108 | LLGLSObjectSelectAlpha gls_alpha; | 134 | LLGLSObjectSelectAlpha gls_alpha; |
109 | 135 | ||
110 | glBlendFunc(GL_ONE, GL_ZERO); | 136 | gGL.blendFunc(GL_ONE, GL_ZERO); |
111 | glAlphaFunc(GL_GREATER, 0.5f); | 137 | glAlphaFunc(GL_GREATER, 0.5f); |
112 | 138 | ||
113 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); | 139 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB); |
@@ -126,7 +152,7 @@ void LLDrawPoolTree::renderForSelect() | |||
126 | renderTree(TRUE); | 152 | renderTree(TRUE); |
127 | 153 | ||
128 | glAlphaFunc(GL_GREATER, 0.01f); | 154 | glAlphaFunc(GL_GREATER, 0.01f); |
129 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | 155 | gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
130 | 156 | ||
131 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); | 157 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
132 | glDisableClientState (GL_TEXTURE_COORD_ARRAY); | 158 | glDisableClientState (GL_TEXTURE_COORD_ARRAY); |
@@ -138,16 +164,7 @@ void LLDrawPoolTree::renderTree(BOOL selecting) | |||
138 | 164 | ||
139 | // Bind the texture for this tree. | 165 | // Bind the texture for this tree. |
140 | LLViewerImage::bindTexture(mTexturep,sDiffTex); | 166 | LLViewerImage::bindTexture(mTexturep,sDiffTex); |
141 | if (mTexturep) | 167 | |
142 | { | ||
143 | if (mTexturep->getClampS()) { | ||
144 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | ||
145 | } | ||
146 | if (mTexturep->getClampT()) { | ||
147 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | ||
148 | } | ||
149 | } | ||
150 | |||
151 | U32 indices_drawn = 0; | 168 | U32 indices_drawn = 0; |
152 | 169 | ||
153 | glMatrixMode(GL_MODELVIEW); | 170 | glMatrixMode(GL_MODELVIEW); |
@@ -164,7 +181,7 @@ void LLDrawPoolTree::renderTree(BOOL selecting) | |||
164 | } | 181 | } |
165 | 182 | ||
166 | face->mVertexBuffer->setBuffer(LLDrawPoolTree::VERTEX_DATA_MASK); | 183 | face->mVertexBuffer->setBuffer(LLDrawPoolTree::VERTEX_DATA_MASK); |
167 | U32* indicesp = (U32*) face->mVertexBuffer->getIndicesPointer(); | 184 | U16* indicesp = (U16*) face->mVertexBuffer->getIndicesPointer(); |
168 | 185 | ||
169 | // Render each of the trees | 186 | // Render each of the trees |
170 | LLVOTree *treep = (LLVOTree *)drawablep->getVObj().get(); | 187 | LLVOTree *treep = (LLVOTree *)drawablep->getVObj().get(); |
@@ -180,28 +197,43 @@ void LLDrawPoolTree::renderTree(BOOL selecting) | |||
180 | color = LLColor4U((U8)(name >> 16), (U8)(name >> 8), (U8)name, 255); | 197 | color = LLColor4U((U8)(name >> 16), (U8)(name >> 8), (U8)name, 255); |
181 | } | 198 | } |
182 | 199 | ||
183 | glPushMatrix(); | 200 | gGLLastMatrix = NULL; |
201 | glLoadMatrixd(gGLModelView); | ||
202 | //glPushMatrix(); | ||
203 | F32 mat[16]; | ||
204 | for (U32 i = 0; i < 16; i++) | ||
205 | mat[i] = (F32) gGLModelView[i]; | ||
206 | |||
207 | LLMatrix4 matrix(mat); | ||
184 | 208 | ||
185 | // Translate to tree base HACK - adjustment in Z plants tree underground | 209 | // Translate to tree base HACK - adjustment in Z plants tree underground |
186 | const LLVector3 &pos_agent = treep->getPositionAgent(); | 210 | const LLVector3 &pos_agent = treep->getPositionAgent(); |
187 | glTranslatef(pos_agent.mV[VX], pos_agent.mV[VY], pos_agent.mV[VZ] - 0.1f); | 211 | //glTranslatef(pos_agent.mV[VX], pos_agent.mV[VY], pos_agent.mV[VZ] - 0.1f); |
188 | 212 | LLMatrix4 trans_mat; | |
189 | // Rotate to tree position | 213 | trans_mat.setTranslation(pos_agent.mV[VX], pos_agent.mV[VY], pos_agent.mV[VZ] - 0.1f); |
190 | F32 angle_radians, x, y, z; | 214 | trans_mat *= matrix; |
191 | treep->getRotation().getAngleAxis(&angle_radians, &x, &y, &z); | 215 | |
192 | glRotatef(angle_radians * RAD_TO_DEG, x, y, z); | 216 | // Rotate to tree position and bend for current trunk/wind |
193 | |||
194 | // Rotate and bend for current trunk/wind | ||
195 | // Note that trunk stiffness controls the amount of bend at the trunk as | 217 | // Note that trunk stiffness controls the amount of bend at the trunk as |
196 | // opposed to the crown of the tree | 218 | // opposed to the crown of the tree |
197 | // | 219 | // |
198 | glRotatef(90.f, 0, 0, 1); | ||
199 | const F32 TRUNK_STIFF = 22.f; | 220 | const F32 TRUNK_STIFF = 22.f; |
200 | glRotatef(treep->mTrunkBend.magVec()*TRUNK_STIFF, treep->mTrunkBend.mV[VX], treep->mTrunkBend.mV[VY], 0); | 221 | |
222 | LLQuaternion rot = | ||
223 | LLQuaternion(treep->mTrunkBend.magVec()*TRUNK_STIFF*DEG_TO_RAD, LLVector4(treep->mTrunkBend.mV[VX], treep->mTrunkBend.mV[VY], 0)) * | ||
224 | LLQuaternion(90.f*DEG_TO_RAD, LLVector4(0,0,1)) * | ||
225 | treep->getRotation(); | ||
201 | 226 | ||
202 | F32 radius = treep->getScale().magVec()*0.5f; | 227 | LLMatrix4 rot_mat(rot); |
203 | radius *= 0.1f; | 228 | rot_mat *= trans_mat; |
204 | glScalef(radius, radius, radius); | 229 | |
230 | F32 radius = treep->getScale().magVec()*0.05f; | ||
231 | LLMatrix4 scale_mat; | ||
232 | scale_mat.mMatrix[0][0] = | ||
233 | scale_mat.mMatrix[1][1] = | ||
234 | scale_mat.mMatrix[2][2] = radius; | ||
235 | |||
236 | scale_mat *= rot_mat; | ||
205 | 237 | ||
206 | const F32 THRESH_ANGLE_FOR_BILLBOARD = 15.f; | 238 | const F32 THRESH_ANGLE_FOR_BILLBOARD = 15.f; |
207 | const F32 BLEND_RANGE_FOR_BILLBOARD = 3.f; | 239 | const F32 BLEND_RANGE_FOR_BILLBOARD = 3.f; |
@@ -231,7 +263,7 @@ void LLDrawPoolTree::renderTree(BOOL selecting) | |||
231 | // Only the billboard, can use closer to normal alpha func. | 263 | // Only the billboard, can use closer to normal alpha func. |
232 | stop_depth = -1; | 264 | stop_depth = -1; |
233 | LLFacePool::LLOverrideFaceColor clr(this, color); | 265 | LLFacePool::LLOverrideFaceColor clr(this, color); |
234 | indices_drawn += treep->drawBranchPipeline(indicesp, trunk_LOD, stop_depth, treep->mDepth, treep->mTrunkDepth, 1.0, treep->mTwist, droop, treep->mBranches, alpha); | 266 | indices_drawn += treep->drawBranchPipeline(scale_mat, indicesp, trunk_LOD, stop_depth, treep->mDepth, treep->mTrunkDepth, 1.0, treep->mTwist, droop, treep->mBranches, alpha); |
235 | } | 267 | } |
236 | else // if (app_angle > (THRESH_ANGLE_FOR_BILLBOARD + BLEND_RANGE_FOR_BILLBOARD)) | 268 | else // if (app_angle > (THRESH_ANGLE_FOR_BILLBOARD + BLEND_RANGE_FOR_BILLBOARD)) |
237 | { | 269 | { |
@@ -240,20 +272,10 @@ void LLDrawPoolTree::renderTree(BOOL selecting) | |||
240 | // | 272 | // |
241 | //stop_depth = (app_angle < THRESH_ANGLE_FOR_RECURSION_REDUCTION); | 273 | //stop_depth = (app_angle < THRESH_ANGLE_FOR_RECURSION_REDUCTION); |
242 | LLFacePool::LLOverrideFaceColor clr(this, color); | 274 | LLFacePool::LLOverrideFaceColor clr(this, color); |
243 | indices_drawn += treep->drawBranchPipeline(indicesp, trunk_LOD, stop_depth, treep->mDepth, treep->mTrunkDepth, 1.0, treep->mTwist, droop, treep->mBranches, alpha); | 275 | indices_drawn += treep->drawBranchPipeline(scale_mat, indicesp, trunk_LOD, stop_depth, treep->mDepth, treep->mTrunkDepth, 1.0, treep->mTwist, droop, treep->mBranches, alpha); |
244 | } | 276 | } |
245 | 277 | ||
246 | glPopMatrix(); | 278 | //glPopMatrix(); |
247 | } | ||
248 | } | ||
249 | |||
250 | if (mTexturep) | ||
251 | { | ||
252 | if (mTexturep->getClampS()) { | ||
253 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||
254 | } | ||
255 | if (mTexturep->getClampT()) { | ||
256 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
257 | } | 279 | } |
258 | } | 280 | } |
259 | 281 | ||
@@ -289,7 +311,3 @@ LLColor3 LLDrawPoolTree::getDebugColor() const | |||
289 | return LLColor3(1.f, 0.f, 1.f); | 311 | return LLColor3(1.f, 0.f, 1.f); |
290 | } | 312 | } |
291 | 313 | ||
292 | S32 LLDrawPoolTree::getMaterialAttribIndex() | ||
293 | { | ||
294 | return gObjectSimpleProgram.mAttribute[LLShaderMgr::MATERIAL_COLOR]; | ||
295 | } | ||