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


C++ IDirect3DTexture9::LockRect方法代码示例

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


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

示例1: GenerateTexture

// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels.
bool GuiRenderer::GenerateTexture(Rocket::Core::TextureHandle& textureHandle, const unsigned char* source, const Rocket::Core::Vector2i& sourceDimensions)
{
	// Create a Direct3DTexture9, which will be set as the texture handle. Note that we only create one surface for
	// this texture; because we're rendering in a 2D context, mip-maps are not required.
	IDirect3DTexture9* texture;
	guiManager->getGraphicsDevice().resource->CreateTexture(sourceDimensions.x, sourceDimensions.y, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);

	// Lock the top surface and write the pixel data onto it.
	D3DLOCKED_RECT lockedRect;
	texture->LockRect(0, &lockedRect, 0, 0);
	for (int y = 0; y < sourceDimensions.y; ++y)
	{
		for (int x = 0; x < sourceDimensions.x; ++x)
		{
			const unsigned char* sourcePixel = source + (sourceDimensions.x * 4 * y) + (x * 4);
			unsigned char* destinationPixel = ((unsigned char*) lockedRect.pBits) + lockedRect.Pitch * y + x * 4;

			destinationPixel[0] = sourcePixel[2];
			destinationPixel[1] = sourcePixel[1];
			destinationPixel[2] = sourcePixel[0];
			destinationPixel[3] = sourcePixel[3];
		}
	}
	texture->UnlockRect(0);

	// Set the handle on the Rocket texture structure.
	textureHandle = (Rocket::Core::TextureHandle)texture;
	return true;
}
开发者ID:sp-alex-osou,项目名称:LuckyLeprechauns,代码行数:30,代码来源:GuiRenderer.cpp

示例2: LOGERROR

    void D3D9Blit(const IntRect& dstRect, unsigned char* src, unsigned srcStride, bool discard = false)
    {
        RECT d3dRect;

        d3dRect.left = dstRect.left_;
        d3dRect.top = dstRect.top_;
        d3dRect.right = dstRect.right_;
        d3dRect.bottom = dstRect.bottom_;

        int level = 0;
        DWORD flags = discard ? D3DLOCK_DISCARD : 0;

        D3DLOCKED_RECT d3dLockedRect;
        IDirect3DTexture9* object = (IDirect3DTexture9*) webTexture2D_->GetTexture2D()->GetGPUObject();

        if (FAILED(object->LockRect(level, &d3dLockedRect, (flags & D3DLOCK_DISCARD) ? 0 : &d3dRect, flags)))
        {
            LOGERROR("WebTexture2D - Could not lock texture");
            return;
        }

        int width = dstRect.Width();
        int height = dstRect.Height();

        for (int j = 0; j < height; ++j)
        {
            unsigned char* dst = (unsigned char*) d3dLockedRect.pBits + j * d3dLockedRect.Pitch;
            memcpy(dst, src, width * 4);
            src += srcStride;
        }

        object->UnlockRect(level);
    }
开发者ID:AliAkbarMontazeri,项目名称:AtomicGameEngine,代码行数:33,代码来源:WebTexture2D.cpp

示例3: MFTexture_CreatePlatformSpecific

// interface functions
void MFTexture_CreatePlatformSpecific(MFTexture *pTexture, bool generateMipChain)
{
	MFCALLSTACK;

	HRESULT hr;
	MFTextureTemplateData *pTemplate = pTexture->pTemplateData;

	// create texture
	D3DFORMAT platformFormat = (D3DFORMAT)MFTexture_GetPlatformFormatID(pTemplate->imageFormat, MFDD_D3D9);
	hr = D3DXCreateTexture(pd3dDevice, pTemplate->pSurfaces[0].width, pTemplate->pSurfaces[0].height, generateMipChain ? 0 : 1, 0, platformFormat, D3DPOOL_MANAGED, (IDirect3DTexture9**)&pTexture->pInternalData);

	MFDebug_Assert(hr != D3DERR_NOTAVAILABLE, MFStr("LoadTexture failed: D3DERR_NOTAVAILABLE, 0x%08X", hr));
	MFDebug_Assert(hr != D3DERR_OUTOFVIDEOMEMORY, MFStr("LoadTexture failed: D3DERR_OUTOFVIDEOMEMORY, 0x%08X", hr));
	MFDebug_Assert(hr != D3DERR_INVALIDCALL, MFStr("LoadTexture failed: D3DERR_INVALIDCALL, 0x%08X", hr));
	MFDebug_Assert(hr != D3DXERR_INVALIDDATA, MFStr("LoadTexture failed: D3DXERR_INVALIDDATA, 0x%08X", hr));

	MFDebug_Assert(hr == D3D_OK, MFStr("Failed to create texture '%s'.", pTexture->name));

	IDirect3DTexture9 *pTex = (IDirect3DTexture9*)pTexture->pInternalData;

	// copy image data
	D3DLOCKED_RECT rect;
	pTex->LockRect(0, &rect, NULL, 0);
	MFCopyMemory(rect.pBits, pTemplate->pSurfaces[0].pImageData, pTemplate->pSurfaces[0].bufferLength);
	pTex->UnlockRect(0);

	// filter mip levels
	if(generateMipChain)
		D3DXFilterTexture(pTex, NULL, 0, D3DX_DEFAULT);
}
开发者ID:jacob-carlborg,项目名称:fuji,代码行数:31,代码来源:MFTexture_D3D9.cpp

