浏览代码

Examples: DirectX9: fixed duplicate creation of vertex buffer. Size of static vertex buffer at top of the code.

ocornut 10 年之前
父节点
当前提交
d3e444dfd9
共有 2 个文件被更改,包括 4 次插入5 次删除
  1. 2 1
      examples/directx11_example/imgui_impl_dx11.cpp
  2. 2 4
      examples/directx9_example/imgui_impl_dx9.cpp

+ 2 - 1
examples/directx11_example/imgui_impl_dx11.cpp

@@ -27,6 +27,7 @@ static ID3D11PixelShader*       g_pPixelShader = NULL;
 static ID3D11SamplerState*      g_pFontSampler = NULL;
 static ID3D11SamplerState*      g_pFontSampler = NULL;
 static ID3D11ShaderResourceView*g_pFontTextureView = NULL;
 static ID3D11ShaderResourceView*g_pFontTextureView = NULL;
 static ID3D11BlendState*        g_blendState = NULL;
 static ID3D11BlendState*        g_blendState = NULL;
+static int                      VERTEX_BUFFER_SIZE = 30000;     // TODO: Make vertex buffer smaller and grow dynamically as needed.
 
 
 struct CUSTOMVERTEX
 struct CUSTOMVERTEX
 {
 {
@@ -358,7 +359,7 @@ bool    ImGui_ImplDX11_CreateDeviceObjects()
         D3D11_BUFFER_DESC bufferDesc;
         D3D11_BUFFER_DESC bufferDesc;
         memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
         memset(&bufferDesc, 0, sizeof(D3D11_BUFFER_DESC));
         bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
         bufferDesc.Usage = D3D11_USAGE_DYNAMIC;
-        bufferDesc.ByteWidth = 100000 * sizeof(CUSTOMVERTEX); // Maybe we should handle that more dynamically?
+        bufferDesc.ByteWidth = VERTEX_BUFFER_SIZE * sizeof(CUSTOMVERTEX);
         bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
         bufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
         bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
         bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
         bufferDesc.MiscFlags = 0;
         bufferDesc.MiscFlags = 0;

+ 2 - 4
examples/directx9_example/imgui_impl_dx9.cpp

@@ -15,6 +15,7 @@ static INT64                    g_Time = 0;
 static INT64                    g_TicksPerSecond = 0;
 static INT64                    g_TicksPerSecond = 0;
 static LPDIRECT3DDEVICE9        g_pd3dDevice = NULL;
 static LPDIRECT3DDEVICE9        g_pd3dDevice = NULL;
 static LPDIRECT3DVERTEXBUFFER9  g_pVB = NULL;
 static LPDIRECT3DVERTEXBUFFER9  g_pVB = NULL;
+static int                      VERTEX_BUFFER_SIZE = 30000;     // TODO: Make vertex buffer smaller and grow dynamically as needed.
 
 
 struct CUSTOMVERTEX
 struct CUSTOMVERTEX
 {
 {
@@ -183,9 +184,6 @@ bool    ImGui_ImplDX9_Init(void* hwnd, IDirect3DDevice9* device)
     io.RenderDrawListsFn = ImGui_ImplDX9_RenderDrawLists;
     io.RenderDrawListsFn = ImGui_ImplDX9_RenderDrawLists;
     io.ImeWindowHandle = g_hWnd;
     io.ImeWindowHandle = g_hWnd;
 
 
-    if (g_pd3dDevice->CreateVertexBuffer(10000 * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0)
-        return false;
-
     return true;
     return true;
 }
 }
 
 
@@ -232,7 +230,7 @@ bool ImGui_ImplDX9_CreateDeviceObjects()
     if (!g_pd3dDevice)
     if (!g_pd3dDevice)
         return false;
         return false;
 
 
-    if (g_pd3dDevice->CreateVertexBuffer(10000 * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0)
+    if (g_pd3dDevice->CreateVertexBuffer(VERTEX_BUFFER_SIZE * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0)
         return false;
         return false;
 
 
     ImGui_ImplDX9_CreateFontsTexture();
     ImGui_ImplDX9_CreateFontsTexture();