| 139 | } |
| 140 | |
| 141 | bool GFXGLTextureObject::copyToBmp(GBitmap * bmp) |
| 142 | { |
| 143 | if (!bmp) |
| 144 | return false; |
| 145 | |
| 146 | // check format limitations |
| 147 | // at the moment we only support RGBA for the source (other 4 byte formats should |
| 148 | // be easy to add though) |
| 149 | AssertFatal(mFormat == GFXFormatR8G8B8A8, "GFXGLTextureObject::copyToBmp - invalid format"); |
| 150 | AssertFatal(bmp->getFormat() == GFXFormatR8G8B8A8 || bmp->getFormat() == GFXFormatR8G8B8, "GFXGLTextureObject::copyToBmp - invalid format"); |
| 151 | if(mFormat != GFXFormatR8G8B8A8) |
| 152 | return false; |
| 153 | |
| 154 | if(bmp->getFormat() != GFXFormatR8G8B8A8 && bmp->getFormat() != GFXFormatR8G8B8) |
| 155 | return false; |
| 156 | |
| 157 | AssertFatal(bmp->getWidth() == getWidth(), "GFXGLTextureObject::copyToBmp - invalid size"); |
| 158 | AssertFatal(bmp->getHeight() == getHeight(), "GFXGLTextureObject::copyToBmp - invalid size"); |
| 159 | |
| 160 | PROFILE_SCOPE(GFXGLTextureObject_copyToBmp); |
| 161 | |
| 162 | PRESERVE_TEXTURE(mBinding); |
| 163 | glBindTexture(mBinding, mHandle); |
| 164 | |
| 165 | U8 dstBytesPerPixel = GFXFormat_getByteSize( bmp->getFormat() ); |
| 166 | U8 srcBytesPerPixel = GFXFormat_getByteSize( mFormat ); |
| 167 | if(dstBytesPerPixel == srcBytesPerPixel) |
| 168 | { |
| 169 | glGetTexImage(mBinding, 0, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], bmp->getWritableBits()); |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | FrameAllocatorMarker mem; |
| 174 | |
| 175 | U32 srcPixelCount = mTextureSize.x * mTextureSize.y; |
| 176 | U8 *dest = bmp->getWritableBits(); |
| 177 | U8 *orig = (U8*)mem.alloc(srcPixelCount * srcBytesPerPixel); |
| 178 | |
| 179 | glGetTexImage(mBinding, 0, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], orig); |
| 180 | |
| 181 | PROFILE_START(GFXGLTextureObject_copyToBmp_pixCopy); |
| 182 | for(int i = 0; i < srcPixelCount; ++i) |
| 183 | { |
| 184 | dest[0] = orig[0]; |
| 185 | dest[1] = orig[1]; |
| 186 | dest[2] = orig[2]; |
| 187 | if(dstBytesPerPixel == 4) |
| 188 | dest[3] = orig[3]; |
| 189 | |
| 190 | orig += srcBytesPerPixel; |
| 191 | dest += dstBytesPerPixel; |
| 192 | } |
| 193 | PROFILE_END(); |
| 194 | |
| 195 | return true; |
| 196 | } |
| 197 | |
| 198 | void GFXGLTextureObject::initSamplerState(const GFXSamplerStateDesc &ssd) |
no test coverage detected