示例4: assert

static IDirect3DTexture9 *BindFont(IDirect3DDevice9 *_Dev, const CTexFont *_Font)
{
    assert(_Font!=NULL);

    IDirect3DTexture9 *Tex = NULL;
    IDirect3DDevice9Ex *D3DDev9Ex = NULL;
    bool IsD3DDev9Ex = SUCCEEDED(_Dev->QueryInterface(__uuidof(IDirect3DDevice9Ex), (void **)&D3DDev9Ex)) && D3DDev9Ex != NULL;
    HRESULT hr;
    if (IsD3DDev9Ex)
    {
        hr = _Dev->CreateTexture(_Font->m_TexWidth, _Font->m_TexHeight, 1, 	D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &Tex, NULL);
        D3DDev9Ex->Release();
    }
    else
        hr = _Dev->CreateTexture(_Font->m_TexWidth, _Font->m_TexHeight, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &Tex, NULL);
    if( FAILED(hr) )
        return NULL;

    D3DLOCKED_RECT r;
    hr = Tex->LockRect(0, &r, NULL, 0);
    if( SUCCEEDED(hr) )
    {
        color32 *p = static_cast<color32 *>(r.pBits);
        for( int i=0; i<_Font->m_TexWidth*_Font->m_TexHeight; ++i, ++p )
            *p = 0x00ffffff | (((color32)(_Font->m_TexBytes[i]))<<24);
        Tex->UnlockRect(0);
    }
    return Tex;
}
开发者ID:THE-FYP,项目名称:LiteAntTweakBar,代码行数:29,代码来源:TwDirect3D9.cpp

示例5: LoadImage

void LoadImage(char *buf, int sizeBuf, int &width, int &height, uint8 ** ppBuffer, bool bAlpha)
{
#ifdef USE_DIRECTX_RENDERER
	HRESULT hr;
	D3DSURFACE_DESC desc;
	IDirect3DTexture9* pTexture = NULL;

	D3DFORMAT d3dFormat;
	if (bAlpha)
		d3dFormat = D3DFMT_A8R8G8B8;
	else
		d3dFormat = D3DFMT_R8G8B8;
	
	// read from file
	hr = D3DXCreateTextureFromFileInMemoryEx( CGlobals::GetRenderDevice(), buf, sizeBuf,
		0, 0, 1, 0, 
		d3dFormat, D3DPOOL_SCRATCH, 
		D3DX_FILTER_NONE, D3DX_FILTER_NONE,
		0, NULL, NULL, &pTexture );
	if( FAILED(hr) )
		return;

	pTexture->GetLevelDesc( 0, &desc ); 

	// set size
	width = desc.Width;
	height = desc.Height;

	uint8 *pBufferTemp;
	int nSize;
	if (bAlpha)
		nSize = width * height * 4;
	else
		nSize = width * height * 3;
	pBufferTemp = new uint8[nSize];

	D3DLOCKED_RECT lockedRect;

	hr = pTexture->LockRect( 0, &lockedRect, NULL, D3DLOCK_READONLY );
	if( SUCCEEDED(hr) )
	{
		uint8 *pImagePixels = (uint8 *) lockedRect.pBits;
		memcpy(pBufferTemp, pImagePixels, nSize);
		//
		*ppBuffer = pBufferTemp;
		pTexture->UnlockRect( 0 );
	}
	else
	{
		width = 0;
		height = 0;
		*ppBuffer = NULL;
	}

	SAFE_RELEASE( pTexture );
#endif
}
开发者ID:LiXizhi,项目名称:NPLRuntime,代码行数:57,代码来源:Loader.cpp

示例6: initialize

void Console::initialize(IDirect3DDevice9* device, int w, int h) {
	SDLOG(0, "Initializing Console on device %p\n", device);
	width = w;
	height = h;
	this->device = device;
	
	// Create font
	SDLOG(2, " - creating console font\n");
	SAFERELEASE(fontTex);
	FILE* ff = fopen(getAssetFileName("font.ttf").c_str(), "rb");
	unsigned char* ttf_buffer = new unsigned char[1<<20];
	unsigned char* temp_bitmap = new unsigned char[BMPSIZE*BMPSIZE];
	fread(ttf_buffer, 1, 1<<20, ff);
	fclose(ff);
	stbtt_BakeFontBitmap(ttf_buffer, 0, 40.0, temp_bitmap, BMPSIZE, BMPSIZE, 32, 96, cdata); // no guarantee this fits!
	device->CreateTexture(BMPSIZE, BMPSIZE, 0, D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8, D3DPOOL_DEFAULT, &fontTex, NULL);
	IDirect3DTexture9 *tempTex;
	device->CreateTexture(BMPSIZE, BMPSIZE, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8, D3DPOOL_SYSTEMMEM, &tempTex, NULL);
	D3DLOCKED_RECT rect;
	tempTex->LockRect(0, &rect, NULL, 0);
	memcpy(rect.pBits, temp_bitmap, BMPSIZE*BMPSIZE);
	tempTex->UnlockRect(0);
	device->UpdateTexture(tempTex, fontTex);
	tempTex->Release();
	delete ttf_buffer;
	delete temp_bitmap;
	
	// Create vertex decl
	SDLOG(2, " - creating console vertex decl\n");
	SAFERELEASE(vertexDeclaration);
	device->CreateVertexDeclaration(vertexElements , &vertexDeclaration);

	// Load effect from file
	SDLOG(2, " - loading console effect file\n");
	SAFERELEASE(effect);
	vector<D3DXMACRO> defines;
	std::stringstream s;
	D3DXMACRO null = { NULL, NULL };
	defines.push_back(null);
	DWORD flags = D3DXFX_NOT_CLONEABLE | D3DXSHADER_OPTIMIZATION_LEVEL3;

	SDLOG(2, " - actually load effect\n");	
	ID3DXBuffer* errors;
	HRESULT hr = D3DXCreateEffectFromFile(device, getAssetFileName("console.fx").c_str(), &defines.front(), NULL, flags, NULL, &effect, &errors);
	if(hr != D3D_OK) SDLOG(0, "ERRORS:\n %s\n", errors->GetBufferPointer());

	// get handles
	rectColorHandle = effect->GetParameterByName(NULL, "rectColor");
	textTex2DHandle = effect->GetParameterByName(NULL, "textTex2D");

	SDLOG(0, " - done\n");
}
开发者ID:Baboonanza,项目名称:gedosato,代码行数:52,代码来源:console.cpp

示例7: int

void RageDisplay_D3D::UpdateTexture( 
	unsigned uTexHandle, 
	RageSurface* img,
	int xoffset, int yoffset, int width, int height )
{
	IDirect3DTexture9* pTex = (IDirect3DTexture9*)uTexHandle;
	ASSERT( pTex != NULL );
	
	RECT rect; 
	rect.left = xoffset;
	rect.top = yoffset;
	rect.right = width - xoffset;
	rect.bottom = height - yoffset;

	D3DLOCKED_RECT lr;
	pTex->LockRect( 0, &lr, &rect, 0 );
	
	D3DSURFACE_DESC desc;
	pTex->GetLevelDesc(0, &desc);
	ASSERT( xoffset+width <= int(desc.Width) );
	ASSERT( yoffset+height <= int(desc.Height) );

	//
	// Copy bits
	//
#if defined(XBOX)
	// Xbox textures need to be swizzled
	XGSwizzleRect(
		img->pixels,	// pSource, 
		img->pitch,		// Pitch,
		NULL,	// pRect,
		lr.pBits,	// pDest,
		img->w,	// Width,
		img->h,	// Height,
		NULL,	// pPoint,
		img->format->BytesPerPixel ); //BytesPerPixel
#else
	int texpixfmt;
	for(texpixfmt = 0; texpixfmt < NUM_PIX_FORMATS; ++texpixfmt)
		if(D3DFORMATS[texpixfmt] == desc.Format) break;
	ASSERT( texpixfmt != NUM_PIX_FORMATS );

	RageSurface *Texture = CreateSurfaceFromPixfmt(RagePixelFormat(texpixfmt), lr.pBits, width, height, lr.Pitch);
	ASSERT( Texture );
	RageSurfaceUtils::Blit( img, Texture, width, height );

	delete Texture;
#endif

	pTex->UnlockRect( 0 );
}
开发者ID:augustg,项目名称:openitg,代码行数:51,代码来源:RageDisplay_D3D.cpp

示例8: DrawARGBBitmap

void COverlayRenderer::DrawARGBBitmap(OSDTexture* pOsdTexture, const BD_ARGB_OVERLAY* pOv)
{
  CAutoLock lock(&m_csRenderLock);
  
  if (!pOsdTexture || !m_pD3DDevice || !pOv)
    return;

  if (pOv->argb)
  {
    IDirect3DTexture9* texture = NULL;

    if (m_pD3DDevice)
    {
      AdjustDirtyRect(pOv->plane, pOv->x, pOv->y, pOv->w, pOv->h);
      
      D3DLOCKED_RECT lockedRect;
    
      HRESULT hr = m_pD3DDevice->CreateTexture(pOv->w, pOv->h, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, 
                                                D3DPOOL_DEFAULT, &texture, NULL);

      if (SUCCEEDED(hr))
      {
        hr = texture->LockRect(0, &lockedRect, NULL, 0);
        if (SUCCEEDED(hr))
        {
          if (pOv->argb)
          {
            for(INT i = 0; i < pOv->h; i++)
            {
              DWORD *pDst = (DWORD*)lockedRect.pBits + (lockedRect.Pitch / 4) * i;
              DWORD *pSrc = (DWORD*)pOv->argb + i * pOv->stride;
              memcpy(pDst, pSrc, pOv->w * 4);
            }
          }
          else 
            LogDebug("ovr: DrawBitmap - pOv->argb is NULL");

          texture->UnlockRect(0);
        }
        else
          LogDebug("ovr: DrawBitmap LockRect 0x%08x", hr);

        DrawToTexture(pOsdTexture, texture, pOv->x, pOv->y, pOv->w, pOv->h);
      }
      else
        LogDebug("ovr: DrawBitmap - CreateTexture2 0x%08x", hr);
    }
  }
}
开发者ID:Azzuro,项目名称:MediaPortal-1,代码行数:49,代码来源:OverlayRenderer.cpp

示例9: LoadFromFile

HRESULT HEIGHTMAP::LoadFromFile(IDirect3DDevice9* Device, char fileName[])
{
	try
	{
		//Reset the heightMap to 0.0f
		memset(m_pHeightMap, 0, sizeof(float) * m_size.x * m_size.y);

		//Initiate the texture variables
		IDirect3DTexture9 *heightMapTexture = NULL;
		D3DXIMAGE_INFO info;

		//Load the texture (and scale it to our heightMap m_size)
		if(FAILED(D3DXCreateTextureFromFileEx(Device, fileName, m_size.x, m_size.y, 1, D3DUSAGE_DYNAMIC, 
											D3DFMT_L8, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 
											NULL, &info, NULL, &heightMapTexture)))return E_FAIL;

		//Lock the texture
		D3DLOCKED_RECT sRect;
		heightMapTexture->LockRect(0, &sRect, NULL, NULL);
		BYTE *bytes = (BYTE*)sRect.pBits;

		//Extract height values from the texture
		for(int y=0;y<m_size.y;y++)
			for(int x=0;x<m_size.x;x++)
				{
					BYTE *b = bytes + y * sRect.Pitch + x;
					m_pHeightMap[x + y * m_size.x] = (*b / 255.0f) * m_maxHeight;
				}
						
		//Unlock the texture
		heightMapTexture->UnlockRect(0);

		//Release texture
		heightMapTexture->Release();
	}
	catch(...)
	{
		debug.Print("Error in HEIGHTMAP::LoadFromFile()");
	}

	return S_OK;
}
开发者ID:Alriightyman,项目名称:RTS,代码行数:42,代码来源:heightMap.cpp

示例10: assert

static IDirect3DTexture9 *BindFont(IDirect3DDevice9 *_Dev, const CTexFont *_Font)
{
    assert(_Font!=NULL);

    IDirect3DTexture9 *Tex = NULL;
    HRESULT hr = _Dev->CreateTexture(_Font->m_TexWidth, _Font->m_TexHeight, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &Tex, NULL);
    if( FAILED(hr) )
        return NULL;

    D3DLOCKED_RECT r;
    hr = Tex->LockRect(0, &r, NULL, 0);
    if( SUCCEEDED(hr) )
    {
        color32 *p = static_cast<color32 *>(r.pBits);
        for( int i=0; i<_Font->m_TexWidth*_Font->m_TexHeight; ++i, ++p )
            *p = 0x00ffffff | (((color32)(_Font->m_TexBytes[i]))<<24);
        Tex->UnlockRect(0);
    }
    return Tex;
}
开发者ID:gaoyakun,项目名称:atom3d,代码行数:20,代码来源:TwDirect3D9.cpp

示例11: if

IDirect3DTexture9 * DXRender::createTextureFromData(unsigned int width, unsigned int height, const unsigned char * data, unsigned int sourcePitch, bool flip, unsigned int mipmapLevels)
{
	IDirect3DTexture9 * texture = NULL;
	
	if (!isDeviceReady())
		return texture;

	if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
		VASSERT(isPowerOfTwo(width) && isPowerOfTwo(height), QString_NT("Texture not POW2: %1, %2").arg(width).arg(height));

	HRESULT hr = dxr->device->CreateTexture(width, height, mipmapLevels, D3DUSAGE_AUTOGENMIPMAP | D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL);
	if (hr != D3D_OK)
	{
		VASSERT(D3D_OK == hr, QString_NT("Failed to create texture: hr = %1, width = %2, height = %3, mipmapLevels = %4").arg(hr).arg(width).arg(height).arg(mipmapLevels));
		return NULL;
	}
	
	D3DLOCKED_RECT lockedRect = {0};
	hr = texture->LockRect(0, &lockedRect, NULL, 0);
	VASSERT(D3D_OK == hr, QString_NT("Could not lock texture: hr = %1").arg(hr));

	if (width * 4 == lockedRect.Pitch && lockedRect.Pitch == sourcePitch && !flip)
		memcpy(lockedRect.pBits, data, width * height * 4);
	else if (flip)
	{
		for (unsigned int i = 0; i < height; i++)
			memcpy((char *)lockedRect.pBits + (height - 1 - i) * lockedRect.Pitch, data + sourcePitch * i, sourcePitch);
	}
	else
	{
		for (unsigned int i = 0; i < height; i++)
			memcpy((char *)lockedRect.pBits + i * lockedRect.Pitch, data + sourcePitch * i, sourcePitch);
	}

	hr = texture->UnlockRect(0);
	VASSERT(D3D_OK == hr, QString_NT("Could not unlock texture: hr = %1").arg(hr));

	return texture;
}
开发者ID:DX94,项目名称:BumpTop,代码行数:39,代码来源:BT_DXRender.cpp

示例12: Texture_Init_Failure

  IDirect3DTexture9 * Texture_DX9::build_from_Image(const Image &image) {
    Video_DX9 &vdx = dynamic_cast<Video_DX9 &>(get_Video());

    IDirect3DTexture9 * ppTexture;

    D3DFORMAT format;
    switch(image.color_space()) {
      case Image::Luminance:
        format = D3DFMT_L8;
        break;

      case Image::Luminance_Alpha:
        format = D3DFMT_A8B8G8R8;
        break;

      case Image::RGB:
        format = D3DFMT_A8B8G8R8;
        break;

      case Image::RGBA:
        format = D3DFMT_A8B8G8R8;
        break;

      default:
        format = D3DFMT_UNKNOWN;
        abort();
    }

    set_sampler_states();

    if(FAILED(Video_DX9::D3DXCreateTexture()(vdx.get_d3d_device(),
                                             UINT(image.width()), UINT(image.height()),
                                             D3DX_DEFAULT,
                                             0,
                                             format,
                                             D3DPOOL_MANAGED,
                                             &ppTexture)))
      throw Texture_Init_Failure();

    D3DLOCKED_RECT rect;
    if(FAILED(ppTexture->LockRect(0, &rect, 0, 0))) {
      ppTexture->Release();
      throw Texture_Init_Failure();
    }

    if(image.color_space() == Image::Luminance) {
      memcpy(rect.pBits, image.get_data(), image.width() * image.height());
    }
    else if(image.color_space() == Image::Luminance_Alpha) {
      Uint8 * dest = reinterpret_cast<Uint8 *>(rect.pBits);
      const Uint8 * src = image.get_data();
      for(Uint8 * const dest_end = dest + image.width() * image.height() * 4; dest != dest_end; dest += 4, src += 2) {
        dest[0] = src[0];
        dest[1] = src[0];
        dest[2] = src[0];
        dest[3] = src[1];
      }
    }
    else if(image.color_space() == Image::RGB) {
      Uint8 * dest = reinterpret_cast<Uint8 *>(rect.pBits);
      const Uint8 * src = image.get_data();
      for(Uint8 * const dest_end = dest + image.width() * image.height() * 4; dest != dest_end; dest += 4, src += 3) {
        dest[0] = src[2];
        dest[1] = src[1];
        dest[2] = src[0];
        dest[3] = 0xFF;
      }
    }
    else /*if(image.color_space() == Image::RGBA)*/ {
      Uint8 * dest = reinterpret_cast<Uint8 *>(rect.pBits);
      const Uint8 * src = image.get_data();
      for(Uint8 * const dest_end = dest + image.width() * image.height() * 4; dest != dest_end; dest += 4, src += 4) {
        dest[0] = src[2];
        dest[1] = src[1];
        dest[2] = src[0];
        dest[3] = src[3];
      }
    }

    if(FAILED(ppTexture->UnlockRect(0))) {
      ppTexture->Release();
      throw Texture_Init_Failure();
    }

    if(FAILED(Video_DX9::D3DXFilterTexture()(ppTexture, 0, D3DX_DEFAULT, D3DX_DEFAULT))) {
      ppTexture->Release();
      throw Texture_Init_Failure();
    }

    return ppTexture;
  }
开发者ID:ccharri,项目名称:EECS494-Assignment3,代码行数:91,代码来源:Texture.cpp

示例13: MFTexture_Update

MF_API bool MFTexture_Update(MFTexture *pTexture, int element, int mipLevel, const void *pData, size_t lineStride, size_t sliceStride)
{
	int numFaces = pTexture->type == MFTexType_Cubemap ? 6 : 1;
	MFDebug_Assert(element < numFaces, "Array textures not supported in D3D9!");

	int s = mipLevel*pTexture->numElements + (element > -1 ? element : 0);
	MFTextureSurface &surface = pTexture->pSurfaces[s];

	DWORD lockFlags = (pTexture->createFlags & MFTCF_TypeMask) == MFTCF_Scratch ? D3DLOCK_DISCARD : 0;

	size_t lineBytes = (surface.bitsPerPixel * surface.width) / 8;
	if(lineStride == 0)
		lineStride = lineBytes;
	if(sliceStride == 0)
		sliceStride = lineStride * surface.width;

	switch(pTexture->type)
	{
		case MFTexType_1D:
		{
			IDirect3DTexture9 *pTex = (IDirect3DTexture9*)pTexture->pInternalData;

#if defined(MF_DEBUG)
			D3DSURFACE_DESC desc;
			pTex->GetLevelDesc(mipLevel, &desc);
			MFDebug_Assert((int)desc.Width == surface.width && (int)desc.Height == surface.height, "D3D9 mip dimensions don't match the texture template data...");
#endif

			D3DLOCKED_RECT rect;
			pTex->LockRect(mipLevel, &rect, NULL, lockFlags);
			MFCopyMemory(rect.pBits, pData, lineBytes);
			pTex->UnlockRect(mipLevel);
			break;
		}
		case MFTexType_2D:
		{
			IDirect3DTexture9 *pTex = (IDirect3DTexture9*)pTexture->pInternalData;

#if defined(MF_DEBUG)
			D3DSURFACE_DESC desc;
			pTex->GetLevelDesc(mipLevel, &desc);
			MFDebug_Assert((int)desc.Width == surface.width && (int)desc.Height == surface.height, "D3D9 mip dimensions don't match the texture template data...");
#endif

			D3DLOCKED_RECT rect;
			pTex->LockRect(mipLevel, &rect, NULL, lockFlags);

			const char *pSrc = (const char*)pData;
			char *pDest = (char*)rect.pBits;
			for(int i=0; i<surface.height; ++i)
			{
				MFCopyMemory(pDest, pSrc, lineBytes);
				pDest += rect.Pitch;
				pSrc += lineStride;
			}

			pTex->UnlockRect(mipLevel);
			break;
		}
		case MFTexType_3D:
		{
			IDirect3DVolumeTexture9 *pTex = (IDirect3DVolumeTexture9*)pTexture->pInternalData;

#if defined(MF_DEBUG)
			D3DVOLUME_DESC desc;
			pTex->GetLevelDesc(mipLevel, &desc);
			MFDebug_Assert((int)desc.Width == surface.width && (int)desc.Height == surface.height && (int)desc.Depth == surface.depth, "D3D9 mip dimensions don't match the texture template data...");
#endif

			D3DLOCKED_BOX box;
			pTex->LockBox(mipLevel, &box, NULL, lockFlags);
			MFCopyMemory(box.pBits, pData, surface.bufferLength);

			const char *pSrcSlice = (const char*)pData;
			char *pDestSlice = (char*)box.pBits;
			for(int d=0; d<surface.depth; ++d)
			{
				const char *pSrcLine = pSrcSlice;
				char *pDestLine = pDestSlice;
				for(int i=0; i<surface.height; ++i)
				{
					MFCopyMemory(pDestLine, pSrcLine, lineBytes);
					pDestLine += box.RowPitch;
					pSrcLine += lineStride;
				}
				pSrcSlice += sliceStride;
				pDestSlice += box.SlicePitch;
			}

			pTex->UnlockBox(mipLevel);
			break;
		}
		case MFTexType_Cubemap:
		{
			MFDebug_Assert(element != -1, "TODO: must handle setting all surfaces at once...");

			IDirect3DCubeTexture9 *pTex = (IDirect3DCubeTexture9*)pTexture->pInternalData;

#if defined(MF_DEBUG)
			D3DSURFACE_DESC desc;
//.........这里部分代码省略.........
开发者ID:TurkeyMan,项目名称:fuji,代码行数:101,代码来源:MFTexture_D3D9.cpp

示例14: ConvertImageFileToBMPBuffer

void ConvertImageFileToBMPBuffer(string szSrcFileName, LPBYTE * bytes, long* len)
{
	if(!FileExists(szSrcFileName))
		return;

	ATG::Timer m_Timer;

	double timeA = m_Timer.GetAbsoluteTime();

	IDirect3DTexture9 * pTexture;
	HRESULT retVal = D3DXCreateTextureFromFileEx(
		CFreestyleApp::getInstance().m_pd3dDevice,
		szSrcFileName.c_str(),
		D3DX_DEFAULT_NONPOW2,
		D3DX_DEFAULT_NONPOW2,
		1,
		D3DUSAGE_CPU_CACHED_MEMORY,
		D3DFMT_LIN_A8R8G8B8,
		D3DPOOL_DEFAULT,
		D3DX_FILTER_NONE,
		D3DX_FILTER_NONE,
		0,
		NULL,
		NULL,
		&pTexture
	);


	float timeB = m_Timer.GetAbsoluteTime();
	DebugMsg("Test", "Texture Creation:  %4.2f", (timeB- timeA));

	if(retVal == S_OK) {
		timeA = m_Timer.GetAbsoluteTime();

		// Get our level desc
		D3DSURFACE_DESC desc;
		pTexture->GetLevelDesc(0, &desc);

		// Now lock our data
		D3DLOCKED_RECT lock;
		RECT rect = {0, 0, desc.Width, desc.Height};
		pTexture->LockRect(0, &lock, &rect, D3DLOCK_READONLY);
	
		//Read our data
		DWORD headerSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
		DWORD dataLen = lock.Pitch * desc.Height;
		DWORD * dataBuffer = (DWORD*)malloc( dataLen + headerSize );
		DWORD * address = (DWORD*)lock.pBits;

		// Create file our header
		BITMAPFILEHEADER* fHead = (BITMAPFILEHEADER*)dataBuffer;
		fHead->bfType = 0x424D; // "BM"
		fHead->bfSize = SwapDWORD(dataLen + headerSize);
		fHead->bfReserved1 = 0;
		fHead->bfReserved2 = 0;
		fHead->bfOffBits = SwapDWORD(headerSize);

		// Create our info header
		BITMAPINFOHEADER* iHead = (BITMAPINFOHEADER*)(fHead + 1);
		ZeroMemory(iHead, sizeof(BITMAPINFOHEADER));
		iHead->biSize = SwapDWORD(sizeof(BITMAPINFOHEADER));
		iHead->biWidth = SwapDWORD(desc.Width);
		iHead->biHeight = SwapDWORD(desc.Height);
		iHead->biPlanes = SwapWORD(1);
		iHead->biBitCount = SwapWORD(32);
		iHead->biSizeImage = SwapDWORD(dataLen);

		// Copy over our raw (BGRA)
		DWORD* rawPtr = (DWORD*)(iHead + 1);
		for(int y = desc.Height - 1; y >= 0; y--) {
			for(DWORD x = 0; x < desc.Width; x++) {

				DWORD cp = (y * lock.Pitch) + (x * 4);
				DWORD * temp = (DWORD*)(address + (cp / 4));
				*rawPtr = SwapDWORD(*temp);				
				rawPtr++;
			}
		}
		
		// Unlock our texture
		pTexture->UnlockRect(0);

		timeB = m_Timer.GetAbsoluteTime();
		DebugMsg("Test", "Texture Lock Time:  %4.2f", (timeB- timeA));
		
		*len = (headerSize + dataLen);
		*bytes = (BYTE*)dataBuffer;
	}else {
		DebugMsg("ConvertImageInMemoryToBMPBuffer", 
			"Conversion To BMP From Memory Failed. [%X]", retVal);		
	}

	// Release our Texture
	if(pTexture != NULL)
		pTexture->Release();
}
开发者ID:DeezNuts12,项目名称:freestyledash,代码行数:96,代码来源:BMPTools.cpp

示例15: init

void RenderState::init(IDirect3DDevice9* dev) {
    _dev = dev;

    D3DDEVICE_CREATION_PARAMETERS params;
    HRESULT hr = dev->GetCreationParameters(&params);
    if (FAILED(hr)) {
        MM_LOG_INFO(format("Failed to obtain device creation parameters"));
    }
    else {
        _focusWindow = params.hFocusWindow;
    }

    // create "selected" texture
    WCHAR* dataPath = NULL;
    if (Interop::OK()) {
        IDirect3DTexture9 * tex;

        int width = 256;
        int height = 256;
        HRESULT hr = dev->CreateTexture(width, height, 1, 0,
                                        D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, 0);
        if (FAILED(hr)) {
            MM_LOG_INFO("Failed to create 'selection' texture");
        } else {
            _selectionTexture = tex;

            D3DLOCKED_RECT rect;
            hr = tex->LockRect(0, &rect, 0, D3DLOCK_DISCARD);
            if (FAILED(hr)) {
                MM_LOG_INFO("Failed to lock 'selection' texture");
            }
            else {
                unsigned char* dest = static_cast<unsigned char*>(rect.pBits);

                // fill it with a lovely shade of green
                Uint32 numEls = width * height;
                for (Uint32 i = 0; i < numEls; ++i) {
                    Uint32* d = (Uint32*)(dest + (i*sizeof(Uint32)));
                    *d = 0xFF00FF00;
                }
                //MM_LOG_INFO("filled selection texture");
                tex->UnlockRect(0);
            }
        }
    }

    // Set key bindings.  Input also assumes that CONTROL modifier is required for these as well.
    // TODO: should push this out to conf file eventually so that they can be customized without rebuild
    // If you change these, be sure to change LocStrings/ProfileText in MMLaunch!
    _punctKeyMap[DIK_BACKSLASH] = [&]() {
        this->loadMods();
    };
    _punctKeyMap[DIK_RBRACKET] = [&]() {
        this->toggleShowModMesh();
    };
    _punctKeyMap[DIK_SEMICOLON] = [&]() {
        this->clearTextureLists();
    };
    _punctKeyMap[DIK_COMMA] = [&]() {
        this->selectNextTexture();
    };
    _punctKeyMap[DIK_PERIOD] = [&]() {
        this->selectPrevTexture();
    };
    _punctKeyMap[DIK_SLASH] = [&]() {
        this->requestSnap();
    };
    _punctKeyMap[DIK_MINUS] = [&]() {
        this->loadEverything();
    };


    // If you change these, be sure to change LocStrings/ProfileText in MMLaunch!
    _fKeyMap[DIK_F1] = [&]() {
        this->loadMods();
    };
    _fKeyMap[DIK_F2] = [&]() {
        this->toggleShowModMesh();
    };
    _fKeyMap[DIK_F6] = [&]() {
        this->clearTextureLists();
    };
    _fKeyMap[DIK_F3] = [&]() {
        this->selectNextTexture();
    };
    _fKeyMap[DIK_F4] = [&]() {
        this->selectPrevTexture();
    };
    _fKeyMap[DIK_F7] = [&]() {
        this->requestSnap();
    };
    _fKeyMap[DIK_F10] = [&]() {
        this->loadEverything();
    };

    _pCurrentKeyMap = &_fKeyMap;

    if (Interop::OK()) {
        if (Interop::Conf().LoadModsOnStart) {
            loadEverything();
//.........这里部分代码省略.........
开发者ID:Tarek-Samy,项目名称:ModelMod,代码行数:101,代码来源:RenderState.cpp


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