MCPcopy Create free account
hub / github.com/carbonengine/trinity / CopyFromTexture

Method CopyFromTexture

trinity/Tr2HostBitmap.cpp:189–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

187}
188
189bool Tr2HostBitmap::CopyFromTexture( Tr2TextureAL& texture, Tr2RenderContext& renderContext )
190{
191 if( !texture.IsValid() )
192 {
193 return false;
194 }
195
196 if( texture.GetType() != TEX_TYPE_2D && texture.GetType() != TEX_TYPE_CUBE )
197 {
198 CCP_LOGERR( "Tr2HostBitmap::CopyFromTextureRes, only 2D and CUBE textures supported" );
199 return false;
200 }
201
202 bool alphaConvert = false;
203
204 if( GetType() != texture.GetType() || !CheckForMatch( texture.GetDesc(), true, alphaConvert, "CopyFromTextureRes" ) )
205 {
206 return false;
207 }
208
209 const uint32_t mipCount = std::min( GetTrueMipCount(), texture.GetTrueMipCount() );
210 const uint32_t faceCount = GetArraySize();
211
212
213 for( uint32_t face = 0; face != faceCount; ++face )
214 {
215 for( uint32_t mipLevel = 0; mipLevel != mipCount; ++mipLevel )
216 {
217 const void* srcData = nullptr;
218 uint32_t srcPitch = 0;
219
220 HRESULT hr = texture.MapForReading( Tr2TextureSubresource( face, mipLevel ), srcData, srcPitch, renderContext );
221 if( FAILED( hr ) || srcData == nullptr )
222 {
223 CCP_LOGERR( "Tr2HostBitmap::CopyFromTextureRes, error locking surface" );
224 return false;
225 }
226
227
228 uint8_t* dst = (uint8_t*)GetMipRawData( mipLevel, face );
229 const uint8_t* src = (uint8_t*)srcData;
230
231 const uint32_t dstPitch = GetMipPitch( mipLevel );
232
233 if( alphaConvert )
234 {
235 const uint32_t width = GetMipWidth( mipLevel );
236 const uint32_t height = GetMipHeight( mipLevel );
237 for( uint32_t j = 0; j != height; ++j, src += srcPitch, dst += dstPitch )
238 {
239 const uint8_t* in = src;
240 uint8_t* out = dst;
241 for( uint32_t i = 0; i != width; ++i )
242 {
243 *out++ = *in++;
244 *out++ = *in++;
245 *out++ = *in++;
246 *out++ = 0xFF;

Callers 1

PyInitFunction · 0.80

Calls 6

GetTrueMipCountMethod · 0.80
IsValidMethod · 0.45
GetTypeMethod · 0.45
MapForReadingMethod · 0.45
UnmapForReadingMethod · 0.45

Tested by

no test coverage detected