mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-23 13:05:11 +00:00
GUI: DirectX 11 render backend, part 8
updateTexture for dynamic textures
This commit is contained in:
parent
6933446d8a
commit
83ad6e0894
1 changed files with 24 additions and 2 deletions
|
@ -74,12 +74,14 @@ struct FurnaceDXTexture {
|
||||||
ID3D11ShaderResourceView* view;
|
ID3D11ShaderResourceView* view;
|
||||||
int width, height;
|
int width, height;
|
||||||
unsigned char* lockedData;
|
unsigned char* lockedData;
|
||||||
|
bool dynamic;
|
||||||
FurnaceDXTexture():
|
FurnaceDXTexture():
|
||||||
tex(NULL),
|
tex(NULL),
|
||||||
view(NULL),
|
view(NULL),
|
||||||
width(0),
|
width(0),
|
||||||
height(0),
|
height(0),
|
||||||
lockedData(NULL) {}
|
lockedData(NULL),
|
||||||
|
dynamic(false) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool FurnaceGUIRenderDX11::destroyRenderTarget() {
|
bool FurnaceGUIRenderDX11::destroyRenderTarget() {
|
||||||
|
@ -173,7 +175,26 @@ bool FurnaceGUIRenderDX11::unlockTexture(void* which) {
|
||||||
|
|
||||||
bool FurnaceGUIRenderDX11::updateTexture(void* which, void* data, int pitch) {
|
bool FurnaceGUIRenderDX11::updateTexture(void* which, void* data, int pitch) {
|
||||||
FurnaceDXTexture* t=(FurnaceDXTexture*)which;
|
FurnaceDXTexture* t=(FurnaceDXTexture*)which;
|
||||||
context->UpdateSubresource(t->tex,D3D11CalcSubresource(0,0,1),NULL,data,pitch,pitch*t->height);
|
if (t->dynamic) {
|
||||||
|
unsigned char* d=NULL;
|
||||||
|
int p=0;
|
||||||
|
if (!lockTexture(t,&d,&p)) return false;
|
||||||
|
if (p==pitch) {
|
||||||
|
memcpy(d,data,p*t->height);
|
||||||
|
} else {
|
||||||
|
unsigned char* ucData=(unsigned char*)data;
|
||||||
|
int srcPos=0;
|
||||||
|
int destPos=0;
|
||||||
|
for (int i=0; i<t->height; i++) {
|
||||||
|
memcpy(&d[destPos],&ucData[srcPos],pitch);
|
||||||
|
srcPos+=pitch;
|
||||||
|
destPos+=p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unlockTexture(t);
|
||||||
|
} else {
|
||||||
|
context->UpdateSubresource(t->tex,D3D11CalcSubresource(0,0,1),NULL,data,pitch,pitch*t->height);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,6 +243,7 @@ void* FurnaceGUIRenderDX11::createTexture(bool dynamic, int width, int height) {
|
||||||
ret->height=height;
|
ret->height=height;
|
||||||
ret->tex=tex;
|
ret->tex=tex;
|
||||||
ret->view=view;
|
ret->view=view;
|
||||||
|
ret->dynamic=dynamic;
|
||||||
textures.push_back(ret);
|
textures.push_back(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue