当前位置: 首页>>代码示例>>C++>>正文


C++ HardwarePixelBufferSharedPtr::getSizeInBytes方法代码示例

本文整理汇总了C++中HardwarePixelBufferSharedPtr::getSizeInBytes方法的典型用法代码示例。如果您正苦于以下问题:C++ HardwarePixelBufferSharedPtr::getSizeInBytes方法的具体用法?C++ HardwarePixelBufferSharedPtr::getSizeInBytes怎么用?C++ HardwarePixelBufferSharedPtr::getSizeInBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HardwarePixelBufferSharedPtr的用法示例。


在下文中一共展示了HardwarePixelBufferSharedPtr::getSizeInBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getTerrain

	Terrain* SnowTerrain::getTerrain()
	{
		if(!mTerrainGroup) return NULL;

		Terrain *t =  mTerrainGroup->getTerrain(0,0);
		return t;

		TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
		while (ti.hasMoreElements())
		{
			Ogre::uint32 tkey = ti.peekNextKey();
			TerrainGroup::TerrainSlot* ts = ti.getNext();
			if (ts->instance && ts->instance->isLoaded())
			{

				float* heights = ts->instance->getHeightData();

				//PixelBox* pBox = ts->instance->calculateNormals());
				TexturePtr texturePtr = ts->instance->getTerrainNormalMap();
				HardwarePixelBufferSharedPtr buf = texturePtr->getBuffer();

				size_t bytes = buf->getSizeInBytes();
				size_t h = buf->getHeight();
				size_t w = buf->getWidth();
				size_t d = buf->getDepth();
				PixelFormat f = PF_BYTE_RGB;//buf->getFormat();


				uint8* tmpData = (uint8*)OGRE_MALLOC(w * h * 3, MEMCATEGORY_GENERAL);
				memset(tmpData,0,w*h*3);
				PixelBox pBox(w, h, d, f, tmpData);
				buf->blitToMemory(pBox);
				OGRE_FREE(tmpData, MEMCATEGORY_GENERAL);
				
			}
		}
		return NULL;
	}
开发者ID:pranavsureshpn,项目名称:gpusphsim,代码行数:38,代码来源:SnowTerrain.cpp

示例2: updateTextureFromSegmentedLists

//------------------------------------------------------------------------------
void SegmentedDynamicLightManager::updateTextureFromSegmentedLists(const Camera* i_pCamera)
{
	float spotIntensity = 1;
		
	HardwarePixelBufferSharedPtr pBuf = mLightTexture->getBuffer();
	void* pStartPos = pBuf->lock(HardwareBuffer::HBL_DISCARD);
	uint16* pData = (uint16*)pStartPos;

	size_t remainBufWidth = mTextureWidth;
	for(size_t j = 0; j < SDL_SEGMENT_GRID_SIZE; ++j)
	{
		//assign first row with number of indexes in the block
		float maxRow = (float)(mSegmentedLightGrid[j].size() - 1 + SDL_TEXTURE_DATA_ROWS);
		PixelUtil::packColour(maxRow,0.0f,0.0f,0.0f,PF_FLOAT16_RGBA, pData);
		pData += 4 * SDL_LIGHT_DATA_SIZE; 		
		remainBufWidth -= SDL_LIGHT_DATA_SIZE;
	}

	//advance the remaining space of the row 
	pData += 4 * remainBufWidth; 		
		
	for(size_t i = 0 ; i < SDL_LIGHT_PER_BLOCK ; ++i)
	{
		remainBufWidth = mTextureWidth;
		for(size_t j = 0; j < SDL_SEGMENT_GRID_SIZE; ++j)
		{
			if (i < mSegmentedLightGrid[j].size())
			{
				const Light* pLight = mSegmentedLightGrid[j][i];
					
				const Vector3& position = pLight->getDerivedPosition(true);
				Vector3 direction = -pLight->getDerivedDirection();
				direction.normalise();

				// Update spotlight parameters.
				Vector3 spotParam;
				float inverseRange = 1.0f / (float)pLight->getAttenuationRange();
				float spotAngle = -1;
				float spotInvAngleRange = std::numeric_limits<float>::max();
				if (pLight->getType() == Light::LT_SPOTLIGHT)
				{
					Real phi   = Math::Cos(pLight->getSpotlightOuterAngle().valueRadians() * 0.5f);
					Real theta = Math::Cos(pLight->getSpotlightInnerAngle().valueRadians() * 0.5f);
					spotAngle = (float)phi;
					spotInvAngleRange = 1.0f / (float)(theta - phi);
				}
					
				PixelUtil::packColour(
					(float)position.x,
					(float)position.y,
					(float)position.z,
					inverseRange,
					PF_FLOAT16_RGBA, pData);
				pData += 4; 		

				PixelUtil::packColour(
					(float)direction.x,
					(float)direction.y,
					(float)direction.z,
					spotAngle,
					PF_FLOAT16_RGBA, pData);
				pData += 4; 

				PixelUtil::packColour(
					pLight->getDiffuseColour().r * spotIntensity,
					pLight->getDiffuseColour().g * spotIntensity,
					pLight->getDiffuseColour().b * spotIntensity,
					spotInvAngleRange,
					PF_FLOAT16_RGBA, pData);
				pData += 4; 		

			}
			else
			{
				//assign position zero with zero width
				PixelUtil::packColour(0.0f,0.0f,0.0f,std::numeric_limits<float>::max(),
					PF_FLOAT16_RGBA, pData);
				pData += 4; 		
				for(int d = 0 ; d < (SDL_LIGHT_DATA_SIZE - 1) ; ++d)
				{
					PixelUtil::packColour(0.0f,0.0f,0.0f,0.0f,PF_FLOAT16_RGBA, pData);
					pData += 4; 		
				}
			}
			remainBufWidth -= 3;
		}

		//advance the remaining space of the row 
		pData += 4 * remainBufWidth; 		
	}

	//Check for memory overrun
	if (pBuf->getSizeInBytes() != (const char*)(void*)pData - (const char*)pStartPos)
	{
		throw "memory overrun";
	}

	pBuf->unlock();
}
开发者ID:sanyaade-teachings,项目名称:ogre,代码行数:100,代码来源:SegmentedDynamicLightManager.cpp

