diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/llfloaterimagepreview.cpp | 150 |
1 files changed, 66 insertions, 84 deletions
diff --git a/linden/indra/newview/llfloaterimagepreview.cpp b/linden/indra/newview/llfloaterimagepreview.cpp index 912a4fc..4a8c66e 100644 --- a/linden/indra/newview/llfloaterimagepreview.cpp +++ b/linden/indra/newview/llfloaterimagepreview.cpp | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * $LicenseInfo:firstyear=2004&license=viewergpl$ | 5 | * $LicenseInfo:firstyear=2004&license=viewergpl$ |
6 | * | 6 | * |
7 | * Copyright (c) 2004-2008, Linden Research, Inc. | 7 | * Copyright (c) 2004-2009, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | 9 | * Second Life Viewer Source Code |
10 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * The source code in this file ("Source Code") is provided by Linden Lab |
@@ -75,7 +75,7 @@ LLFloaterImagePreview::LLFloaterImagePreview(const std::string& filename) : | |||
75 | { | 75 | { |
76 | mLastMouseX = 0; | 76 | mLastMouseX = 0; |
77 | mLastMouseY = 0; | 77 | mLastMouseY = 0; |
78 | mGLName = 0; | 78 | mImagep = NULL ; |
79 | loadImage(mFilenameAndPath); | 79 | loadImage(mFilenameAndPath); |
80 | } | 80 | } |
81 | 81 | ||
@@ -138,10 +138,7 @@ LLFloaterImagePreview::~LLFloaterImagePreview() | |||
138 | delete mAvatarPreview; | 138 | delete mAvatarPreview; |
139 | delete mSculptedPreview; | 139 | delete mSculptedPreview; |
140 | 140 | ||
141 | if (mGLName) | 141 | mImagep = NULL ; |
142 | { | ||
143 | glDeleteTextures(1, &mGLName ); | ||
144 | } | ||
145 | } | 142 | } |
146 | 143 | ||
147 | //static | 144 | //static |
@@ -224,44 +221,31 @@ void LLFloaterImagePreview::draw() | |||
224 | gl_rect_2d_checkerboard(mPreviewRect); | 221 | gl_rect_2d_checkerboard(mPreviewRect); |
225 | LLGLDisable gls_alpha(GL_ALPHA_TEST); | 222 | LLGLDisable gls_alpha(GL_ALPHA_TEST); |
226 | 223 | ||
227 | GLenum format_options[4] = { GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA }; | 224 | if(mImagep.notNull()) |
228 | GLenum format = format_options[mRawImagep->getComponents()-1]; | ||
229 | |||
230 | GLenum internal_format_options[4] = { GL_LUMINANCE8, GL_LUMINANCE8_ALPHA8, GL_RGB8, GL_RGBA8 }; | ||
231 | GLenum internal_format = internal_format_options[mRawImagep->getComponents()-1]; | ||
232 | |||
233 | if (mGLName) | ||
234 | { | 225 | { |
235 | LLImageGL::bindExternalTexture( mGLName, 0, GL_TEXTURE_2D ); | 226 | gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mImagep->getTexName()); |
236 | } | 227 | } |
237 | else | 228 | else |
238 | { | 229 | { |
239 | glGenTextures(1, &mGLName ); | 230 | mImagep = new LLImageGL(mRawImagep, FALSE) ; |
240 | stop_glerror(); | 231 | |
241 | 232 | gGL.getTexUnit(0)->unbind(mImagep->getTarget()) ; | |
242 | LLImageGL::bindExternalTexture( mGLName, 0, GL_TEXTURE_2D ); | 233 | gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mImagep->getTexName()); |
243 | stop_glerror(); | ||
244 | |||
245 | glTexImage2D( | ||
246 | GL_TEXTURE_2D, 0, internal_format, | ||
247 | mRawImagep->getWidth(), mRawImagep->getHeight(), | ||
248 | 0, format, GL_UNSIGNED_BYTE, mRawImagep->getData()); | ||
249 | stop_glerror(); | 234 | stop_glerror(); |
250 | 235 | ||
251 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 236 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
252 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 237 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
253 | 238 | ||
254 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 239 | gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP); |
255 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | ||
256 | if (mAvatarPreview) | 240 | if (mAvatarPreview) |
257 | { | 241 | { |
258 | mAvatarPreview->setTexture(mGLName); | 242 | mAvatarPreview->setTexture(mImagep->getTexName()); |
259 | mSculptedPreview->setTexture(mGLName); | 243 | mSculptedPreview->setTexture(mImagep->getTexName()); |
260 | } | 244 | } |
261 | } | 245 | } |
262 | 246 | ||
263 | gGL.color3f(1.f, 1.f, 1.f); | 247 | gGL.color3f(1.f, 1.f, 1.f); |
264 | gGL.begin( LLVertexBuffer::QUADS ); | 248 | gGL.begin( LLRender::QUADS ); |
265 | { | 249 | { |
266 | gGL.texCoord2f(mPreviewImageRect.mLeft, mPreviewImageRect.mTop); | 250 | gGL.texCoord2f(mPreviewImageRect.mLeft, mPreviewImageRect.mTop); |
267 | gGL.vertex2i(PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT); | 251 | gGL.vertex2i(PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT); |
@@ -274,7 +258,7 @@ void LLFloaterImagePreview::draw() | |||
274 | } | 258 | } |
275 | gGL.end(); | 259 | gGL.end(); |
276 | 260 | ||
277 | LLImageGL::unbindTexture(0, GL_TEXTURE_2D); | 261 | gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); |
278 | 262 | ||
279 | stop_glerror(); | 263 | stop_glerror(); |
280 | } | 264 | } |
@@ -285,11 +269,15 @@ void LLFloaterImagePreview::draw() | |||
285 | gGL.color3f(1.f, 1.f, 1.f); | 269 | gGL.color3f(1.f, 1.f, 1.f); |
286 | 270 | ||
287 | if (selected == 9) | 271 | if (selected == 9) |
288 | mSculptedPreview->bindTexture(); | 272 | { |
273 | gGL.getTexUnit(0)->bind(mSculptedPreview->getTexture()); | ||
274 | } | ||
289 | else | 275 | else |
290 | mAvatarPreview->bindTexture(); | 276 | { |
277 | gGL.getTexUnit(0)->bind(mAvatarPreview->getTexture()); | ||
278 | } | ||
291 | 279 | ||
292 | gGL.begin( LLVertexBuffer::QUADS ); | 280 | gGL.begin( LLRender::QUADS ); |
293 | { | 281 | { |
294 | gGL.texCoord2f(0.f, 1.f); | 282 | gGL.texCoord2f(0.f, 1.f); |
295 | gGL.vertex2i(PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT); | 283 | gGL.vertex2i(PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT); |
@@ -302,10 +290,7 @@ void LLFloaterImagePreview::draw() | |||
302 | } | 290 | } |
303 | gGL.end(); | 291 | gGL.end(); |
304 | 292 | ||
305 | if (selected == 9) | 293 | gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); |
306 | mSculptedPreview->unbindTexture(); | ||
307 | else | ||
308 | mAvatarPreview->unbindTexture(); | ||
309 | } | 294 | } |
310 | } | 295 | } |
311 | } | 296 | } |
@@ -774,7 +759,9 @@ LLImagePreviewSculpted::LLImagePreviewSculpted(S32 width, S32 height) : LLDynami | |||
774 | LLVolumeParams volume_params; | 759 | LLVolumeParams volume_params; |
775 | volume_params.setType(LL_PCODE_PROFILE_CIRCLE, LL_PCODE_PATH_CIRCLE); | 760 | volume_params.setType(LL_PCODE_PROFILE_CIRCLE, LL_PCODE_PATH_CIRCLE); |
776 | volume_params.setSculptID(LLUUID::null, LL_SCULPT_TYPE_SPHERE); | 761 | volume_params.setSculptID(LLUUID::null, LL_SCULPT_TYPE_SPHERE); |
777 | mVolume = new LLVolume(volume_params, (F32) MAX_LOD); | 762 | |
763 | F32 const HIGHEST_LOD = 4.0f; | ||
764 | mVolume = new LLVolume(volume_params, HIGHEST_LOD); | ||
778 | 765 | ||
779 | /* | 766 | /* |
780 | mDummyAvatar = new LLVOAvatar(LLUUID::null, LL_PCODE_LEGACY_AVATAR, gAgent.getRegion()); | 767 | mDummyAvatar = new LLVOAvatar(LLUUID::null, LL_PCODE_LEGACY_AVATAR, gAgent.getRegion()); |
@@ -811,7 +798,36 @@ void LLImagePreviewSculpted::setPreviewTarget(LLImageRaw* imagep, F32 distance) | |||
811 | { | 798 | { |
812 | mVolume->sculpt(imagep->getWidth(), imagep->getHeight(), imagep->getComponents(), imagep->getData(), 0); | 799 | mVolume->sculpt(imagep->getWidth(), imagep->getHeight(), imagep->getComponents(), imagep->getData(), 0); |
813 | } | 800 | } |
814 | 801 | ||
802 | const LLVolumeFace &vf = mVolume->getVolumeFace(0); | ||
803 | U32 num_indices = vf.mIndices.size(); | ||
804 | U32 num_vertices = vf.mVertices.size(); | ||
805 | |||
806 | mVertexBuffer = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL, 0); | ||
807 | mVertexBuffer->allocateBuffer(num_vertices, num_indices, TRUE); | ||
808 | |||
809 | LLStrider<LLVector3> vertex_strider; | ||
810 | LLStrider<LLVector3> normal_strider; | ||
811 | LLStrider<U16> index_strider; | ||
812 | |||
813 | mVertexBuffer->getVertexStrider(vertex_strider); | ||
814 | mVertexBuffer->getNormalStrider(normal_strider); | ||
815 | mVertexBuffer->getIndexStrider(index_strider); | ||
816 | |||
817 | // build vertices and normals | ||
818 | for (U32 i = 0; (S32)i < num_vertices; i++) | ||
819 | { | ||
820 | *(vertex_strider++) = vf.mVertices[i].mPosition; | ||
821 | LLVector3 normal = vf.mVertices[i].mNormal; | ||
822 | normal.normalize(); | ||
823 | *(normal_strider++) = normal; | ||
824 | } | ||
825 | |||
826 | // build indices | ||
827 | for (U16 i = 0; i < num_indices; i++) | ||
828 | { | ||
829 | *(index_strider++) = vf.mIndices[i]; | ||
830 | } | ||
815 | } | 831 | } |
816 | 832 | ||
817 | 833 | ||
@@ -846,7 +862,7 @@ BOOL LLImagePreviewSculpted::render() | |||
846 | glMatrixMode(GL_MODELVIEW); | 862 | glMatrixMode(GL_MODELVIEW); |
847 | gGL.popMatrix(); | 863 | gGL.popMatrix(); |
848 | 864 | ||
849 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | 865 | glClear(GL_DEPTH_BUFFER_BIT); |
850 | 866 | ||
851 | LLVector3 target_pos(0, 0, 0); | 867 | LLVector3 target_pos(0, 0, 0); |
852 | 868 | ||
@@ -865,55 +881,21 @@ BOOL LLImagePreviewSculpted::render() | |||
865 | LLViewerCamera::getInstance()->setView(LLViewerCamera::getInstance()->getDefaultFOV() / mCameraZoom); | 881 | LLViewerCamera::getInstance()->setView(LLViewerCamera::getInstance()->getDefaultFOV() / mCameraZoom); |
866 | LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mWidth, mHeight, FALSE); | 882 | LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mWidth, mHeight, FALSE); |
867 | 883 | ||
868 | gPipeline.enableLightsAvatar(); | ||
869 | |||
870 | gGL.pushMatrix(); | ||
871 | glScalef(0.5, 0.5, 0.5); | ||
872 | |||
873 | const LLVolumeFace &vf = mVolume->getVolumeFace(0); | 884 | const LLVolumeFace &vf = mVolume->getVolumeFace(0); |
874 | U32 num_indices = vf.mIndices.size(); | 885 | U32 num_indices = vf.mIndices.size(); |
875 | U32 num_vertices = vf.mVertices.size(); | 886 | |
876 | 887 | mVertexBuffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL); | |
877 | if (num_vertices > 0 && num_indices > 0) | ||
878 | { | ||
879 | glEnableClientState(GL_NORMAL_ARRAY); | ||
880 | // build vertices and normals | ||
881 | F32* vertices = new F32[num_vertices * 3]; | ||
882 | F32* normals = new F32[num_vertices * 3]; | ||
883 | |||
884 | for (U32 i = 0; (S32)i < num_vertices; i++) | ||
885 | { | ||
886 | LLVector3 position = vf.mVertices[i].mPosition; | ||
887 | vertices[i*3] = position.mV[VX]; | ||
888 | vertices[i*3+1] = position.mV[VY]; | ||
889 | vertices[i*3+2] = position.mV[VZ]; | ||
890 | |||
891 | LLVector3 normal = vf.mVertices[i].mNormal; | ||
892 | normals[i*3] = normal.mV[VX]; | ||
893 | normals[i*3+1] = normal.mV[VY]; | ||
894 | normals[i*3+2] = normal.mV[VZ]; | ||
895 | } | ||
896 | 888 | ||
897 | // build indices | 889 | gPipeline.enableLightsAvatar(); |
898 | U16* indices = new U16[num_indices]; | 890 | gGL.pushMatrix(); |
899 | for (U16 i = 0; i < num_indices; i++) | 891 | const F32 SCALE = 1.25f; |
900 | { | 892 | gGL.scalef(SCALE, SCALE, SCALE); |
901 | indices[i] = vf.mIndices[i]; | 893 | const F32 BRIGHTNESS = 0.9f; |
902 | } | 894 | gGL.color3f(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS); |
895 | mVertexBuffer->draw(LLRender::TRIANGLES, num_indices, 0); | ||
903 | 896 | ||
904 | gGL.color3f(0.4f, 0.4f, 0.4f); | 897 | gGL.popMatrix(); |
905 | glVertexPointer(3, GL_FLOAT, 0, (void *)vertices); | ||
906 | glNormalPointer(GL_FLOAT, 0, (void *)normals); | ||
907 | glDrawRangeElements(GL_TRIANGLES, 0, num_vertices-1, num_indices, GL_UNSIGNED_SHORT, (void *)indices); | ||
908 | 898 | ||
909 | gGL.popMatrix(); | ||
910 | glDisableClientState(GL_NORMAL_ARRAY); | ||
911 | |||
912 | delete [] indices; | ||
913 | delete [] vertices; | ||
914 | delete [] normals; | ||
915 | } | ||
916 | |||
917 | return TRUE; | 899 | return TRUE; |
918 | } | 900 | } |
919 | 901 | ||