Commit 106ef774 authored by D-AIRY's avatar D-AIRY

Added DX_CALL macro for validating DX call results

parent 9b8eaadd
......@@ -296,7 +296,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sxgenpreview", "..\..\sxgen
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sxgui", "..\..\sxgui\vs2013\sxgui.vcxproj", "{8AA0585B-D6E4-46B4-9183-3BACD5B9D47F}"
ProjectSection(ProjectDependencies) = postProject
{C1C1F046-C839-4602-AF70-923CDD237C1B} = {C1C1F046-C839-4602-AF70-923CDD237C1B}
{78B079BD-9FC7-4B9E-B4A6-96DA0F00248B} = {78B079BD-9FC7-4B9E-B4A6-96DA0F00248B}
{AEECC2DB-C7C7-4089-9262-A69794DF834D} = {AEECC2DB-C7C7-4089-9262-A69794DF834D}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "freetype-2.6", "freetype-2.6", "{2D039A6D-B874-4AA7-8F89-E86DD70B21ED}"
......
......@@ -424,8 +424,8 @@ void ModelFile::render(SMMATRIX * mWorld, UINT nSkin, UINT nLod, ID idOverrideMa
MODEL_VERTEX_TYPE vtype = (m_hdr.iFlags & MODEL_FLAG_STATIC) ? MVT_STATIC_EX : MVT_DYNAMIC_EX;
m_pMgr->m_pd3dDevice->SetIndices(m_ppIndexBuffer[nLod]);
m_pMgr->m_pd3dDevice->SetStreamSource(0, m_ppVertexBuffer[nLod], 0, iVertSize[vtype]);
DX_CALL(m_pMgr->m_pd3dDevice->SetIndices(m_ppIndexBuffer[nLod]));
DX_CALL(m_pMgr->m_pd3dDevice->SetStreamSource(0, m_ppVertexBuffer[nLod], 0, iVertSize[vtype]));
m_pMgr->setVertexDeclaration(vtype);
......@@ -658,16 +658,16 @@ void ModelFile::BuildMeshBuffers()
memcpy((byte*)pVertices + m_pLods[j].pSubLODmeshes[i].iStartVertex * vsize, m_pLods[j].pSubLODmeshes[i].pVertices, vsize * m_pLods[j].pSubLODmeshes[i].iVectexCount);
}
m_pMgr->m_pd3dDevice->CreateVertexBuffer(vsize * iStartVertex, NULL, NULL, D3DPOOL_MANAGED, &m_ppVertexBuffer[j], 0);
DX_CALL(m_pMgr->m_pd3dDevice->CreateVertexBuffer(vsize * iStartVertex, NULL, NULL, D3DPOOL_MANAGED, &m_ppVertexBuffer[j], 0));
VOID * pData;
if(!FAILED(m_ppVertexBuffer[j]->Lock(0, vsize * iStartVertex, (void**)&pData, 0)))
if(!FAILED(DX_CALL(m_ppVertexBuffer[j]->Lock(0, vsize * iStartVertex, (void**)&pData, 0))))
{
memcpy(pData, pVertices, vsize * iStartVertex);
m_ppVertexBuffer[j]->Unlock();
}
m_pMgr->m_pd3dDevice->CreateIndexBuffer(sizeof(UINT) * iStartIndex, NULL, D3DFMT_INDEX32, D3DPOOL_MANAGED, &m_ppIndexBuffer[j], 0);
if(!FAILED(m_ppIndexBuffer[j]->Lock(0, sizeof(UINT) * iStartIndex, (void**)&pData, 0)))
DX_CALL(m_pMgr->m_pd3dDevice->CreateIndexBuffer(sizeof(UINT)* iStartIndex, NULL, D3DFMT_INDEX32, D3DPOOL_MANAGED, &m_ppIndexBuffer[j], 0));
if(!FAILED(DX_CALL(m_ppIndexBuffer[j]->Lock(0, sizeof(UINT)* iStartIndex, (void**)&pData, 0))))
{
memcpy(pData, pIndices, sizeof(UINT) * iStartIndex);
m_ppIndexBuffer[j]->Unlock();
......@@ -1495,7 +1495,7 @@ void Animation::RenderSkeleton(int hlBone)
verts[i * 2].color = verts[i * 2 + 1].color = hlBone == i ? 0xFFFF00FF : 0xFF0000FF;
}
m_pMgr->m_pd3dDevice->DrawPrimitiveUP(D3DPT_LINELIST, m_iBoneCount - 1, verts + 2, sizeof(verts[0]));
DX_CALL(m_pMgr->m_pd3dDevice->DrawPrimitiveUP(D3DPT_LINELIST, m_iBoneCount - 1, verts + 2, sizeof(verts[0])));
mem_delete_a(verts);
}
......@@ -1701,7 +1701,7 @@ void Animation::render()
}
if(!(m_pMdl->m_hdr.iFlags & MODEL_FLAG_STATIC))
{
m_pMgr->m_pd3dDevice->SetVertexShaderConstantF(16, (float*)m_pBoneMatrixRender, sizeof(ModelBoneShader)* m_iBoneCount / sizeof(float) / 4);
DX_CALL(m_pMgr->m_pd3dDevice->SetVertexShaderConstantF(16, (float*)m_pBoneMatrixRender, sizeof(ModelBoneShader)* m_iBoneCount / sizeof(float) / 4));
}
m_pMdl->render(&(getWorldTM()), m_iCurrentSkin, 0, m_idOverrideMaterial, &m_vGlowColor, m_isGlowEnabled);
......@@ -2302,7 +2302,7 @@ void AnimationManager::initVertexDeclarations()
{0, 20, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
D3DDECL_END()
};
m_pd3dDevice->CreateVertexDeclaration(layoutStatic, &pVertexDeclaration[MVT_STATIC]);
DX_CALL(m_pd3dDevice->CreateVertexDeclaration(layoutStatic, &pVertexDeclaration[MVT_STATIC]));
D3DVERTEXELEMENT9 layoutStaticEx[] =
{
......@@ -2313,7 +2313,7 @@ void AnimationManager::initVertexDeclarations()
{0, 44, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0},
D3DDECL_END()
};
m_pd3dDevice->CreateVertexDeclaration(layoutStaticEx, &pVertexDeclaration[MVT_STATIC_EX]);
DX_CALL(m_pd3dDevice->CreateVertexDeclaration(layoutStaticEx, &pVertexDeclaration[MVT_STATIC_EX]));
D3DVERTEXELEMENT9 layoutDynamic[] =
{
......@@ -2324,7 +2324,7 @@ void AnimationManager::initVertexDeclarations()
{0, 36, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0},
D3DDECL_END()
};
m_pd3dDevice->CreateVertexDeclaration(layoutDynamic, &pVertexDeclaration[MVT_DYNAMIC]);
DX_CALL(m_pd3dDevice->CreateVertexDeclaration(layoutDynamic, &pVertexDeclaration[MVT_DYNAMIC]));
D3DVERTEXELEMENT9 layoutDynamicEx[] =
{
......@@ -2337,7 +2337,7 @@ void AnimationManager::initVertexDeclarations()
{0, 60, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0},
D3DDECL_END()
};
m_pd3dDevice->CreateVertexDeclaration(layoutDynamicEx, &pVertexDeclaration[MVT_DYNAMIC_EX]);
DX_CALL(m_pd3dDevice->CreateVertexDeclaration(layoutDynamicEx, &pVertexDeclaration[MVT_DYNAMIC_EX]));
}
void AnimationManager::setVertexDeclaration(MODEL_VERTEX_TYPE nDecl)
......
......@@ -615,11 +615,11 @@ void DecalManager::render()
SkyXEngine::Core::Data::MaterialsManager->Render(m_vDecals[i]->m_material, &SMMatrixIdentity(), 0);
SkyXEngine::Core::Data::Device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, m_vDecals[i]->iVertCount / 3, m_vDecals[i]->m_pVerts, sizeof(DecalVertex));
}*/
dev->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(DecalVertex));
DX_CALL(dev->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(DecalVertex)));
for(UINT i = 0; i < m_iRngs.size(); i++)
{
SGCore_MtlSet(m_iRngs[i].iMaterialId, &SMMatrixIdentity());
dev->DrawPrimitive(D3DPT_TRIANGLELIST, m_iRngs[i].iStartVertex, m_iRngs[i].iVertexCount / 3);
DX_CALL(dev->DrawPrimitive(D3DPT_TRIANGLELIST, m_iRngs[i].iStartVertex, m_iRngs[i].iVertexCount / 3));
}
dev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
......@@ -663,9 +663,9 @@ void DecalManager::updateBuffer()
return;
}
dev->CreateVertexBuffer(sizeof(DecalVertex)* iVC, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_pVertexBuffer, 0);
DX_CALL(dev->CreateVertexBuffer(sizeof(DecalVertex)* iVC, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_pVertexBuffer, 0));
DecalVertex * pData;
if(!FAILED(m_pVertexBuffer->Lock(0, sizeof(DecalVertex) * iVC, (void**)&pData, 0)))
if(!FAILED(DX_CALL(m_pVertexBuffer->Lock(0, sizeof(DecalVertex)* iVC, (void**)&pData, 0))))
{
iVC = 0;
for(AssotiativeArray<ID, Array<_DecalMatItem>>::Iterator i = m_MaterialSort.begin(); i; i++)
......
......@@ -89,12 +89,12 @@ void CTracer::render()
SGCore_GetDXDevice()->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
SGCore_GetDXDevice()->SetTexture(0, 0);
DX_CALL(SGCore_GetDXDevice()->SetTexture(0, 0));
// render m_iLineCount traces
for(int i = 0; i < m_iLineCount; ++i)
{
SGCore_GetDXDevice()->DrawPrimitiveUP(D3DPT_LINESTRIP, m_vpPoints[i].size() - 1, &(m_vpPoints[i][0]), sizeof(Point));
DX_CALL(SGCore_GetDXDevice()->DrawPrimitiveUP(D3DPT_LINESTRIP, m_vpPoints[i].size() - 1, &(m_vpPoints[i][0]), sizeof(Point)));
}
}
......
......@@ -37,8 +37,8 @@ CCrosshair::CCrosshair():
m_pVertices[1] = (Vertex*)&m_pMemoryBlob[(sizeof(Vertex)* iVC + sizeof(UINT)* iIC)];
m_pIndices[1] = (UINT*)&m_pMemoryBlob[sizeof(Vertex)* iVC + (sizeof(Vertex)* iVC + sizeof(UINT)* iIC)];
m_pDev->CreateVertexBuffer(sizeof(Vertex)* iVC, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_pVertexBuffer, NULL);
m_pDev->CreateIndexBuffer(sizeof(UINT)* iIC, D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, &m_pIndexBuffer, NULL);
DX_CALL(m_pDev->CreateVertexBuffer(sizeof(Vertex)* iVC, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_pVertexBuffer, NULL));
DX_CALL(m_pDev->CreateIndexBuffer(sizeof(UINT)* iIC, D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, &m_pIndexBuffer, NULL));
}
CCrosshair::~CCrosshair()
......@@ -356,8 +356,8 @@ void CCrosshair::render()
m_pDev->SetTransform(D3DTS_VIEW, (D3DMATRIX*)&SMMatrixIdentity());
m_pDev->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)&SMMatrixIdentity());
m_pDev->SetRenderState(D3DRS_ZENABLE, FALSE);
m_pDev->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(Vertex));
m_pDev->SetIndices(m_pIndexBuffer);
DX_CALL(m_pDev->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(Vertex)));
DX_CALL(m_pDev->SetIndices(m_pIndexBuffer));
m_pDev->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1);
m_pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
SGCore_ShaderUnBind();
......
......@@ -121,7 +121,7 @@ SX_LIB_API void SGame_0Create(HWND hWnd, bool isGame)
g_pGameData = new GameData(hWnd, isGame);
//g_pPlayer->spawn();
D3DXCreateBox(SGCore_GetDXDevice(), 1, 1, 1, &g_pFigureBox, 0);
DX_CALL(D3DXCreateBox(SGCore_GetDXDevice(), 1, 1, 1, &g_pFigureBox, 0));
Core_0RegisterConcmd("add_corner", ccmd_cam_pt);
Core_0RegisterConcmdArg("ent_save", ccmd_save_as);
......@@ -272,7 +272,7 @@ SX_LIB_API void SGame_EditorRender(ID id, ID id_sel_tex, const float3 *pvRenderP
SGCore_GetDXDevice()->SetFVF(D3DFVF_XYZ);
SGCore_GetDXDevice()->SetTexture(0, 0);
SGCore_GetDXDevice()->DrawPrimitiveUP(D3DPT_LINELIST, npoints, &(pts[0]), sizeof(float3_t));
DX_CALL(SGCore_GetDXDevice()->DrawPrimitiveUP(D3DPT_LINELIST, npoints, &(pts[0]), sizeof(float3_t)));
}
else
{
......@@ -284,8 +284,8 @@ SX_LIB_API void SGame_EditorRender(ID id, ID id_sel_tex, const float3 *pvRenderP
SGCore_GetDXDevice()->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)&mProj);
SGCore_GetDXDevice()->SetTransform(D3DTS_WORLD, (D3DMATRIX*)&(SMMatrixScaling(vBoxSize) * pEnt->getOrient().GetMatrix() * SMMatrixTranslation(pvRenderPos ? *pvRenderPos : pEnt->getPos()))/*bEnt->getWorldTM()*/);
SGCore_GetDXDevice()->SetTexture(0, SGCore_LoadTexGetTex(id_sel_tex));
g_pFigureBox->DrawSubset(0);
DX_CALL(SGCore_GetDXDevice()->SetTexture(0, SGCore_LoadTexGetTex(id_sel_tex)));
DX_CALL(g_pFigureBox->DrawSubset(0));
}
}
......@@ -379,6 +379,18 @@ SX_LIB_API BOOL SGame_AddWMsg(UINT message, WPARAM wParam, LPARAM lParam)
return(TRUE);
}
static const bool *s_pisWindowed = GET_PCVAR_BOOL("r_win_windowed");
if(!*s_pisWindowed && message >= WM_MOUSEFIRST && message <= WM_MOUSELAST)
{
POINT pt;
if(GetCursorPos(&pt))
{
short x = (short)pt.x;
short y = (short)pt.y;
lParam = (*((unsigned short*)&x)) | (*((unsigned short*)&y) << 16);
}
}
return(GameData::m_pGUI->putMessage(message, wParam, lParam));
}
......
......@@ -52,7 +52,7 @@ COcclusionCulling *g_pOC = 0;
void StdDrawIndexedPrimitive(UINT type_primitive, long base_vertexIndex, UINT min_vertex_index, UINT num_vertices, UINT start_index, UINT prim_count)
{
Core_RIntSet(G_RI_INT_COUNT_DIP, Core_RIntGet(G_RI_INT_COUNT_DIP) + 1);
g_pDXDevice->DrawIndexedPrimitive((D3DPRIMITIVETYPE)type_primitive, base_vertexIndex, min_vertex_index, num_vertices, start_index, prim_count);
DX_CALL(g_pDXDevice->DrawIndexedPrimitive((D3DPRIMITIVETYPE)type_primitive, base_vertexIndex, min_vertex_index, num_vertices, start_index, prim_count));
}
void StdMtlSet(ID id, const float4x4 *pWorld, const float4 *pColor)
......@@ -191,6 +191,7 @@ SX_LIB_API void SGCore_Dbg_Set(report_func rf)
SX_LIB_API void SGCore_0Create(const char *szName, HWND hWnd, int iWidth, int iHeigth, bool isWindowed, DWORD dwFlags, bool isUnic)
{
Core_SetOutPtr();
if (szName && strlen(szName) > 1)
{
if (isUnic)
......@@ -219,6 +220,15 @@ SX_LIB_API const DEVMODE* SGCore_GetModes(int *pCount)
return &(g_aModes[0]);
}
SX_LIB_API HRESULT SGCore_DXcallCheck(HRESULT hr, const char *callStr)
{
if(FAILED(hr))
{
printf(COLOR_LRED "DirectX call failed: %s\n%s, %s\n", callStr, DXGetErrorString9(hr), DXGetErrorDescription9(hr));
}
return(hr);
}
SX_LIB_API HWND SGCore_GetHWND()
{
return g_oD3DAPP.hDeviceWindow;
......
......@@ -20,6 +20,7 @@ See the license in LICENSE
#include <d3d9.h>
#include <d3dx9.h>
#include <dxerr9.h>
#if defined(_DEBUG)
#pragma comment(lib, "sxcore_d.lib")
......@@ -60,6 +61,8 @@ See the license in LICENSE
#define SXGC_ERR_FAILED_INIT_D3D -2
class IFrustum;
//! \name Базовые функции библиотеки
//!@{
......@@ -92,6 +95,10 @@ SX_LIB_API IDirect3DDevice9* SGCore_GetDXDevice();
//! возвращает массив всех доступных разрешений монитора, в iCount записывает размер массива
SX_LIB_API const DEVMODE* SGCore_GetModes(int *iCount);
//! Проверяет успешность вызова по HRESULT, выводит сообщение об ошибке
SX_LIB_API HRESULT SGCore_DXcallCheck(HRESULT hr, const char *callStr);
#define DX_CALL(call) SGCore_DXcallCheck((call), #call)
//!@}
......
......@@ -2,7 +2,6 @@
#include "IHTMLparser.h"
#include "IRenderFrame.h"
#include <gcore/sxgcore.h>
//#include "CDOM.h"
namespace gui
......@@ -59,8 +58,8 @@ namespace gui
void CDesktop::createRenderTarget()
{
GetGUI()->getDevice()->CreateRenderTarget(m_iWidth, m_iHeight, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_4_SAMPLES, 0, FALSE, &m_pRenderSurface, NULL);
GetGUI()->getDevice()->CreateDepthStencilSurface(m_iWidth, m_iHeight, D3DFMT_D24S8, D3DMULTISAMPLE_4_SAMPLES, 0, FALSE, &m_pDepthStencilSurface, NULL);
DX_CALL(GetGUI()->getDevice()->CreateRenderTarget(m_iWidth, m_iHeight, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_4_SAMPLES, 0, FALSE, &m_pRenderSurface, NULL));
DX_CALL(GetGUI()->getDevice()->CreateDepthStencilSurface(m_iWidth, m_iHeight, D3DFMT_D24S8, D3DMULTISAMPLE_4_SAMPLES, 0, FALSE, &m_pDepthStencilSurface, NULL));
m_txFinal = CTextureManager::createTexture(StringW(L"@") + m_sName, m_iWidth, m_iHeight, 32, true);
......@@ -98,12 +97,12 @@ namespace gui
CTextureManager::bindTexture(NULL);
IDirect3DSurface9 *pOldRT;
IDirect3DSurface9 *pOldDS;
GetGUI()->getDevice()->GetRenderTarget(0, &pOldRT);
GetGUI()->getDevice()->SetRenderTarget(0, m_pRenderSurface);
GetGUI()->getDevice()->GetDepthStencilSurface(&pOldDS);
GetGUI()->getDevice()->SetDepthStencilSurface(m_pDepthStencilSurface);
DX_CALL(GetGUI()->getDevice()->GetRenderTarget(0, &pOldRT));
DX_CALL(GetGUI()->getDevice()->SetRenderTarget(0, m_pRenderSurface));
DX_CALL(GetGUI()->getDevice()->GetDepthStencilSurface(&pOldDS));
DX_CALL(GetGUI()->getDevice()->SetDepthStencilSurface(m_pDepthStencilSurface));
GetGUI()->getDevice()->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_STENCIL, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
DX_CALL(GetGUI()->getDevice()->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_STENCIL, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0));
//GetGUI()->getDevice()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
//GetGUI()->getDevice()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO);
......@@ -115,8 +114,8 @@ namespace gui
m_pDoc->render();
GetGUI()->getDevice()->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE);
GetGUI()->getDevice()->SetRenderTarget(0, pOldRT);
GetGUI()->getDevice()->SetDepthStencilSurface(pOldDS);
DX_CALL(GetGUI()->getDevice()->SetRenderTarget(0, pOldRT));
DX_CALL(GetGUI()->getDevice()->SetDepthStencilSurface(pOldDS));
pOldRT->Release();
pOldDS->Release();
......@@ -124,9 +123,9 @@ namespace gui
IDirect3DSurface9 *pNewSurface;
m_txFinal->getAPItexture()->GetSurfaceLevel(0, &pNewSurface);
DX_CALL(m_txFinal->getAPItexture()->GetSurfaceLevel(0, &pNewSurface));
HRESULT hr = GetGUI()->getDevice()->StretchRect(m_pRenderSurface, NULL, pNewSurface, NULL, D3DTEXF_NONE);
DX_CALL(GetGUI()->getDevice()->StretchRect(m_pRenderSurface, NULL, pNewSurface, NULL, D3DTEXF_NONE));
pNewSurface->Release();
......@@ -195,8 +194,8 @@ namespace gui
GetGUI()->getDevice()->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1);
CTextureManager::bindShader(def_sh);
GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&float4_t(1.0f, 1.0f, 1.0f, 1.0f), 1);
GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &a, sizeof(point));
DX_CALL(GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&float4_t(1.0f, 1.0f, 1.0f, 1.0f), 1));
DX_CALL(GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &a, sizeof(point)));
GetGUI()->getDevice()->SetTransform(D3DTS_VIEW, reinterpret_cast<D3DMATRIX*>(&mOldView));
GetGUI()->getDevice()->SetTransform(D3DTS_PROJECTION, reinterpret_cast<D3DMATRIX*>(&mOldProj));
......
......@@ -1212,15 +1212,15 @@ namespace gui
}
VOID * pData;
GetGUI()->getDevice()->CreateVertexBuffer(sizeof(vertex) * iVertexCount, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, ppVertexBuffer, 0);
if(!FAILED((*ppVertexBuffer)->Lock(0, sizeof(vertex) * iVertexCount, (void**)&pData, 0)))
DX_CALL(GetGUI()->getDevice()->CreateVertexBuffer(sizeof(vertex)* iVertexCount, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, ppVertexBuffer, 0));
if(!FAILED(DX_CALL((*ppVertexBuffer)->Lock(0, sizeof(vertex)* iVertexCount, (void**)&pData, 0))))
{
memcpy(pData, pVB, sizeof(vertex) * iVertexCount);
(*ppVertexBuffer)->Unlock();
}
GetGUI()->getDevice()->CreateIndexBuffer(sizeof(UINT) * iIndexCount, D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, ppIndexBuffer, 0);
if(!FAILED((*ppIndexBuffer)->Lock(0, sizeof(UINT) * iIndexCount, (void**)&pData, 0)))
DX_CALL(GetGUI()->getDevice()->CreateIndexBuffer(sizeof(UINT)* iIndexCount, D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, ppIndexBuffer, 0));
if(!FAILED(DX_CALL((*ppIndexBuffer)->Lock(0, sizeof(UINT)* iIndexCount, (void**)&pData, 0))))
{
memcpy(pData, pIB, sizeof(UINT) * iIndexCount);
(*ppIndexBuffer)->Unlock();
......
......@@ -4,6 +4,7 @@
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <gcore/sxgcore.h>
#pragma comment(lib, "d3dcompiler.lib")
#pragma comment(lib, "d3d9.lib")
......@@ -13,6 +14,12 @@
# pragma comment(lib, "d3dx9.lib")
#endif
#if defined(_DEBUG)
# pragma comment(lib, "sxgcore_d.lib")
#else
# pragma comment(lib, "sxgcore.lib")
#endif
#if defined(_WINDOWS)
#pragma warning(disable:4244)
#endif
......
......@@ -124,8 +124,8 @@ namespace gui
if(need)
{
GetGUI()->getDevice()->SetFVF(D3DFVF_XYZ);
GetGUI()->getDevice()->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(float3_t));
GetGUI()->getDevice()->SetIndices(m_pIndexBuffer);
DX_CALL(GetGUI()->getDevice()->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(float3_t)));
DX_CALL(GetGUI()->getDevice()->SetIndices(m_pIndexBuffer));
}
// UINT iVC = 0;
......@@ -134,8 +134,8 @@ namespace gui
{
if(m_iWidth[i] != 0)
{
GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&m_pColor[i], 1);
GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, m_iVertexStart[i], 0, m_iVertexCount[i], m_iIndexStart[i], m_iIndexCount[i] / 3);
DX_CALL(GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&m_pColor[i], 1));
DX_CALL(GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, m_iVertexStart[i], 0, m_iVertexCount[i], m_iIndexStart[i], m_iIndexCount[i] / 3));
}
// iVC += m_iVertexCount[i];
// iIC += m_iIndexCount[i];
......@@ -145,14 +145,14 @@ namespace gui
// GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&float4_t(0.0f, 1.0f, 0.0f, 0.4f), 1);
// GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, iVC, iIC, m_iFillIndexCount / 3);
}
GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&float4_t(0.0f, 0.0f, 0.0f, 0.0f), 1);
DX_CALL(GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&float4_t(0.0f, 0.0f, 0.0f, 0.0f), 1));
}
void IRenderBorder::renderInnerFill()
{
GetGUI()->getDevice()->SetFVF(D3DFVF_XYZ);
GetGUI()->getDevice()->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(float3_t));
GetGUI()->getDevice()->SetIndices(m_pIndexBuffer);
DX_CALL(GetGUI()->getDevice()->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(float3_t)));
DX_CALL(GetGUI()->getDevice()->SetIndices(m_pIndexBuffer));
static CSHADER shText = CTextureManager::loadShader(L"text");
......@@ -165,8 +165,8 @@ namespace gui
}
CTextureManager::bindShader(shText);
GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&float4_t(1.0f, 1.0f, 1.0f, 1.0f), 1);
GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, iVC, iIC, m_iFillIndexCount / 3);
DX_CALL(GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&float4_t(1.0f, 1.0f, 1.0f, 1.0f), 1));
DX_CALL(GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, iVC, iIC, m_iFillIndexCount / 3));
}
void IRenderBorder::build()
......@@ -381,8 +381,8 @@ namespace gui
UINT iCV = 0;
UINT iCI = 0;
VOID * pData;
GetGUI()->getDevice()->CreateVertexBuffer(sizeof(float3_t) * iVertexCount, NULL, NULL, D3DPOOL_MANAGED, &m_pVertexBuffer, 0);
if(!FAILED(m_pVertexBuffer->Lock(0, sizeof(float3_t) * iVertexCount, (void**)&pData, 0)))
DX_CALL(GetGUI()->getDevice()->CreateVertexBuffer(sizeof(float3_t)* iVertexCount, NULL, NULL, D3DPOOL_MANAGED, &m_pVertexBuffer, 0));
if(!FAILED(DX_CALL(m_pVertexBuffer->Lock(0, sizeof(float3_t)* iVertexCount, (void**)&pData, 0))))
{
memcpy((float3_t*)pData + iCV, t->vb[0], sizeof(float3_t) * t->iVC[0]);
iCV += t->iVC[0];
......@@ -396,8 +396,8 @@ namespace gui
m_pVertexBuffer->Unlock();
}
GetGUI()->getDevice()->CreateIndexBuffer(sizeof(UINT) * iIndexCount, NULL, D3DFMT_INDEX32, D3DPOOL_MANAGED, &m_pIndexBuffer, 0);
if(!FAILED(m_pIndexBuffer->Lock(0, sizeof(UINT) * iIndexCount, (void**)&pData, 0)))
DX_CALL(GetGUI()->getDevice()->CreateIndexBuffer(sizeof(UINT)* iIndexCount, NULL, D3DFMT_INDEX32, D3DPOOL_MANAGED, &m_pIndexBuffer, 0));
if(!FAILED(DX_CALL(m_pIndexBuffer->Lock(0, sizeof(UINT)* iIndexCount, (void**)&pData, 0))))
{
memcpy((UINT*)pData + iCI, t->ib[0], sizeof(UINT) * t->iIC[0]);
iCI += t->iIC[0];
......
......@@ -1300,7 +1300,7 @@ namespace gui
}
GetGUI()->getDevice()->SetRenderState(D3DRS_STENCILREF, lvl);
GetGUI()->getDevice()->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1);
GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&m_pBackgroundColor, 1);
DX_CALL(GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&m_pBackgroundColor, 1));
GetGUI()->getDevice()->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
......@@ -1309,13 +1309,13 @@ namespace gui
{
CTextureManager::bindShader(shText);
CTextureManager::bindTexture(texWhite);
GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, m_iTCBackground, &m_pVBackground, sizeof(pointtex));
DX_CALL(GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, m_iTCBackground, &m_pVBackground, sizeof(pointtex)));
}
if(m_bHasBackgroundImage)
{
CTextureManager::unbindShader();
CTextureManager::bindTexture(m_pBackgroundImage);
GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, m_iTCBackground, &m_pVBackground, sizeof(pointtex));
DX_CALL(GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, m_iTCBackground, &m_pVBackground, sizeof(pointtex)));
}
CTranslationManager::popMatrix();
......@@ -1766,7 +1766,7 @@ namespace gui
{
GetGUI()->getDevice()->SetRenderState(D3DRS_COLORWRITEENABLE, FALSE);
GetGUI()->getDevice()->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_DECR);
GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &a, sizeof(point));
DX_CALL(GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &a, sizeof(point)));
GetGUI()->getDevice()->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
GetGUI()->getDevice()->SetRenderState(D3DRS_COLORWRITEENABLE, 0x0F);
if(lvl == 0)
......@@ -2037,7 +2037,7 @@ namespace gui
{
GetGUI()->getDevice()->SetRenderState(D3DRS_COLORWRITEENABLE, FALSE);
GetGUI()->getDevice()->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_DECR);
GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &a, sizeof(point));
DX_CALL(GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &a, sizeof(point)));
GetGUI()->getDevice()->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
GetGUI()->getDevice()->SetRenderState(D3DRS_COLORWRITEENABLE, 0x0F);
if(lvl == 0)
......@@ -2207,9 +2207,9 @@ namespace gui
//SMMATRIX m = SMMatrixTranslation(m_pParent->GetLeftOffset(), m_pParent->GetTopOffset(), 0.0f);
//GetGUI()->getDevice()->SetTransform(D3DTS_WORLD, reinterpret_cast<D3DMATRIX*>(&m));
CTextureManager::bindTexture(pFont->getTexture(0));
GetGUI()->getDevice()->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(CFont::vertex));
GetGUI()->getDevice()->SetIndices(m_pIndexBuffer);
GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, m_iVertexCount, 0, m_iIndexBaseCount / 3);
DX_CALL(GetGUI()->getDevice()->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(CFont::vertex)));
DX_CALL(GetGUI()->getDevice()->SetIndices(m_pIndexBuffer));
DX_CALL(GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, m_iVertexCount, 0, m_iIndexBaseCount / 3));
CTextureManager::bindTexture(texWhite);
......@@ -2337,7 +2337,7 @@ namespace gui
float4_t vColor = m_pStyle->color->getColor();
float4_t vShadowColor = m_pStyle->text_shadow_color->isSet() ? m_pStyle->text_shadow_color->getColor() : vColor;
GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&vColor, 1);
DX_CALL(GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&vColor, 1));
for(UINT i = 0; i < m_pRenderElems.size(); i++)
{
CRenderElement * el = &m_pRenderElems[i];
......@@ -2348,24 +2348,24 @@ namespace gui
{
CTranslationManager::pushMatrix(SMMatrixTranslation(el->m_pNextREl->m_iLeftOffset, el->m_pNextREl->m_iTopOffset, 0.0f));
CTextureManager::bindTexture(pShadowFont->getTexture(0));
GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&vShadowColor, 1);
DX_CALL(GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&vShadowColor, 1));
GetGUI()->getDevice()->SetStreamSource(0, el->m_pNextREl->m_pVertexBuffer, 0, sizeof(CFont::vertex));
GetGUI()->getDevice()->SetIndices(el->m_pNextREl->m_pIndexBuffer);
GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, el->m_pNextREl->m_iVertexCount, 0, el->m_pNextREl->m_iIndexBaseCount / 3);
DX_CALL(GetGUI()->getDevice()->SetStreamSource(0, el->m_pNextREl->m_pVertexBuffer, 0, sizeof(CFont::vertex)));
DX_CALL(GetGUI()->getDevice()->SetIndices(el->m_pNextREl->m_pIndexBuffer));
DX_CALL(GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, el->m_pNextREl->m_iVertexCount, 0, el->m_pNextREl->m_iIndexBaseCount / 3));
GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&vColor, 1);
DX_CALL(GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&vColor, 1));
CTranslationManager::popMatrix();
}
CTextureManager::bindTexture(pFont->getTexture(0));
GetGUI()->getDevice()->SetStreamSource(0, el->m_pVertexBuffer, 0, sizeof(CFont::vertex));
GetGUI()->getDevice()->SetIndices(el->m_pIndexBuffer);
GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, el->m_iVertexCount, 0, el->m_iIndexBaseCount / 3);
DX_CALL(GetGUI()->getDevice()->SetStreamSource(0, el->m_pVertexBuffer, 0, sizeof(CFont::vertex)));
DX_CALL(GetGUI()->getDevice()->SetIndices(el->m_pIndexBuffer));
DX_CALL(GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, el->m_iVertexCount, 0, el->m_iIndexBaseCount / 3));
if(el->m_iIndexAddCount)
{
CTextureManager::bindTexture(texWhite);
GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, el->m_iVertexCount, el->m_iIndexBaseCount, el->m_iIndexAddCount / 3);
DX_CALL(GetGUI()->getDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, el->m_iVertexCount, el->m_iIndexBaseCount, el->m_iIndexAddCount / 3));
}
CTranslationManager::popMatrix();
......@@ -2773,9 +2773,9 @@ namespace gui
float op = sinf((float)GetTickCount() * 0.003f);
op *= op;
color.w = op;
GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&color, 1);
DX_CALL(GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&color, 1));
CTranslationManager::pushMatrix(SMMatrixTranslation(_x - 1.0f, _y, 0.0f));
GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &a, sizeof(point));
DX_CALL(GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &a, sizeof(point)));
CTranslationManager::popMatrix();
int _w = m_pParent->getInnerWidth();
......@@ -2925,7 +2925,7 @@ namespace gui
selEnd = m_vCharRects.size();
}
GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&color, 1);
DX_CALL(GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&color, 1));
for(UINT i = selStart; i < selEnd; i++)
{
......
......@@ -21,6 +21,7 @@
#include <chrono>
typedef std::chrono::system_clock::time_point time_point;
namespace gui
{
CPITexture def_w;
......
......@@ -26,7 +26,7 @@ namespace gui
CTextureManager::bindShader(shText);
CTextureManager::bindTexture(texWhite);
float4_t asd(1, 1, 1, 0.5);
GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&asd, 1);
DX_CALL(GetGUI()->getDevice()->SetPixelShaderConstantF(0, (float*)&asd, 1));
updateData();
if(m_iScrollMax == 0)
......@@ -68,7 +68,7 @@ namespace gui
}
}
GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &a, sizeof(point));
DX_CALL(GetGUI()->getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, &a, sizeof(point)));
}
void CScrollBarSimple::dispatchEvent(IEvent & ev)
......
......@@ -37,7 +37,7 @@ namespace gui
CTexture * CTextureManager::createTexture(const StringW & szTexture, int w, int h, int bpp, bool isRT)
{
CTexture bt;
if(FAILED(GetGUI()->getDevice()->CreateTexture(w, h, isRT ? 1 : 0, isRT ? D3DUSAGE_RENDERTARGET : 0, D3DFMT_A8R8G8B8, isRT ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED, &bt.m_pTexture, NULL)))
if(FAILED(DX_CALL(GetGUI()->getDevice()->CreateTexture(w, h, isRT ? 1 : 0, isRT ? D3DUSAGE_RENDERTARGET : 0, D3DFMT_A8R8G8B8, isRT ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED, &bt.m_pTexture, NULL))))
{
return(NULL);
}
......@@ -71,14 +71,14 @@ namespace gui
if(!tex)
{
//FIXME: Set fallback texture
GetGUI()->getDevice()->SetTexture(0, NULL);
DX_CALL(GetGUI()->getDevice()->SetTexture(0, NULL));
m_pCurrentTex = NULL;
return;
}
if(m_pCurrentTex != tex)
{
m_pCurrentTex = tex;
GetGUI()->getDevice()->SetTexture(0, m_pCurrentTex->m_pTexture);
DX_CALL(GetGUI()->getDevice()->SetTexture(0, m_pCurrentTex->m_pTexture));
}
......@@ -143,7 +143,7 @@ namespace gui
fclose(pF);
}