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

Method sampleTexel

Engine/source/gfx/bitmap/gBitmap.cpp:731–765  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

729
730//------------------------------------------------------------------------------
731LinearColorF GBitmap::sampleTexel(F32 u, F32 v, bool retAlpha) const
732{
733 LinearColorF col(0.5f, 0.5f, 0.5f);
734 // normally sampling wraps all the way around at 1.0,
735 // but locking doesn't support this, and we seem to calc
736 // the uv based on a clamped 0 - 1...
737 Point2F max((F32)(getWidth()-1), (F32)(getHeight()-1));
738 Point2F posf;
739 posf.x = mClampF(((u) * max.x), 0.0f, max.x);
740 posf.y = mClampF(((v) * max.y), 0.0f, max.y);
741 Point2I posi((S32)posf.x, (S32)posf.y);
742
743 const U8 *buffer = getBits();
744 U32 lexelindex = ((posi.y * getWidth()) + posi.x) * mBytesPerPixel;
745
746 if(mBytesPerPixel == 2)
747 {
748 //U16 *buffer = (U16 *)lockrect->pBits;
749 }
750 else if(mBytesPerPixel > 2)
751 {
752 col.red = F32(buffer[lexelindex + 0]) / 255.0f;
753 col.green = F32(buffer[lexelindex + 1]) / 255.0f;
754 col.blue = F32(buffer[lexelindex + 2]) / 255.0f;
755 if (retAlpha)
756 {
757 if (getHasTransparency())
758 col.alpha = F32(buffer[lexelindex + 3]) / 255.0f;
759 else
760 col.alpha = 1.0f;
761 }
762 }
763
764 return col;
765}
766
767//--------------------------------------------------------------------------
768bool GBitmap::getColor(const U32 x, const U32 y, ColorI& rColor) const

Callers 4

getColorFromRayInfoMethod · 0.80
_generateCellMethod · 0.80
sampleSideFunction · 0.80

Calls 3

getWidthFunction · 0.85
mClampFFunction · 0.85
getHeightFunction · 0.50

Tested by

no test coverage detected