DirectX 9 backend, part 3
This commit is contained in:
parent
056545d899
commit
5a0ddbc212
|
@ -391,13 +391,15 @@ void ImGui_ImplDX9_InvalidateDeviceObjects()
|
||||||
ImGui_ImplDX9_InvalidateDeviceObjectsForPlatformWindows();
|
ImGui_ImplDX9_InvalidateDeviceObjectsForPlatformWindows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplDX9_NewFrame()
|
bool ImGui_ImplDX9_NewFrame()
|
||||||
{
|
{
|
||||||
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
|
||||||
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX9_Init()?");
|
IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplDX9_Init()?");
|
||||||
|
|
||||||
if (!bd->FontTexture)
|
if (!bd->FontTexture)
|
||||||
ImGui_ImplDX9_CreateDeviceObjects();
|
return ImGui_ImplDX9_CreateDeviceObjects();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -19,7 +19,7 @@ struct IDirect3DDevice9;
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplDX9_Init(IDirect3DDevice9* device);
|
IMGUI_IMPL_API bool ImGui_ImplDX9_Init(IDirect3DDevice9* device);
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX9_Shutdown();
|
IMGUI_IMPL_API void ImGui_ImplDX9_Shutdown();
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX9_NewFrame();
|
IMGUI_IMPL_API bool ImGui_ImplDX9_NewFrame();
|
||||||
IMGUI_IMPL_API void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data);
|
IMGUI_IMPL_API void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data);
|
||||||
|
|
||||||
// Use if you want to reset your rendering device without losing Dear ImGui state.
|
// Use if you want to reset your rendering device without losing Dear ImGui state.
|
||||||
|
|
|
@ -27,13 +27,15 @@
|
||||||
class FurnaceDX9Texture: public FurnaceGUITexture {
|
class FurnaceDX9Texture: public FurnaceGUITexture {
|
||||||
public:
|
public:
|
||||||
IDirect3DTexture9* tex;
|
IDirect3DTexture9* tex;
|
||||||
int width, height;
|
int width, height, widthReal, heightReal;
|
||||||
unsigned char* lockedData;
|
unsigned char* lockedData;
|
||||||
bool dynamic;
|
bool dynamic;
|
||||||
FurnaceDX9Texture():
|
FurnaceDX9Texture():
|
||||||
tex(NULL),
|
tex(NULL),
|
||||||
width(0),
|
width(0),
|
||||||
height(0),
|
height(0),
|
||||||
|
widthReal(0),
|
||||||
|
heightReal(0),
|
||||||
lockedData(NULL),
|
lockedData(NULL),
|
||||||
dynamic(false) {}
|
dynamic(false) {}
|
||||||
};
|
};
|
||||||
|
@ -44,23 +46,72 @@ ImTextureID FurnaceGUIRenderDX9::getTextureID(FurnaceGUITexture* which) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FurnaceGUIRenderDX9::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) {
|
bool FurnaceGUIRenderDX9::lockTexture(FurnaceGUITexture* which, void** data, int* pitch) {
|
||||||
return false;
|
FurnaceDX9Texture* t=(FurnaceDX9Texture*)which;
|
||||||
|
D3DLOCKED_RECT lockedRect;
|
||||||
|
|
||||||
|
HRESULT result=t->tex->LockRect(0,&lockedRect,NULL,D3DLOCK_DISCARD);
|
||||||
|
|
||||||
|
if (result!=D3D_OK) {
|
||||||
|
logW("could not lock texture!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*data=lockedRect.pBits;
|
||||||
|
*pitch=lockedRect.Pitch;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FurnaceGUIRenderDX9::unlockTexture(FurnaceGUITexture* which) {
|
bool FurnaceGUIRenderDX9::unlockTexture(FurnaceGUITexture* which) {
|
||||||
return false;
|
FurnaceDX9Texture* t=(FurnaceDX9Texture*)which;
|
||||||
|
HRESULT result=t->tex->UnlockRect(0);
|
||||||
|
|
||||||
|
if (result!=D3D_OK) {
|
||||||
|
logW("could not unlock texture!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FurnaceGUIRenderDX9::updateTexture(FurnaceGUITexture* which, void* data, int pitch) {
|
bool FurnaceGUIRenderDX9::updateTexture(FurnaceGUITexture* which, void* data, int pitch) {
|
||||||
|
// TODO
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FurnaceGUITexture* FurnaceGUIRenderDX9::createTexture(bool dynamic, int width, int height, bool interpolate) {
|
FurnaceGUITexture* FurnaceGUIRenderDX9::createTexture(bool dynamic, int width, int height, bool interpolate) {
|
||||||
return NULL;
|
IDirect3DTexture9* tex=NULL;
|
||||||
|
int widthReal=width;
|
||||||
|
int heightReal=height;
|
||||||
|
|
||||||
|
if ((widthReal&(widthReal-1))!=0) {
|
||||||
|
widthReal=1<<bsr(width);
|
||||||
|
}
|
||||||
|
if ((heightReal&(heightReal-1))!=0) {
|
||||||
|
heightReal=1<<bsr(height);
|
||||||
|
}
|
||||||
|
logV("width: %d (requested)... %d (actual)",width,widthReal);
|
||||||
|
logV("height: %d (requested)... %d (actual)",height,heightReal);
|
||||||
|
|
||||||
|
HRESULT result=device->CreateTexture(widthReal,heightReal,1,dynamic?D3DUSAGE_DYNAMIC:0,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,&tex,NULL);
|
||||||
|
|
||||||
|
if (result!=D3D_OK) {
|
||||||
|
logW("could not create texture! %.8x",result);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
FurnaceDXTexture* ret=new FurnaceDXTexture;
|
||||||
|
ret->width=width;
|
||||||
|
ret->height=height;
|
||||||
|
ret->widthReal=widthReal;
|
||||||
|
ret->heightReal=heightReal;
|
||||||
|
ret->tex=tex;
|
||||||
|
ret->dynamic=dynamic;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FurnaceGUIRenderDX9::destroyTexture(FurnaceGUITexture* which) {
|
bool FurnaceGUIRenderDX9::destroyTexture(FurnaceGUITexture* which) {
|
||||||
FurnaceDX9Texture* t=(FurnaceDX9Texture*)which;
|
FurnaceDX9Texture* t=(FurnaceDX9Texture*)which;
|
||||||
|
t->tex->Release();
|
||||||
delete t;
|
delete t;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -90,13 +141,11 @@ void FurnaceGUIRenderDX9::present() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FurnaceGUIRenderDX9::newFrame() {
|
bool FurnaceGUIRenderDX9::newFrame() {
|
||||||
ImGui_ImplDX9_NewFrame();
|
return ImGui_ImplDX9_NewFrame();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FurnaceGUIRenderDX9::canVSync() {
|
bool FurnaceGUIRenderDX9::canVSync() {
|
||||||
// TODO: find out how to retrieve VSync status
|
return supportsVSync;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FurnaceGUIRenderDX9::createFontsTexture() {
|
void FurnaceGUIRenderDX9::createFontsTexture() {
|
||||||
|
@ -190,6 +239,7 @@ bool FurnaceGUIRenderDX9::init(SDL_Window* win, int swapInt) {
|
||||||
} else {
|
} else {
|
||||||
priv->present.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;
|
priv->present.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||||
}
|
}
|
||||||
|
priv->present.hDeviceWindow=window;
|
||||||
|
|
||||||
HRESULT result=iface->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,window,D3DCREATE_HARDWARE_VERTEXPROCESSING,&priv->present,&device);
|
HRESULT result=iface->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,window,D3DCREATE_HARDWARE_VERTEXPROCESSING,&priv->present,&device);
|
||||||
|
|
||||||
|
@ -200,6 +250,17 @@ bool FurnaceGUIRenderDX9::init(SDL_Window* win, int swapInt) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
D3DCAPS9 caps;
|
||||||
|
|
||||||
|
result=device->GetDeviceCaps(&caps);
|
||||||
|
|
||||||
|
if (result==D3D_OK) {
|
||||||
|
supportsDynamicTex=(caps.Caps2&D3DCAPS2_DYNAMICTEXTURES);
|
||||||
|
supportsVSync=(caps.PresentationIntervals&D3DPRESENT_INTERVAL_ONE);
|
||||||
|
maxWidth=caps.MaxTextureWidth;
|
||||||
|
maxHeight=caps.MaxTextureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class FurnaceGUIRenderDX9: public FurnaceGUIRender {
|
||||||
|
|
||||||
int outW, outH, swapInterval;
|
int outW, outH, swapInterval;
|
||||||
|
|
||||||
bool dead, haveScene;
|
bool dead, haveScene, supportsDynamicTex, supportsVSync;
|
||||||
|
|
||||||
// SHADERS //
|
// SHADERS //
|
||||||
|
|
||||||
|
@ -85,6 +85,8 @@ class FurnaceGUIRenderDX9: public FurnaceGUIRender {
|
||||||
swapInterval(1),
|
swapInterval(1),
|
||||||
dead(false),
|
dead(false),
|
||||||
haveScene(false),
|
haveScene(false),
|
||||||
|
supportsDynamicTex(false),
|
||||||
|
supportsVSync(false),
|
||||||
maxWidth(8192),
|
maxWidth(8192),
|
||||||
maxHeight(8192) {
|
maxHeight(8192) {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue