diff options
Diffstat (limited to 'linden/indra/llrender/llimagegl.cpp')
-rw-r--r-- | linden/indra/llrender/llimagegl.cpp | 79 |
1 files changed, 62 insertions, 17 deletions
diff --git a/linden/indra/llrender/llimagegl.cpp b/linden/indra/llrender/llimagegl.cpp index 76c8252..c4b90a7 100644 --- a/linden/indra/llrender/llimagegl.cpp +++ b/linden/indra/llrender/llimagegl.cpp | |||
@@ -128,10 +128,16 @@ S32 LLImageGL::dataFormatComponents(S32 dataformat) | |||
128 | void LLImageGL::bindExternalTexture(LLGLuint gl_name, S32 stage, LLGLenum bind_target ) | 128 | void LLImageGL::bindExternalTexture(LLGLuint gl_name, S32 stage, LLGLenum bind_target ) |
129 | { | 129 | { |
130 | gGL.flush(); | 130 | gGL.flush(); |
131 | glActiveTextureARB(GL_TEXTURE0_ARB + stage); | 131 | if (stage > 0) |
132 | glClientActiveTextureARB(GL_TEXTURE0_ARB + stage); | 132 | { |
133 | glActiveTextureARB(GL_TEXTURE0_ARB + stage); | ||
134 | } | ||
133 | glBindTexture(bind_target, gl_name); | 135 | glBindTexture(bind_target, gl_name); |
134 | sCurrentBoundTextures[stage] = gl_name; | 136 | sCurrentBoundTextures[stage] = gl_name; |
137 | if (stage > 0) | ||
138 | { | ||
139 | glActiveTextureARB(GL_TEXTURE0_ARB); | ||
140 | } | ||
135 | } | 141 | } |
136 | 142 | ||
137 | // static | 143 | // static |
@@ -141,9 +147,16 @@ void LLImageGL::unbindTexture(S32 stage, LLGLenum bind_target) | |||
141 | if (stage >= 0) | 147 | if (stage >= 0) |
142 | { | 148 | { |
143 | gGL.flush(); | 149 | gGL.flush(); |
144 | glActiveTextureARB(GL_TEXTURE0_ARB + stage); | 150 | if (stage > 0) |
145 | glClientActiveTextureARB(GL_TEXTURE0_ARB + stage); | 151 | { |
146 | glBindTexture(bind_target, 0); | 152 | glActiveTextureARB(GL_TEXTURE0_ARB + stage); |
153 | glBindTexture(GL_TEXTURE_2D, 0); | ||
154 | glActiveTextureARB(GL_TEXTURE0_ARB); | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | glBindTexture(GL_TEXTURE_2D, 0); | ||
159 | } | ||
147 | sCurrentBoundTextures[stage] = 0; | 160 | sCurrentBoundTextures[stage] = 0; |
148 | } | 161 | } |
149 | } | 162 | } |
@@ -151,15 +164,7 @@ void LLImageGL::unbindTexture(S32 stage, LLGLenum bind_target) | |||
151 | // static (duplicated for speed and to avoid GL_TEXTURE_2D default argument which requires GL header dependency) | 164 | // static (duplicated for speed and to avoid GL_TEXTURE_2D default argument which requires GL header dependency) |
152 | void LLImageGL::unbindTexture(S32 stage) | 165 | void LLImageGL::unbindTexture(S32 stage) |
153 | { | 166 | { |
154 | // LLGLSLShader can return -1 | 167 | unbindTexture(stage, GL_TEXTURE_2D); |
155 | if (stage >= 0) | ||
156 | { | ||
157 | gGL.flush(); | ||
158 | glActiveTextureARB(GL_TEXTURE0_ARB + stage); | ||
159 | glClientActiveTextureARB(GL_TEXTURE0_ARB + stage); | ||
160 | glBindTexture(GL_TEXTURE_2D, 0); | ||
161 | sCurrentBoundTextures[stage] = 0; | ||
162 | } | ||
163 | } | 168 | } |
164 | 169 | ||
165 | // static | 170 | // static |
@@ -419,8 +424,6 @@ BOOL LLImageGL::bindTextureInternal(const S32 stage) const | |||
419 | } | 424 | } |
420 | 425 | ||
421 | 426 | ||
422 | glActiveTextureARB(GL_TEXTURE0_ARB + stage); | ||
423 | |||
424 | if (sCurrentBoundTextures[stage] && sCurrentBoundTextures[stage] == mTexName) | 427 | if (sCurrentBoundTextures[stage] && sCurrentBoundTextures[stage] == mTexName) |
425 | { | 428 | { |
426 | // already set! | 429 | // already set! |
@@ -434,10 +437,20 @@ BOOL LLImageGL::bindTextureInternal(const S32 stage) const | |||
434 | #endif | 437 | #endif |
435 | 438 | ||
436 | gGL.flush(); | 439 | gGL.flush(); |
440 | if (stage > 0) | ||
441 | { | ||
442 | glActiveTextureARB(GL_TEXTURE0_ARB + stage); | ||
443 | } | ||
444 | |||
437 | glBindTexture(mBindTarget, mTexName); | 445 | glBindTexture(mBindTarget, mTexName); |
438 | sCurrentBoundTextures[stage] = mTexName; | 446 | sCurrentBoundTextures[stage] = mTexName; |
439 | sBindCount++; | 447 | sBindCount++; |
440 | 448 | ||
449 | if (stage > 0) | ||
450 | { | ||
451 | glActiveTextureARB(GL_TEXTURE0_ARB); | ||
452 | } | ||
453 | |||
441 | if (mLastBindTime != sLastFrameTime) | 454 | if (mLastBindTime != sLastFrameTime) |
442 | { | 455 | { |
443 | // we haven't accounted for this texture yet this frame | 456 | // we haven't accounted for this texture yet this frame |
@@ -451,7 +464,15 @@ BOOL LLImageGL::bindTextureInternal(const S32 stage) const | |||
451 | else | 464 | else |
452 | { | 465 | { |
453 | gGL.flush(); | 466 | gGL.flush(); |
467 | if (stage > 0) | ||
468 | { | ||
469 | glActiveTextureARB(GL_TEXTURE0_ARB+stage); | ||
470 | } | ||
454 | glBindTexture(mBindTarget, 0); | 471 | glBindTexture(mBindTarget, 0); |
472 | if (stage > 0) | ||
473 | { | ||
474 | glActiveTextureARB(GL_TEXTURE0_ARB+stage); | ||
475 | } | ||
455 | sCurrentBoundTextures[stage] = 0; | 476 | sCurrentBoundTextures[stage] = 0; |
456 | return FALSE; | 477 | return FALSE; |
457 | } | 478 | } |
@@ -985,6 +1006,21 @@ BOOL LLImageGL::setDiscardLevel(S32 discard_level) | |||
985 | } | 1006 | } |
986 | } | 1007 | } |
987 | 1008 | ||
1009 | BOOL LLImageGL::isValidForSculpt(S32 discard_level, S32 image_width, S32 image_height, S32 ncomponents) | ||
1010 | { | ||
1011 | assert_glerror(); | ||
1012 | S32 gl_discard = discard_level - mCurrentDiscardLevel; | ||
1013 | LLGLint glwidth = 0; | ||
1014 | glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_WIDTH, (GLint*)&glwidth); | ||
1015 | LLGLint glheight = 0; | ||
1016 | glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_HEIGHT, (GLint*)&glheight); | ||
1017 | LLGLint glcomponents = 0 ; | ||
1018 | glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_INTERNAL_FORMAT, (GLint*)&glcomponents); | ||
1019 | assert_glerror(); | ||
1020 | |||
1021 | return glwidth >= image_width && glheight >= image_height && (GL_RGB8 == glcomponents || GL_RGBA8 == glcomponents) ; | ||
1022 | } | ||
1023 | |||
988 | BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compressed_ok) | 1024 | BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compressed_ok) |
989 | { | 1025 | { |
990 | if (discard_level < 0) | 1026 | if (discard_level < 0) |
@@ -1033,12 +1069,22 @@ BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compre | |||
1033 | glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, (GLint*)&glbytes); | 1069 | glGetTexLevelParameteriv(mTarget, gl_discard, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, (GLint*)&glbytes); |
1034 | imageraw->allocateDataSize(width, height, ncomponents, glbytes); | 1070 | imageraw->allocateDataSize(width, height, ncomponents, glbytes); |
1035 | glGetCompressedTexImageARB(mTarget, gl_discard, (GLvoid*)(imageraw->getData())); | 1071 | glGetCompressedTexImageARB(mTarget, gl_discard, (GLvoid*)(imageraw->getData())); |
1072 | if(glGetError() != GL_NO_ERROR) | ||
1073 | { | ||
1074 | llwarns << "Error happens when reading back the compressed texture image." << llendl ; | ||
1075 | imageraw->deleteData() ; | ||
1076 | } | ||
1036 | stop_glerror(); | 1077 | stop_glerror(); |
1037 | } | 1078 | } |
1038 | else | 1079 | else |
1039 | { | 1080 | { |
1040 | imageraw->allocateDataSize(width, height, ncomponents); | 1081 | imageraw->allocateDataSize(width, height, ncomponents); |
1041 | glGetTexImage(GL_TEXTURE_2D, gl_discard, mFormatPrimary, mFormatType, (GLvoid*)(imageraw->getData())); | 1082 | glGetTexImage(GL_TEXTURE_2D, gl_discard, mFormatPrimary, mFormatType, (GLvoid*)(imageraw->getData())); |
1083 | if(glGetError() != GL_NO_ERROR) | ||
1084 | { | ||
1085 | llwarns << "Error happens when reading back the texture image." << llendl ; | ||
1086 | imageraw->deleteData() ; | ||
1087 | } | ||
1042 | stop_glerror(); | 1088 | stop_glerror(); |
1043 | } | 1089 | } |
1044 | 1090 | ||
@@ -1057,7 +1103,6 @@ void LLImageGL::destroyGLTexture() | |||
1057 | { | 1103 | { |
1058 | unbindTexture(i, GL_TEXTURE_2D); | 1104 | unbindTexture(i, GL_TEXTURE_2D); |
1059 | stop_glerror(); | 1105 | stop_glerror(); |
1060 | glActiveTextureARB(GL_TEXTURE0_ARB); | ||
1061 | } | 1106 | } |
1062 | } | 1107 | } |
1063 | 1108 | ||