示例3: WriteToTexture

void WriteToTexture(const String &str, TexturePtr destTexture, Image::Box destRectangle, Font* font, const ColourValue &color, char justify,  bool wordwrap)
{
    using namespace Ogre;

    if (destTexture->getHeight() < destRectangle.bottom)
        destRectangle.bottom = destTexture->getHeight();
    if (destTexture->getWidth() < destRectangle.right)
        destRectangle.right = destTexture->getWidth();

    if (!font->isLoaded())
        font->load();

    TexturePtr fontTexture = (TexturePtr) TextureManager::getSingleton().getByName(font->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName());

    HardwarePixelBufferSharedPtr fontBuffer = fontTexture->getBuffer();
    HardwarePixelBufferSharedPtr destBuffer = destTexture->getBuffer();

    PixelBox destPb = destBuffer->lock(destRectangle,HardwareBuffer::HBL_NORMAL);

    // The font texture buffer was created write only...so we cannot read it back :o). One solution is to copy the buffer  instead of locking it. (Maybe there is a way to create a font texture which is not write_only ?)

    // create a buffer
    size_t nBuffSize = fontBuffer->getSizeInBytes();
    unsigned char* buffer = (unsigned char*)calloc(nBuffSize, sizeof(unsigned char));

    // create pixel box using the copy of the buffer
    PixelBox fontPb(fontBuffer->getWidth(), fontBuffer->getHeight(),fontBuffer->getDepth(), fontBuffer->getFormat(), buffer);
    fontBuffer->blitToMemory(fontPb);

    unsigned char* fontData = static_cast<unsigned char*>( fontPb.data );
    unsigned char* destData = static_cast<unsigned char*>( destPb.data );

    const size_t fontPixelSize = PixelUtil::getNumElemBytes(fontPb.format);
    const size_t destPixelSize = PixelUtil::getNumElemBytes(destPb.format);

    const size_t fontRowPitchBytes = fontPb.rowPitch * fontPixelSize;
    const size_t destRowPitchBytes = destPb.rowPitch * destPixelSize;

    Box *GlyphTexCoords;
    GlyphTexCoords = new Box[str.size()];

    Font::UVRect glypheTexRect;
    size_t charheight = 0;
    size_t charwidth = 0;

    for (unsigned int i = 0; i < str.size(); i++)
    {
        if ((str[i] != '\t') && (str[i] != '\n') && (str[i] != ' '))
        {
            glypheTexRect = font->getGlyphTexCoords(str[i]);
            GlyphTexCoords[i].left = glypheTexRect.left * fontTexture->getSrcWidth();
            GlyphTexCoords[i].top = glypheTexRect.top * fontTexture->getSrcHeight();
            GlyphTexCoords[i].right = glypheTexRect.right * fontTexture->getSrcWidth();
            GlyphTexCoords[i].bottom = glypheTexRect.bottom * fontTexture->getSrcHeight();

            if (GlyphTexCoords[i].getHeight() > charheight)
                charheight = GlyphTexCoords[i].getHeight();
            if (GlyphTexCoords[i].getWidth() > charwidth)
                charwidth = GlyphTexCoords[i].getWidth();
        }

    }

    size_t cursorX = 0;
    size_t cursorY = 0;
    size_t lineend = destRectangle.getWidth();
    bool carriagreturn = true;
    for (unsigned int strindex = 0; strindex < str.size(); strindex++)
    {
        switch(str[strindex])
        {
        case ' ':
            cursorX += charwidth;
            break;
        case '\t':
            cursorX += charwidth * 3;
            break;
        case '\n':
            cursorY += charheight;
            carriagreturn = true;
            break;
        default:
        {
            //wrapping
            if ((cursorX + GlyphTexCoords[strindex].getWidth()> lineend) && !carriagreturn )
            {
                cursorY += charheight;
                carriagreturn = true;
            }

            //justify
            if (carriagreturn)
            {
                size_t l = strindex;
                size_t textwidth = 0;
                size_t wordwidth = 0;

                while( (l < str.size() ) && (str[l] != '\n'))
                {
                    wordwidth = 0;
//.........这里部分代码省略.........
开发者ID:TheLonetrucker,项目名称:rigs-of-rods,代码行数:101,代码来源:WriteTextToTexture.cpp


注:本文中的HardwarePixelBufferSharedPtr::getSizeInBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。