MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / copyToBmp

Method copyToBmp

Engine/source/gfx/gl/gfxGLTextureObject.cpp:153–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151}
152
153bool GFXGLTextureObject::copyToBmp(GBitmap * bmp)
154{
155 if (!bmp)
156 return false;
157
158 // check format limitations
159 // at the moment we only support RGBA for the source (other 4 byte formats should
160 // be easy to add though)
161 AssertFatal(mFormat == GFXFormatR16G16B16A16F || mFormat == GFXFormatR8G8B8A8 || mFormat == GFXFormatR8G8B8A8_LINEAR_FORCE || mFormat == GFXFormatR8G8B8A8_SRGB, "copyToBmp: invalid format");
162 if (mFormat != GFXFormatR16G16B16A16F && mFormat != GFXFormatR8G8B8A8 && mFormat != GFXFormatR8G8B8A8_LINEAR_FORCE && mFormat != GFXFormatR8G8B8A8_SRGB)
163 return false;
164
165 AssertFatal(bmp->getWidth() == getWidth(), avar("GFXGLTextureObject::copyToBmp - Width mismatch: %i vs %i", bmp->getWidth(), getWidth()));
166 AssertFatal(bmp->getHeight() == getHeight(), avar("GFXGLTextureObject::copyToBmp - Height mismatch: %i vs %i", bmp->getHeight(), getHeight()));
167
168 PROFILE_SCOPE(GFXGLTextureObject_copyToBmp);
169
170 PRESERVE_TEXTURE(mBinding);
171 glBindTexture(mBinding, mHandle);
172
173 U8 dstBytesPerPixel = GFXFormat_getByteSize( bmp->getFormat() );
174 U8 srcBytesPerPixel = GFXFormat_getByteSize( mFormat );
175
176 FrameAllocatorMarker mem;
177
178
179 U32 mipLevels = getMipLevels();
180 for (U32 mip = 0; mip < mipLevels; mip++)
181 {
182 U32 srcPixelCount = bmp->getSurfaceSize(mip)/ srcBytesPerPixel;
183
184 U8* dest = bmp->getWritableBits(mip);
185 U8* orig = (U8*)mem.alloc(srcPixelCount * srcBytesPerPixel);
186
187 glGetTexImage(mBinding, mip, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], orig);
188 if (mFormat == GFXFormatR16G16B16A16F)
189 {
190 dMemcpy(dest, orig, srcPixelCount * srcBytesPerPixel);
191 }
192 else
193 {
194 for (int i = 0; i < srcPixelCount; ++i)
195 {
196 dest[0] = orig[0];
197 dest[1] = orig[1];
198 dest[2] = orig[2];
199 if (dstBytesPerPixel == 4)
200 dest[3] = orig[3];
201
202 orig += srcBytesPerPixel;
203 dest += dstBytesPerPixel;
204 }
205 }
206 }
207 glBindTexture(mBinding, NULL);
208
209 return true;
210}

Callers 5

_updateBaseTextureMethod · 0.45
saveFunction · 0.45
onRenderMethod · 0.45
onMouseDownMethod · 0.45
_renderToTextureMethod · 0.45

Calls 11

getWidthFunction · 0.85
avarFunction · 0.85
GFXFormat_getByteSizeFunction · 0.85
getWritableBitsMethod · 0.80
getHeightFunction · 0.50
dMemcpyFunction · 0.50
getWidthMethod · 0.45
getHeightMethod · 0.45
getFormatMethod · 0.45
getSurfaceSizeMethod · 0.45
allocMethod · 0.45

Tested by

no test coverage detected