示例#1
0
Texmap  *plRTSpotLight::GetProjMap()
{
    if( !fLightPB->GetInt( kUseProjectorBool ) )
        return nil;

    Interval valid = Interval(0,0); 
    if( !GetTex() )
    {
        if( fLightPB->GetInt( kUseProjectorBool ) )
        {
            PBBitmap* bitmap = fLightPB->GetBitmap( kProjMapTexButton, 0 );         
            SetProjMap( &bitmap->bi );
        }
    }

    if( GetTex() )
    {
        const char* dbgTexName = GetTex()->GetName();

        IParamBlock2 *bitmapPB = fTex->GetParamBlockByID(plLayerTex::kBlkBitmap);
        hsAssert(bitmapPB, "LayerTex with no param block");

        int noCompress = fLightPB->GetInt(kProjNoCompress);
        int noMip = fLightPB->GetInt(kProjNoMip);
        bitmapPB->SetValue(kBmpNonCompressed, TimeValue(0), noCompress);
        bitmapPB->SetValue(kBmpNoFilter, TimeValue(0), noMip);
    }

    return (Texmap *)GetTex();
}
示例#2
0
D3DTexture::D3DTexture(D3DSystem *curSystem, CTSTR lpFile, D3DXIMAGE_INFO &imageInfo, BOOL bBuildMipMaps)
{
    traceIn(D3DTexture::D3DTexture(2));

    DWORD dwMipLevels; 
    
    if(bBuildMipMaps)
    {
        switch(imageInfo.ImageFileFormat)
        {
            case D3DXIFF_DDS:
                dwMipLevels = D3DX_FROM_FILE;
                break;

            default:
                dwMipLevels = D3DX_DEFAULT;
        }
    }
    else
        dwMipLevels = 1;

    d3d = curSystem;

    bHasMipMaps = bBuildMipMaps;
    bNeedsBlending = 0;
    mipLevel = 0;
    dwFormat = -1;
    switch(imageInfo.Format)
    {
        case D3DFMT_DXT1:       dwFormat = GS_DXT1; break;
        case D3DFMT_DXT3:       dwFormat = GS_DXT3; break;
        case D3DFMT_DXT5:       dwFormat = GS_DXT5; break;
        case D3DFMT_R8G8B8:     dwFormat = GS_RGB;  break;
        case D3DFMT_A8R8G8B8:   dwFormat = GS_RGBA;
    }

    bDynamic = FALSE;
    dwTexType = D3DTEXTURE_STANDARD_BUFFER;

    DWORD dwDefaultSize = bBuildMipMaps ? D3DX_DEFAULT : D3DX_DEFAULT_NONPOW2;

    //D3DXCreateTextureFromFile(d3d->d3dDevice, lpFile, &d3dTex);

    if(!SUCCEEDED(D3DXCreateTextureFromFileEx(d3d->d3dDevice,
                                   lpFile,
                                   dwDefaultSize, dwDefaultSize,
                                   dwMipLevels,
                                   0, D3DFMT_FROM_FILE, D3DPOOL_MANAGED,
                                   D3DX_FILTER_NONE, D3DX_DEFAULT, 
                                   0, NULL, NULL, &GetTex())))
        ErrOut(TEXT("Could not load file %s"), lpFile);

    D3DSURFACE_DESC sDesc;
    GetTex()->GetLevelDesc(0, &sDesc);

    texWidth = sDesc.Width;
    texHeight = sDesc.Height;

    traceOut;
}
示例#3
0
static int SetTex( int sel, short mode, short opt, short sx, short sy, short width, short height, GLuint texid )
{
	//		TEXINFを設定する
	//
	TEXINF *t;
	int myid;
	myid = sel;
	if ( sel >= 0 ) {
		t = GetTex( sel );
	} else {
		myid = GetNextTex();
		if ( myid < 0 ) return myid;
		t = GetTex( myid );
	}
	t->mode = mode;
	t->opt = opt;
	t->sx = sx;
	t->sy = sy;
	t->width = width;
	t->height = height;
	t->ratex = 1.0f / (float)sx;
	t->ratey = 1.0f / (float)sy;
	t->texid = (int)texid;
	t->hash = 0;
	t->life = TEXMES_CACHE_DEFAULT;
	t->text = NULL;
	return myid;
}
示例#4
0
BOOL D3DTexture::GetRenderTargetImage(OffscreenSurface *destination)
{
    if(dwTexType != D3DTEXTURE_FRAME_BUFFER)
    {
        AppWarning(TEXT("D3DTexture::GetRenderTargetImage can only be used with a render target"));
        return FALSE;
    }

    if(!destination)
        return FALSE;

    IDirect3DSurface9 *RenderSurface=NULL;
    BOOL bSuccess=FALSE;
    D3DOffscreenSurface *oss = static_cast<D3DOffscreenSurface*>(destination);

    if(oss->bLocked)
    {
        AppWarning(TEXT("D3DTexture::GetRenderTargetImage cannot be used while destination is locked"));
        return FALSE;
    }

    if(SUCCEEDED(GetTex()->GetSurfaceLevel(0, &RenderSurface)))
    {
        if(SUCCEEDED(d3d->d3dDevice->GetRenderTargetData(RenderSurface, oss->surface)))
            bSuccess = TRUE;

        RenderSurface->Release();
    }

    return bSuccess;
}
示例#5
0
void DeleteTex( int id )
{
	//	TEXINF idのテクスチャを破棄
	//
	DeleteTexInf( GetTex( id ) );
}
示例#6
0
int GetCacheMesTextureID( char *msg, int font_size, int font_style )
{
	//		キャッシュ済みのテクスチャIDを返す(OpenGLテクスチャIDを返す)
	//		(作成されていないメッセージテクスチャは自動的に作成する)
	//		(作成の必要がない場合は-1を返す)
	//
	GLuint id;
	int texid;
	int tsx,tsy;
	unsigned char *pImg;

	TEXINF *t;
	int mylen;
	short mycache;
	
	mycache = str2hash( msg, &mylen );			// キャッシュを取得
	if ( mylen <= 0 ) return -1;

	texid = getCache( msg, mycache, font_size, font_style );
	if ( texid >= 0 ) {
		return texid;							// キャッシュがあった
	}

	//		キャッシュが存在しないので作成
	pImg = (unsigned char *)j_callFontBitmap( msg, font_size, font_style, &tsx, &tsy );
	texid = MakeEmptyTex( tsx, tsy );
	if ( texid < 0 ) return -1;

	t = GetTex( texid );
	t->hash = mycache;
	t->font_size = font_size;
	t->font_style = font_style;

	if ( curmestex >= GetSysReq(SYSREQ_MESCACHE_MAX) ) {	// エントリ数がオーバーしているものは次のフレームで破棄
		t->life = 0;
		t->buf[0] = 0;
	} else {
		//		キャッシュの登録
		if ( mylen >= ( TEXMES_NAME_BUFFER - 1 ) ) {
			t->text = (char *)malloc( mylen+1 );		// テキストハッシュネーム用バッファを作成する
			strcpy( t->text, msg );
		} else {
			strcpy( t->buf, msg );						// 標準バッファにコピーする
		}
	}

	id = (GLuint)t->texid;

	glBindTexture( GL_TEXTURE_2D, id );
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glPixelStorei( GL_UNPACK_ALIGNMENT, 1);

	glTexSubImage2D(
		GL_TEXTURE_2D,
		0,
		(GLint)0,
		(GLint)0,
		(GLsizei)tsx,
		(GLsizei)tsy,
		GL_ALPHA,
		GL_UNSIGNED_BYTE,
		pImg
	);

	glBindTexture(GL_TEXTURE_2D, 0);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	free(pImg);

	return texid;
}
示例#7
0
文件: hgtex.cpp 项目: sharkpp/openhsp
int GetCacheMesTextureID( char *msg, int font_size, int font_style )
{
	//		キャッシュ済みのテクスチャIDを返す(OpenGLテクスチャIDを返す)
	//		(作成されていないメッセージテクスチャは自動的に作成する)
	//		(作成の必要がない場合は-1を返す)
	//
#ifdef HSPNDK
	GLuint id;
	int texid;
	int tsx,tsy;
	unsigned char *pImg;

	TEXINF *t;
	int mylen;
	short mycache;
	
	mycache = str2hash( msg, &mylen );			// キャッシュを取得
	if ( mylen <= 0 ) return -1;

	texid = getCache( msg, mycache, font_size, font_style );
	if ( texid >= 0 ) {
		return texid;							// キャッシュがあった
	}

	//		キャッシュが存在しないので作成
	pImg = (unsigned char *)j_callFontBitmap( msg, font_size, font_style, &tsx, &tsy );
	texid = MakeEmptyTex( tsx, tsy );
	if ( texid < 0 ) return -1;

	t = GetTex( texid );
	t->hash = mycache;
	t->font_size = font_size;
	t->font_style = font_style;

	if ( curmestex >= GetSysReq(SYSREQ_MESCACHE_MAX) ) {	// エントリ数がオーバーしているものは次のフレームで破棄
		t->life = 0;
		t->buf[0] = 0;
	} else {
		//		キャッシュの登録
		if ( mylen >= ( TEXMES_NAME_BUFFER - 1 ) ) {
			t->text = (char *)malloc( mylen+1 );		// テキストハッシュネーム用バッファを作成する
			strcpy( t->text, msg );
		} else {
			strcpy( t->buf, msg );						// 標準バッファにコピーする
		}
	}

	id = (GLuint)t->texid;

	glBindTexture( GL_TEXTURE_2D, id );
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glPixelStorei( GL_UNPACK_ALIGNMENT, 1);

	glTexSubImage2D(
		GL_TEXTURE_2D,
		0,
		(GLint)0,
		(GLint)0,
		(GLsizei)tsx,
		(GLsizei)tsy,
		GL_ALPHA,
		GL_UNSIGNED_BYTE,
		pImg
	);

	glBindTexture(GL_TEXTURE_2D, 0);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	free(pImg);

	return texid;
#endif

#ifdef HSPEMSCRIPTEN
	GLuint id;
	int texid;
	int tsx,tsy;
	unsigned char *pImg;

	TEXINF *t;
	int mylen;
	short mycache;

	mycache = str2hash( msg, &mylen );			// キャッシュを取得
	if ( mylen <= 0 ) return -1;

	texid = getCache( msg, mycache, font_size, font_style );
	if ( texid >= 0 ) {
		return texid;							// キャッシュがあった
	}

	EM_ASM_({
		var d = document.getElementById('hsp3dishFontDiv');
		if (!d) {
			d = document.createElement("div");
			d.id = 'hsp3dishFontDiv';
			d.style.setProperty("width", "auto");
			d.style.setProperty("height", "auto");
			d.style.setProperty("position", "absolute");
			d.style.setProperty("visibility", "hidden");
		}
		d.style.setProperty("font", $1 + "px 'sans-serif'");
		document.body.appendChild(d);

		var t = document.createTextNode(Pointer_stringify($0));
		if (d.hasChildNodes())
			d.removeChild(d.firstChild);
		d.appendChild(t);
		}, msg, font_size);
示例#8
0
void  D3DTexture::RebuildMipMaps()
{
    GetTex()->GenerateMipSubLevels();
}
示例#9
0
void* D3DTexture::GetImage(BOOL bForce, void *lpInputPtr)
{
    if(!bForce || (bDynamic && (dwTexType != D3DTEXTURE_FRAME_BUFFER)))
    {
        if(dwTexType == D3DTEXTURE_FRAME_BUFFER)
            ErrOut(TEXT("Tried to query image for frame buffer"));
        if(!bDynamic)
            ErrOut(TEXT("Tried to query image for non-dynamic texture"));
    }
    else
    {
        IDirect3DSurface9 *RenderSurface=NULL, *CopySurface=NULL;
        BOOL bSuccess=FALSE;
        LPVOID lpData=NULL;

        D3DLOCKED_RECT d3dRect;
        int i,j;

        if(dwTexType == D3DTEXTURE_FRAME_BUFFER)
        {
            if(SUCCEEDED(GetTex()->GetSurfaceLevel(0, &RenderSurface)))
            {
                profileSegment("is it this?"); //3.14%
                if(SUCCEEDED(d3d->d3dDevice->CreateOffscreenPlainSurface(Width(), Height(), (D3DFORMAT)dwInternalFormat, D3DPOOL_SYSTEMMEM, &CopySurface, NULL)))
                {
                    profileSegment("or is it this?"); //5.48%
                    if(SUCCEEDED(d3d->d3dDevice->GetRenderTargetData(RenderSurface, CopySurface)))
                    {
                        profileSegment("or how about this?");
                        if(SUCCEEDED(CopySurface->LockRect(&d3dRect, NULL, 0)))
                            bSuccess = TRUE;
                    }
                }
            }

            if(RenderSurface)
                RenderSurface->Release();

            if(!bSuccess)
            {
                if(CopySurface)
                    CopySurface->Release();

                return NULL;
            }
        }
        else
        {
            if(!SUCCEEDED(GetTex()->GetSurfaceLevel(0, &CopySurface)))
                return NULL;
            if(!SUCCEEDED(CopySurface->LockRect(&d3dRect, NULL, 0)))
            {
                CopySurface->Release();
                return NULL;
            }
        }

        //-------------------------------------------------------

        if(dwFormat <= GS_GRAYSCALE)
        {
            lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height());

            LPBYTE lpBits  = (LPBYTE)d3dRect.pBits;
            LPBYTE lpInput = (LPBYTE)lpData;

            for(i=0; i<texHeight; i++)
                mcpy(lpInput+(i*texWidth), lpBits+(i*(d3dRect.Pitch)), texWidth);
        }
        else if(dwFormat == GS_A8L8)
        {
            lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*2);

            LPWORD lpBits  = (LPWORD)d3dRect.pBits;
            LPWORD lpInput = (LPWORD)lpData;
            DWORD widthX2 = texWidth*2;

            for(i=0; i<texHeight; i++)
                mcpy(lpInput+(i*widthX2), lpBits+(i*d3dRect.Pitch), widthX2);
        }
        else if(dwFormat == GS_RGB)
        {
            lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*3);

            LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData;
            //DWORD widthX3 = texWidth*3;

            for(i=0; i<texHeight; i++)
            {
                //mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX3), widthX3);
                DWORD curY      = (i*texWidth*3);
                DWORD curD3DY   = (i*d3dRect.Pitch);

                for(j=0; j<texWidth; j++)
                {
                    DWORD curX      = curY+(j*3);
                    DWORD curD3DX   = curD3DY+(j*4);

                    lpInput[curX]   = lpBits[curD3DX];
                    lpInput[curX+1] = lpBits[curD3DX+1];
                    lpInput[curX+2] = lpBits[curD3DX+2];
                }
            }
        }
        else if(dwFormat == GS_DXT1)
        {
            LPBYTE lpBits = (LPBYTE)d3dRect.pBits;

            DWORD tempWidth  = (texWidth+3)/4;
            DWORD tempHeight = (texHeight+3)/4;

            lpData = lpInputPtr ? lpInputPtr : Allocate(tempWidth*tempHeight*8);
            mcpy(lpData, lpBits, tempWidth*tempHeight*8);
        }
        else if((dwFormat == GS_DXT3) || (dwFormat == GS_DXT5))
        {
            LPBYTE lpBits = (LPBYTE)d3dRect.pBits;

            DWORD tempWidth  = (texWidth+3)/4;
            DWORD tempHeight = (texHeight+3)/4;

            lpData = lpInputPtr ? lpInputPtr : Allocate(tempWidth*tempHeight*16);
            mcpy(lpData, lpBits, tempWidth*tempHeight*16);
        }
        else if((dwFormat == GS_RGBA) || (dwFormat == GS_RG16F))
        {
            lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*4);

            LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData;
            DWORD widthX4 = texWidth*4;

            for(i=0; i<texHeight; i++)
                mcpy(lpInput+(i*widthX4), lpBits+(i*d3dRect.Pitch), widthX4);
        }
        else if((dwFormat == GS_RGBA16) || (dwFormat == GS_RG32F))
        {
            lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*2*4);

            LPBYTE lpBits = (LPBYTE)d3dRect.pBits;
            LPWORD lpInput = (LPWORD)lpData;
            DWORD widthX8 = texWidth*8;

            for(i=0; i<texHeight; i++)
                mcpy(lpInput+(i*widthX8), lpBits+(i*d3dRect.Pitch), widthX8);
        }
        else if(dwFormat == GS_RGBA16F) //converts to 8bit RGBA
        {
            lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*sizeof(Vect4));

            LPBYTE lpBits = (LPBYTE)d3dRect.pBits;
            Vect4* lpInput = (Vect4*)lpData;
            DWORD widthXVect = texWidth*sizeof(Vect4);

            for(i=0; i<texHeight; i++)
            {
                DWORD curY      = (i*texWidth);
                DWORD curD3DY   = (i*d3dRect.Pitch);

                for(j=0; j<texWidth; j++)
                {
                    DWORD curX      = curY+(j*4);
                    DWORD curD3DX   = curD3DY+(j*2*4);

                    lpInput[curY+j].x = ((FLOAT)*(D3DXFLOAT16*)(lpBits+(curD3DX)));
                    lpInput[curY+j].y = ((FLOAT)*(D3DXFLOAT16*)(lpBits+(curD3DX+2)));
                    lpInput[curY+j].z = ((FLOAT)*(D3DXFLOAT16*)(lpBits+(curD3DX+4)));
                    lpInput[curY+j].w = ((FLOAT)*(D3DXFLOAT16*)(lpBits+(curD3DX+6)));
                }
            }
        }
        else if(dwFormat == GS_RGBA32F) //converts to 8bit RGBA
        {
            lpData = lpInputPtr ? lpInputPtr : Allocate(Width()*Height()*sizeof(Vect4));

            LPBYTE lpBits = (LPBYTE)d3dRect.pBits;
            Vect4* lpInput = (Vect4*)lpData;
            DWORD widthXVect = texWidth*sizeof(Vect4);

            if(widthXVect == d3dRect.Pitch)
                mcpy(lpInput, lpBits, widthXVect*texHeight);
            else
            {
                for(i=0; i<texHeight; i++)
                    mcpy(lpInput+(i*texWidth), lpBits+(i*d3dRect.Pitch), widthXVect);
            }
        }

        //-------------------------------------------------------

        CopySurface->UnlockRect();
        CopySurface->Release();

        return lpData;
    }

    return textureData;
}
示例#10
0
void D3DTexture::SetImage(void *lpData)
{
    traceInFast(D3DTexture::SetImage);

    assert(lpData);

    D3DLOCKED_RECT d3dRect;
    int i,j;

    HRESULT problemo = GetTex()->LockRect(0, &d3dRect, NULL, 0);

    if(!d3dRect.pBits)
        return;

    if(dwFormat <= GS_GRAYSCALE) // if dwFormat is GS_ALPHA or GS_GRAYSCALE
    {
        if(dwInternalFormat == D3DFMT_A8L8)
        {
            LPWORD lpBits  = (LPWORD)d3dRect.pBits;
            LPBYTE lpInput = (LPBYTE)lpData;

            for(i=0; i<texHeight; i++)
            {
                for(j=0; j<texWidth; j++)
                {
                    WORD val = ((lpInput[(i*texWidth)+j]) << 8) | 0xFF;
                    lpBits[(i*(d3dRect.Pitch/2))+j] = val;
                }
            }
        }
        else
        {
            LPBYTE lpBits  = (LPBYTE)d3dRect.pBits;
            LPBYTE lpInput = (LPBYTE)lpData;

            for(i=0; i<texHeight; i++)
                mcpy(lpBits+(i*(d3dRect.Pitch)), lpInput+(i*texWidth), texWidth);
        }
    }
    else if((dwFormat == GS_A8L8) || (dwFormat == GS_L16))
    {
        LPWORD lpBits  = (LPWORD)d3dRect.pBits;
        LPWORD lpInput = (LPWORD)lpData;
        DWORD widthX2 = texWidth*2;

        for(i=0; i<texHeight; i++)
            mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX2), widthX2);
    }
    else if(dwFormat == GS_RGB)
    {
        LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData;
        //DWORD widthX3 = texWidth*3;

        for(i=0; i<texHeight; i++)
        {
            //mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX3), widthX3);
            DWORD curY      = (i*texWidth*3);
            DWORD curD3DY   = (i*d3dRect.Pitch);

            for(j=0; j<texWidth; j++)
            {
                DWORD curX      = curY+(j*3);
                DWORD curD3DX   = curD3DY+(j*4);

                lpBits[curD3DX]   = lpInput[curX];
                lpBits[curD3DX+1] = lpInput[curX+1];
                lpBits[curD3DX+2] = lpInput[curX+2];
            }
        }

    }
    else if(dwFormat == GS_DXT1)
    {
        LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData;

        DWORD tempWidth  = (texWidth+3)/4;
        DWORD tempHeight = (texHeight+3)/4;

        mcpy(lpBits, lpInput, tempWidth*tempHeight*8);
    }
    else if((dwFormat == GS_DXT3) || (dwFormat == GS_DXT5))
    {
        LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData;

        DWORD tempWidth  = (texWidth+3)/4;
        DWORD tempHeight = (texHeight+3)/4;

        mcpy(lpBits, lpInput, tempWidth*tempHeight*16);
    }
    else if((dwFormat == GS_RGBA) || (dwFormat == GS_RG16F))
    {
        LPBYTE lpBits = (LPBYTE)d3dRect.pBits, lpInput = (LPBYTE)lpData;
        DWORD widthX4 = texWidth*4;

        for(i=0; i<texHeight; i++)
        {
            mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX4), widthX4);
            /*DWORD curY      = (i*texWidth*4);
            DWORD curD3DY   = (i*d3dRect.Pitch);

            for(j=0; j<texWidth; j++)
            {
                DWORD jx4       = (j*4);
                DWORD curX      = curY+jx4;
                DWORD curD3DX   = curD3DY+jx4;

                lpBits[curD3DX]   = lpInput[curX+2];
                lpBits[curD3DX+1] = lpInput[curX+1];
                lpBits[curD3DX+2] = lpInput[curX];
                lpBits[curD3DX+3] = lpInput[curX+3];
            }*/
        }
    }
    else if((dwFormat == GS_RGBA16) || (dwFormat == GS_RGBA16F) || (dwFormat == GS_RG32F))
    {
        LPBYTE lpBits = (LPBYTE)d3dRect.pBits;
        LPWORD lpInput = (LPWORD)lpData;
        DWORD widthX8 = texWidth*8;

        for(i=0; i<texHeight; i++)
        {
            mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX8), widthX8);
            /*DWORD yOffset = (i*(texWidth*8));
            DWORD yTexOffset = (i*d3dRect.Pitch);
            for(j=0; j<texWidth; j++)
            {
                WORD *lpColors = (WORD*)&lpBits[yTexOffset+(j*8)];
                DWORD offset = yOffset+(j*8);

                lpColors[3] = lpInput[offset+2];
                lpColors[2] = lpInput[offset+1];
                lpColors[1] = lpInput[offset];
                lpColors[0] = lpInput[offset+3];
            }*/
        }
    }
    else if(dwFormat == GS_RGBA32F)
    {
        LPBYTE lpBits = (LPBYTE)d3dRect.pBits;
        LPDWORD lpInput = (LPDWORD)lpData;
        DWORD widthX16 = texWidth*16;

        for(i=0; i<texHeight; i++)
        {
            mcpy(lpBits+(i*d3dRect.Pitch), lpInput+(i*widthX16), widthX16);
            /*DWORD yOffset = (i*(texWidth*16));
            DWORD yTexOffset = (i*d3dRect.Pitch);
            for(j=0; j<texWidth; j++)
            {
                LPDWORD lpColors = (LPDWORD)&lpBits[yTexOffset+(j*8)];
                DWORD offset = yOffset+(j*16);

                lpColors[3] = lpInput[offset+2];
                lpColors[2] = lpInput[offset+1];
                lpColors[1] = lpInput[offset];
                lpColors[0] = lpInput[offset+3];
            }*/
        }
    }
    else
    {
        GetTex()->UnlockRect(0);
        ErrOut(TEXT("eep-chi, this message is required because a texture format needs Texture::SetImage implementation."));
        return;
    }

    GetTex()->UnlockRect(0);

    if(bHasMipMaps && (dwTexType == D3DTEXTURE_STANDARD_BUFFER))
        D3DXFilterTexture(GetTex(), NULL, 0, D3DX_DEFAULT);

    if(bDynamic && (textureData != lpData))
    {
        Free(textureData);
        textureData = (LPBYTE)lpData;
    }

    traceOutFast;
}
示例#11
0
void D3DTexture::FreeBuffer()
{
    D3DRelease(GetTex());
}
示例#12
0
void D3DTexture::CreateBuffer()
{
    traceIn(D3DTexture::CreateBuffer);

    HRESULT problemo;

    if(dwTexType == D3DTEXTURE_FRAME_BUFFER)
    {
        switch(dwFormat)
        {
            case GS_RGBA:
                dwInternalFormat = D3DFMT_A8R8G8B8;
                bNeedsBlending = 1;
                break;
            case GS_RGBA16:
                dwInternalFormat = D3DFMT_A16B16G16R16;
                break;
            case GS_RGBA16F:
                dwInternalFormat = D3DFMT_A16B16G16R16F;
                break;
            case GS_RGBA32F:
                dwInternalFormat = D3DFMT_A32B32G32R32F;
                break;
            case GS_RG16F:
                dwInternalFormat = D3DFMT_G16R16F;
                break;
            case GS_RG32F:
                dwInternalFormat = D3DFMT_G32R32F;
                break;
            default:
                ErrOut(TEXT("render target texture format not supported"));
        }

        problemo = d3d->d3dDevice->CreateTexture(texWidth, texHeight, !bHasMipMaps, (bHasMipMaps ? D3DUSAGE_AUTOGENMIPMAP : 0) | D3DUSAGE_RENDERTARGET | (bDynamic ? D3DUSAGE_DYNAMIC : 0), (D3DFORMAT)dwInternalFormat, D3DPOOL_DEFAULT, &GetTex(), NULL);

        if(!SUCCEEDED(problemo))
        {
            if(problemo == D3DERR_OUTOFVIDEOMEMORY)
                ErrOut(TEXT("Error Creating D3D Render Texture: Out of Video Memory!"));
            else if(problemo == D3DERR_INVALIDCALL)
                ErrOut(TEXT("Error Creating D3D Render Texture: Invalid call, Format 0x%lX"), dwFormat);
            else if(problemo == E_OUTOFMEMORY)
                ErrOut(TEXT("Error Creating D3D Render Texture: Out of general memory!"));
            else if(problemo == D3DERR_DRIVERINTERNALERROR)
                ErrOut(TEXT("Error Creating D3D Render Texture: Internal driver error"));
            else
                ErrOut(TEXT("Could not create D3D Render Texture for some unknown reason:  exact error code is 0x%lX"), problemo);
        }
    }
    else
    {
        switch(dwFormat)
        {
            case GS_GRAYSCALE:
                dwInternalFormat = D3DFMT_L8;
                break;
            case GS_L16:
                dwInternalFormat = D3DFMT_L16;
                break;
            case GS_ALPHA:
                bNeedsBlending = 1;
                if(d3d->bA8Supported)
                    dwInternalFormat = D3DFMT_A8;
                else
                    dwInternalFormat = D3DFMT_A8L8;
                break;
            case GS_RGB:
                dwInternalFormat = D3DFMT_X8R8G8B8;
                break;
            case GS_RGBA:
                dwInternalFormat = D3DFMT_A8R8G8B8;
                bNeedsBlending = 1;
                break;
            case GS_RGBA16:
                dwInternalFormat = D3DFMT_A16B16G16R16;
                break;
            case GS_RGBA16F:
                dwInternalFormat = D3DFMT_A16B16G16R16F;
                break;
            case GS_RGBA32F:
                dwInternalFormat = D3DFMT_A32B32G32R32F;
                break;
            case GS_RG16F:
                dwInternalFormat = D3DFMT_G16R16F;
                break;
            case GS_RG32F:
                dwInternalFormat = D3DFMT_G32R32F;
                break;
            case GS_A8L8:
                dwInternalFormat = D3DFMT_A8L8;
                break;
            case GS_DXT1:
                dwInternalFormat = D3DFMT_DXT1;
                break;
            case GS_DXT3:
                dwInternalFormat = D3DFMT_DXT3;
                break;
            case GS_DXT5:
                dwInternalFormat = D3DFMT_DXT5;
                break;
            default:
                ErrOut(TEXT("texture format not supported"));
        }

        problemo = d3d->d3dDevice->CreateTexture(texWidth, texHeight, bHasMipMaps ? 0 : 1, bDynamic ? D3DUSAGE_DYNAMIC : 0, (D3DFORMAT)dwInternalFormat, bDynamic ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED, &GetTex(), NULL);

        if(!SUCCEEDED(problemo))
        {
            if(problemo == D3DERR_OUTOFVIDEOMEMORY)
                ErrOut(TEXT("Error Creating D3D Texture: Out of Video Memory!"));
            else if(problemo == D3DERR_INVALIDCALL)
                ErrOut(TEXT("Error Creating D3D Texture: Invalid call, Format 0x%lX"), dwFormat);
            else if(problemo == E_OUTOFMEMORY)
                ErrOut(TEXT("Error Creating D3D Texture: Out of general memory!"));
            else
                ErrOut(TEXT("Could not create D3D Texture for some unknown reason:  exact error code is 0x%lX"), problemo);
        }
    }

    traceOut;
}