784 lines
24 KiB
C++
784 lines
24 KiB
C++
// ShaderEditorToolbarDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "ShaderEditor.h"
|
|
#include "ShaderEditorToolbarDlg.h"
|
|
#include "ShaderEditorDlg.h"
|
|
|
|
#include "CKHideContentManager.h"
|
|
|
|
#define ULONG_PTR DWORD
|
|
#include <XBoxDbg.h>
|
|
|
|
#include "mCppLib.h"
|
|
|
|
#pragma comment(lib,"XboxDbg.lib")
|
|
#pragma comment(lib,"delayimp.lib")
|
|
|
|
unsigned int CompileFx(const char *shaderName,const char*cmd, const XString& xsIn,XString& compileErr);
|
|
unsigned int CompileFxXBox(const char *shaderName,const char*cmd, const XString& xsIn,XString& compileErr);
|
|
unsigned int CompileFxXenon(const char *shaderName,const char*cmd, const XString& xsIn,XString& compileErr);
|
|
|
|
HRESULT (__stdcall *XboxDmSendFile)(LPCSTR szLocalName,LPCSTR szRemoteName)= NULL;
|
|
HRESULT (__stdcall *XboxDmSetConnectionTimeout)(DWORD dwConnectTimeout,DWORD dwConversationTimeout) = NULL;
|
|
HRESULT (__stdcall *XboxDmOpenConnection)(PDM_CONNECTION *ppConnection) = NULL;
|
|
HRESULT (__stdcall *XboxDmDedicateConnection)(PDM_CONNECTION pdcon,LPCSTR szHandler) = NULL;
|
|
HRESULT (__stdcall *XboxDmSendCommand)(PDM_CONNECTION pConnection,LPCSTR szCommand,LPSTR szResponse,LPDWORD lpdwResponseSize)= NULL;
|
|
HRESULT (__stdcall *XboxDmCloseConnection)(PDM_CONNECTION pConnection) = NULL;
|
|
|
|
|
|
HRESULT (__stdcall *XenonDmSendFile)(LPCSTR szLocalName,LPCSTR szRemoteName)= NULL;
|
|
HRESULT (__stdcall *XenonDmSetConnectionTimeout)(DWORD dwConnectTimeout,DWORD dwConversationTimeout) = NULL;
|
|
HRESULT (__stdcall *XenonDmOpenConnection)(PDM_CONNECTION *ppConnection) = NULL;
|
|
HRESULT (__stdcall *XenonDmDedicateConnection)(PDM_CONNECTION pdcon,LPCSTR szHandler) = NULL;
|
|
HRESULT (__stdcall *XenonDmSendCommand)(PDM_CONNECTION pConnection,LPCSTR szCommand,LPSTR szResponse,LPDWORD lpdwResponseSize)= NULL;
|
|
HRESULT (__stdcall *XenonDmCloseConnection)(PDM_CONNECTION pConnection) = NULL;
|
|
|
|
|
|
#ifdef _MFCDEBUGNEW
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
#endif
|
|
|
|
bool sXBoxDebugPresent = FALSE;
|
|
bool sXenonDebugPresent = FALSE;
|
|
|
|
typedef unsigned int (*COMPILEFXFUNC) (const char *shaderName,const char*cmd, const XString& xsIn,XString& compileErr);
|
|
|
|
unsigned int CompileFxForXBox(const XString& xsIn,XString& compileErr);
|
|
char* XBDMErrToString(DWORD err);
|
|
|
|
#define COMMANDPREFIX "XSHA!"
|
|
|
|
|
|
|
|
//-------------------------------
|
|
//DIALOG CREATION FUNC FOR EXPORT
|
|
DllToolbarDlg* fCreateToolbarDlg(HWND parent/*, CKContext* ctx*/)
|
|
{
|
|
ShaderEditorToolbarDlg* dlg;
|
|
HRESULT r = CreateDllDialog(parent,IDD_SHADEREDITORTOOLBAR,&dlg);
|
|
return (DllToolbarDlg*)dlg;
|
|
}
|
|
//DIALOG CREATION FUNC FOR EXPORT
|
|
//-------------------------------
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// ShaderEditorToolbarDlg dialog
|
|
|
|
|
|
ShaderEditorToolbarDlg::ShaderEditorToolbarDlg(CWnd* pParent /*=NULL*/)
|
|
: DllToolbarDlg(ShaderEditorToolbarDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(ShaderEditorToolbarDlg)
|
|
//}}AFX_DATA_INIT
|
|
}
|
|
|
|
|
|
void ShaderEditorToolbarDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
DllToolbarDlg::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(ShaderEditorToolbarDlg)
|
|
DDX_Control(pDX, IDC_SAVE_SHADER, m_SaveShader);
|
|
DDX_Control(pDX, IDC_LOAD_SHADER, m_LoadShader);
|
|
DDX_Control(pDX, IDC_COMPILED_OUTPUT, m_CompiledOutput);
|
|
DDX_Control(pDX, IDC_COMPILE_ALL, m_CompileAll);
|
|
DDX_Control(pDX, IDC_COMPILE, m_Compile);
|
|
DDX_Control(pDX, IDC_Hide, m_Hide);
|
|
DDX_Control(pDX, IDC_CLARIFY, m_Clarify);
|
|
DDX_Control(pDX, IDC_NEW_SHADER, m_NewShader);
|
|
DDX_Control(pDX, IDC_STATIC_SHADER_MODE, m_StaticTextShaderCplMode);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(ShaderEditorToolbarDlg, DllToolbarDlg)
|
|
//{{AFX_MSG_MAP(ShaderEditorToolbarDlg)
|
|
ON_BN_CLICKED(IDC_NEW_SHADER, OnNewShader)
|
|
ON_BN_CLICKED(IDC_COMPILE, OnCompile)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT, OnCompiledOutput)
|
|
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_VS_1_1, OnCompiledOutputVS_1_1)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_VS_2_0, OnCompiledOutputVS_2_0)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_VS_3_0, OnCompiledOutputVS_3_0)
|
|
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_PS_1_1, OnCompiledOutputPS_1_1)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_PS_1_2, OnCompiledOutputPS_1_2)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_PS_1_3, OnCompiledOutputPS_1_3)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_PS_1_4, OnCompiledOutputPS_1_4)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_PS_2_0, OnCompiledOutputPS_2_0)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_PS_3_0, OnCompiledOutputPS_3_0)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_FX_2_0, OnCompiledOutputFX_2_0)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_FX_2_0_NOPRE, OnCompiledOutputFX_2_0_NOPRE)
|
|
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_ARBVP1, OnCompiledOutputARBVP1)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_NV_VP20, OnCompiledOutputNV_VP20)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_NV_VP30, OnCompiledOutputNV_VP30)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_NV_VP40, OnCompiledOutputNV_VP40)
|
|
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_ARBFP1, OnCompiledOutputARBFP1)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_NV_FP20, OnCompiledOutputNV_FP20)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_NV_FP30, OnCompiledOutputNV_FP30)
|
|
ON_BN_CLICKED(IDC_COMPILED_OUTPUT_NV_FP40, OnCompiledOutputNV_FP40)
|
|
|
|
ON_BN_CLICKED(IDC_LOAD_SHADER, OnLoadShader)
|
|
ON_BN_CLICKED(IDC_SAVE_SHADER, OnSaveShader)
|
|
ON_BN_CLICKED(IDC_COMPILE_ALL, OnCompileAll)
|
|
ON_BN_CLICKED(IDC_CLOSE_ASM_WINDOW, OnCloseAsmWindow)
|
|
|
|
ON_WM_CONTEXTMENU()
|
|
ON_BN_CLICKED(IDC_COMPILE_FOR_XENON, OnCompileForXenon)
|
|
ON_BN_CLICKED(IDC_COMPILE_FOR_XBOX, OnCompileForXBox)
|
|
ON_BN_CLICKED(IDC_COMPILE_FOR_DX81, OnCompileForDX81)
|
|
ON_BN_CLICKED(IDC_COMPILE_FOR_DX80, OnCompileForDX80)
|
|
ON_BN_CLICKED(IDC_COMPILE_FOR_DX9 , OnCompileForDX9)
|
|
ON_BN_CLICKED(IDC_COMPILE_FOR_CG , OnCompileForCG)
|
|
|
|
ON_BN_CLICKED(IDC_Hide, &ShaderEditorToolbarDlg::OnBnClickedHide)
|
|
ON_BN_CLICKED(IDC_CLARIFY, &ShaderEditorToolbarDlg::OnBnClickedClarify)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
//toolbarheight default is 21
|
|
#define CHECKRECT(wnd) \
|
|
wnd.GetClientRect(&r2); \
|
|
wnd.MapWindowPoints(this,&r2); \
|
|
if (r2.top<2) \
|
|
r2.top=2; \
|
|
if (r2.bottom>18) \
|
|
r2.bottom=18; \
|
|
wnd.MoveWindow(&r2); \
|
|
|
|
void ShaderEditorToolbarDlg::CheckToolbarItemSize()
|
|
{
|
|
RECT r,r2;
|
|
GetClientRect(&r);
|
|
CHECKRECT(m_CompileAll);
|
|
CHECKRECT(m_Compile);
|
|
CHECKRECT(m_Hide);
|
|
CHECKRECT(m_Clarify);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// ShaderEditorToolbarDlg message handlers
|
|
|
|
void ShaderEditorToolbarDlg::OnInterfaceInit()
|
|
{
|
|
CheckToolbarItemSize();
|
|
ActivateClosebutton();
|
|
|
|
if(NULL != m_XboxLib.Load("XboxDbg.dll")){
|
|
sXBoxDebugPresent = TRUE;
|
|
*(void**)&XboxDmSendFile = m_XboxLib.GetFunctionPtr("DmSendFileA");
|
|
*(void**)&XboxDmSetConnectionTimeout= m_XboxLib.GetFunctionPtr("DmSetConnectionTimeout");
|
|
*(void**)&XboxDmOpenConnection= m_XboxLib.GetFunctionPtr("DmOpenConnection");
|
|
*(void**)&XboxDmDedicateConnection= m_XboxLib.GetFunctionPtr("DmDedicateConnection");
|
|
*(void**)&XboxDmSendCommand= m_XboxLib.GetFunctionPtr("DmSendCommand");
|
|
*(void**)&XboxDmCloseConnection= m_XboxLib.GetFunctionPtr("DmCloseConnection");
|
|
}
|
|
|
|
if(NULL != m_XenonLib.Load("xbdm.dll")){
|
|
sXenonDebugPresent = TRUE;
|
|
|
|
*(void**)&XenonDmSendFile = m_XenonLib.GetFunctionPtr("DmSendFileA");
|
|
*(void**)&XenonDmSetConnectionTimeout= m_XenonLib.GetFunctionPtr("DmSetConnectionTimeout");
|
|
*(void**)&XenonDmOpenConnection= m_XenonLib.GetFunctionPtr("DmOpenConnection");
|
|
*(void**)&XenonDmDedicateConnection= m_XenonLib.GetFunctionPtr("DmDedicateConnection");
|
|
*(void**)&XenonDmSendCommand= m_XenonLib.GetFunctionPtr("DmSendCommand");
|
|
*(void**)&XenonDmCloseConnection= m_XenonLib.GetFunctionPtr("DmCloseConnection");
|
|
}
|
|
|
|
m_Editor = (ShaderEditorDlg*)m_EditorDlg;
|
|
EnableToolTips(TRUE);
|
|
{
|
|
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
|
m_NewShader.SetBitmaps(IDB_NEW_FILE1, IDB_NEW_FILE2, IDB_NEW_FILE3,
|
|
IDB_NEW_FILE1, IDB_NEW_FILE1);
|
|
m_SaveShader.SetBitmaps(IDB_SAVE_FILE1, IDB_SAVE_FILE2, IDB_SAVE_FILE3,
|
|
IDB_SAVE_FILE1, IDB_SAVE_FILE1);
|
|
m_LoadShader.SetBitmaps(IDB_OPEN_FILE1, IDB_OPEN_FILE2, IDB_OPEN_FILE3,
|
|
IDB_OPEN_FILE1, IDB_OPEN_FILE1);
|
|
m_CompiledOutput.SetBitmaps(IDB_COMPILE1, IDB_COMPILE2, IDB_COMPILE3,
|
|
IDB_COMPILE3, IDB_COMPILE1);
|
|
}
|
|
|
|
m_Tooltip.Create(this);
|
|
m_Tooltip.Activate(TRUE);
|
|
m_Tooltip.AddTool(&m_NewShader, "New Shader");
|
|
m_Tooltip.AddTool(&m_LoadShader, "Load Shader from a file");
|
|
m_Tooltip.AddTool(&m_SaveShader, "Save Shader in a file");
|
|
m_Tooltip.AddTool(&m_CompiledOutput, "Show assembly result of compiled shader function (select the function name)");
|
|
m_Tooltip.SetDelayTime(TTDT_INITIAL, 50);
|
|
m_Tooltip.SetDelayTime(TTDT_AUTOPOP, 5000);
|
|
m_Tooltip.SetWindowPos(&(CWnd::wndTopMost), 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
|
|
m_Tooltip.SendMessage(TTM_SETMAXTIPWIDTH, 0, 500);
|
|
|
|
{
|
|
RECT r;
|
|
m_StaticTextShaderCplMode.GetWindowRect(&r);
|
|
ScreenToClient(&r);
|
|
m_StaticTextShaderCplMode.SetWindowPos(0,r.left,4,r.right-r.left,16,SWP_NOZORDER);
|
|
m_StaticTextShaderCplMode.SetColors(CZC_WHITE,CZC_TOOLBARBACK,CZC_TOOLBARBACK,CZC_TOOLBARBACK,GetVIBrush(CZC_TOOLBARBACK),GetVIBrush(CZC_TOOLBARBACK));
|
|
|
|
if (m_Editor->GetShaderManagerType() == CKSM_HLSL)
|
|
m_StaticTextShaderCplMode.SetWindowText("HLSL");
|
|
else
|
|
m_StaticTextShaderCplMode.SetWindowText("CgFX");
|
|
}
|
|
}
|
|
|
|
void ShaderEditorToolbarDlg::OnInterfaceEnd()
|
|
{
|
|
if (sXBoxDebugPresent )
|
|
m_XboxLib.ReleaseLibrary();
|
|
|
|
if (sXBoxDebugPresent )
|
|
m_XenonLib.ReleaseLibrary();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void ShaderEditorToolbarDlg::OnNewShader()
|
|
{
|
|
m_Editor->OnNewShader();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void ShaderEditorToolbarDlg::OnCompile()
|
|
{
|
|
m_Editor->UpdateShaderText();
|
|
m_Editor->CompileShader(NULL);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void ShaderEditorToolbarDlg::OnCompileAll()
|
|
{
|
|
m_Editor->CompileAllShaders();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void ShaderEditorToolbarDlg::OnLoadShader()
|
|
{
|
|
m_Editor->OnImportShader();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void ShaderEditorToolbarDlg::OnSaveShader()
|
|
{
|
|
m_Editor->OnExportShader();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void ShaderEditorToolbarDlg::OnCompiledOutput()
|
|
{
|
|
HWND hwnd;
|
|
GetDlgItem(IDC_COMPILED_OUTPUT, &hwnd);
|
|
RECT rect;
|
|
::GetWindowRect(hwnd, &rect);
|
|
|
|
m_Popup.Attach(this);
|
|
m_Popup.Empty();
|
|
|
|
CString sname = m_Editor->m_Editor.GetSelText();
|
|
|
|
//--- Nothing selected
|
|
if( !sname.GetLength() ){
|
|
|
|
m_Popup.AddItem("You can HIGHLIGHT a function name to see ASM",0, FALSE, FALSE, FALSE );
|
|
m_Popup.AddSeparator();
|
|
if ( m_Editor->GetShaderType() == CKSM_HLSL) {
|
|
m_Popup.AddItem("Whole Effect ASM", IDC_COMPILED_OUTPUT_FX_2_0);
|
|
m_Popup.AddItem("Whole Effect ASM no PreShader", IDC_COMPILED_OUTPUT_FX_2_0_NOPRE);
|
|
}
|
|
|
|
//--- Ok Something have have been selected
|
|
} else {
|
|
m_Popup.AddItem("Compile using:",0, FALSE, FALSE, FALSE );
|
|
|
|
m_Popup.AddSeparator();
|
|
|
|
//--- Switch between different compilation profile
|
|
if ( m_Editor->GetShaderType() == CKSM_HLSL)
|
|
{
|
|
//--- DirectX compilation profile
|
|
m_Popup.AddItem("vs_1_1", IDC_COMPILED_OUTPUT_VS_1_1);
|
|
m_Popup.AddItem("vs_2_0", IDC_COMPILED_OUTPUT_VS_2_0);
|
|
m_Popup.AddItem("vs_3_0", IDC_COMPILED_OUTPUT_VS_3_0);
|
|
m_Popup.AddItem("ps_1_1", IDC_COMPILED_OUTPUT_PS_1_1);
|
|
m_Popup.AddItem("ps_1_2", IDC_COMPILED_OUTPUT_PS_1_2);
|
|
m_Popup.AddItem("ps_1_3", IDC_COMPILED_OUTPUT_PS_1_3);
|
|
m_Popup.AddItem("ps_1_4", IDC_COMPILED_OUTPUT_PS_1_4);
|
|
m_Popup.AddItem("ps_2_0", IDC_COMPILED_OUTPUT_PS_2_0);
|
|
m_Popup.AddItem("ps_3_0", IDC_COMPILED_OUTPUT_PS_3_0);
|
|
|
|
m_Popup.AddSeparator();
|
|
|
|
m_Popup.AddItem("Whole Effect ASM", IDC_COMPILED_OUTPUT_FX_2_0);
|
|
m_Popup.AddItem("Whole Effect ASM no PreShader", IDC_COMPILED_OUTPUT_FX_2_0_NOPRE);
|
|
}
|
|
else
|
|
{
|
|
//--- OpenGl compilation profile
|
|
m_Popup.AddItem("arbvp1", IDC_COMPILED_OUTPUT_ARBVP1);
|
|
m_Popup.AddItem("vp20", IDC_COMPILED_OUTPUT_NV_VP20);
|
|
m_Popup.AddItem("vp30", IDC_COMPILED_OUTPUT_NV_VP30);
|
|
m_Popup.AddItem("vp40", IDC_COMPILED_OUTPUT_NV_VP40);
|
|
m_Popup.AddItem("arbfp1", IDC_COMPILED_OUTPUT_ARBFP1);
|
|
m_Popup.AddItem("fp20", IDC_COMPILED_OUTPUT_NV_FP20);
|
|
m_Popup.AddItem("fp30", IDC_COMPILED_OUTPUT_NV_FP30);
|
|
m_Popup.AddItem("fp40", IDC_COMPILED_OUTPUT_NV_FP40);
|
|
}
|
|
}
|
|
|
|
//--- Output window is already visible, so user surely knows that he has
|
|
///// to select a function name
|
|
if( m_Editor->m_SplitEditorTitle.GetColumnCount() >= 2 ){
|
|
m_Popup.AddSeparator();
|
|
m_Popup.AddItem("Close ASM window", IDC_CLOSE_ASM_WINDOW, FALSE, FALSE, FALSE );
|
|
}
|
|
|
|
m_Popup.Show(rect.right, rect.top);
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void ShaderEditorToolbarDlg::OnContextMenu(CWnd* pWnd,CPoint pos){
|
|
HWND hwnd;
|
|
GetDlgItem(IDC_COMPILE, &hwnd);
|
|
RECT rect;
|
|
::GetWindowRect(hwnd, &rect);
|
|
|
|
if(PtInRect(&rect,pos) && (sXBoxDebugPresent || sXenonDebugPresent)){
|
|
m_Popup.Attach(this);
|
|
m_Popup.Empty();
|
|
if(sXBoxDebugPresent){
|
|
m_Popup.AddItem("Check syntax for : ",0, FALSE, FALSE, FALSE );
|
|
|
|
m_Popup.AddSeparator();
|
|
|
|
m_Popup.AddItem("Dx 8.0", IDC_COMPILE_FOR_DX80);
|
|
m_Popup.AddItem("Dx 8.1", IDC_COMPILE_FOR_DX81);
|
|
//m_Popup.AddItem("Dx 9.0", IDC_COMPILE_FOR_DX9);
|
|
//m_Popup.AddItem("Cg", IDC_COMPILE_FOR_CG);
|
|
|
|
m_Popup.AddItem("Compile and Update Shader on XBox", IDC_COMPILE_FOR_XBOX);
|
|
}
|
|
|
|
if(sXenonDebugPresent)
|
|
m_Popup.AddItem("Compile and Update Shader on Xenon", IDC_COMPILE_FOR_XENON);
|
|
|
|
m_Popup.Show(rect.right, rect.top);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void XStringToTokenList(const XString& prefix,const XString &xs, XClassArray<XString>& output){
|
|
XStringTokenizer tokizer(xs.CStr(), "\n");
|
|
const char *tok = NULL;
|
|
while ((tok = tokizer.NextToken(tok)) != NULL){
|
|
output.PushBack(prefix + XString(" ") + XString(tok));
|
|
}
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void ShaderEditorToolbarDlg::OnCompileForXBox(){
|
|
CompileWithPreprocessing("xbec.exe","-D XBOX -D D3DX_VERSION=0x0800 -D DIRECT3D_VERSION=0x0800",CompileFxXBox);
|
|
}
|
|
|
|
void ShaderEditorToolbarDlg::OnCompileForXenon(){
|
|
CompileWithPreprocessing(NULL,"",CompileFxXenon);
|
|
}
|
|
|
|
|
|
void ShaderEditorToolbarDlg::OnCompileForDX81(){
|
|
CompileWithPreprocessing("x81ec.exe","-D D3DX_VERSION=0x0800 -D DIRECT3D_VERSION=0x0800",CompileFx);
|
|
}
|
|
|
|
void ShaderEditorToolbarDlg::OnCompileForDX80(){
|
|
CompileWithPreprocessing("x80ec.exe","-D D3DX_VERSION=0x0800 -D DIRECT3D_VERSION=0x0800",CompileFx);
|
|
}
|
|
|
|
|
|
void ShaderEditorToolbarDlg::OnCompileForDX9(){
|
|
CompileWithPreprocessing("x9ec.exe","-D D3DX_VERSION=0x0901 -D DIRECT3D_VERSION=0x0900",CompileFx);
|
|
}
|
|
|
|
void ShaderEditorToolbarDlg::OnCompileForCG(){
|
|
CompileWithPreprocessing("cgfxec.exe","",CompileFx);
|
|
}
|
|
|
|
|
|
void ShaderEditorToolbarDlg::CompileWithPreprocessing(const char* cmd,const char* ppOpt,COMPILEFXFUNC func){
|
|
|
|
m_Editor->UpdateShaderText();
|
|
|
|
// Preprocess File
|
|
XString PreProcErr;
|
|
XString PreProcessed;
|
|
XClassArray<XString> output;
|
|
HRESULT hr = S_OK;
|
|
|
|
CKShader* rfx = m_Editor->GetCurrentShader();
|
|
if(cmd){
|
|
hr = mCppLib_PreProcess(rfx->GetText(),ppOpt, PreProcessed, PreProcErr);
|
|
|
|
if(hr && PreProcErr.Length()){
|
|
// an error occurred during preprocessing
|
|
XStringToTokenList(rfx->GetName(),PreProcErr,output);
|
|
output.PushBack(rfx->GetName() + ": Shader compilation failed.");
|
|
m_Editor->SetErrorList(output);
|
|
return ;
|
|
}
|
|
}else{
|
|
PreProcessed = rfx->GetText();
|
|
}
|
|
|
|
// Call external Compiler
|
|
XString compileError;
|
|
hr = func(rfx->GetName().CStr(),cmd,PreProcessed,compileError);
|
|
if(hr && compileError.Length()){
|
|
// an error occurred during preprocessing
|
|
XStringToTokenList(rfx->GetName(),compileError,output);
|
|
output.PushBack(rfx->GetName() + ": Shader compilation failed.");
|
|
m_Editor->SetErrorList(output);
|
|
return;
|
|
}
|
|
|
|
output.PushBack(rfx->GetName() + ": Shader compilation successful.");
|
|
m_Editor->SetErrorList(output);
|
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
void ShaderEditorToolbarDlg::OnCloseAsmWindow()
|
|
{
|
|
m_Editor->HideCompiledOutput();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
#define ONCOMPILEDOUTPUTCOMMAND(VERSION) \
|
|
void ShaderEditorToolbarDlg::OnCompiledOutput##VERSION() \
|
|
{ \
|
|
m_Editor->ShowCompiledOutput(CST_##VERSION); \
|
|
}
|
|
|
|
|
|
ONCOMPILEDOUTPUTCOMMAND(VS_1_1)
|
|
ONCOMPILEDOUTPUTCOMMAND(VS_2_0)
|
|
ONCOMPILEDOUTPUTCOMMAND(VS_3_0)
|
|
ONCOMPILEDOUTPUTCOMMAND(PS_1_1)
|
|
ONCOMPILEDOUTPUTCOMMAND(PS_1_2)
|
|
ONCOMPILEDOUTPUTCOMMAND(PS_1_3)
|
|
ONCOMPILEDOUTPUTCOMMAND(PS_1_4)
|
|
ONCOMPILEDOUTPUTCOMMAND(PS_2_0)
|
|
ONCOMPILEDOUTPUTCOMMAND(PS_3_0)
|
|
ONCOMPILEDOUTPUTCOMMAND(FX_2_0)
|
|
ONCOMPILEDOUTPUTCOMMAND(FX_2_0_NOPRE)
|
|
|
|
ONCOMPILEDOUTPUTCOMMAND(ARBVP1)
|
|
ONCOMPILEDOUTPUTCOMMAND(NV_VP20)
|
|
ONCOMPILEDOUTPUTCOMMAND(NV_VP30)
|
|
ONCOMPILEDOUTPUTCOMMAND(NV_VP40)
|
|
ONCOMPILEDOUTPUTCOMMAND(ARBFP1)
|
|
ONCOMPILEDOUTPUTCOMMAND(NV_FP20)
|
|
ONCOMPILEDOUTPUTCOMMAND(NV_FP30)
|
|
ONCOMPILEDOUTPUTCOMMAND(NV_FP40)
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
BOOL ShaderEditorToolbarDlg::PreTranslateMessage(MSG* pMsg)
|
|
{
|
|
{
|
|
if (
|
|
pMsg->message >= WM_MOUSEFIRST &&
|
|
pMsg->message <= WM_MOUSELAST)
|
|
{
|
|
MSG msg;
|
|
::CopyMemory(&msg, pMsg, sizeof(MSG));
|
|
m_Tooltip.RelayEvent(pMsg);
|
|
}
|
|
}
|
|
|
|
return DllToolbarDlg::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
|
|
char* XBDMErrToString(DWORD err){
|
|
switch(err){
|
|
|
|
case XBDM_UNDEFINED:
|
|
return "XBDM_UNDEFINED";
|
|
case XBDM_MAXCONNECT:
|
|
return "XBDM_MAXCONNECT";
|
|
case XBDM_NOSUCHFILE:
|
|
return "XBDM_NOSUCHFILE";
|
|
case XBDM_NOMODULE:
|
|
return "XBDM_NOMODULE";
|
|
case XBDM_MEMUNMAPPED:
|
|
return "XBDM_MEMUNMAPPED";
|
|
case XBDM_NOTHREAD:
|
|
return "XBDM_NOTHREAD";
|
|
case XBDM_CLOCKNOTSET:
|
|
return "XBDM_CLOCKNOTSET";
|
|
case XBDM_INVALIDCMD:
|
|
return "XBDM_INVALIDCMD";
|
|
case XBDM_NOTSTOPPED:
|
|
return "XBDM_NOTSTOPPED";
|
|
case XBDM_MUSTCOPY:
|
|
return "XBDM_MUSTCOPY";
|
|
case XBDM_ALREADYEXISTS:
|
|
return "XBDM_ALREADYEXISTS";
|
|
case XBDM_DIRNOTEMPTY:
|
|
return "XBDM_DIRNOTEMPTY";
|
|
case XBDM_BADFILENAME:
|
|
return "XBDM_BADFILENAME";
|
|
case XBDM_CANNOTCREATE:
|
|
return "XBDM_CANNOTCREATE";
|
|
case XBDM_CANNOTACCESS:
|
|
return "XBDM_CANNOTACCESS";
|
|
case XBDM_DEVICEFULL:
|
|
return "XBDM_DEVICEFULL";
|
|
case XBDM_NOTDEBUGGABLE:
|
|
return "XBDM_NOTDEBUGGABLE";
|
|
case XBDM_BADCOUNTTYPE:
|
|
return "XBDM_BADCOUNTTYPE";
|
|
case XBDM_COUNTUNAVAILABLE:
|
|
return "XBDM_COUNTUNAVAILABLE";
|
|
case XBDM_NOTLOCKED:
|
|
return "XBDM_NOTLOCKED";
|
|
case XBDM_KEYXCHG:
|
|
return "XBDM_KEYXCHG";
|
|
case XBDM_MUSTBEDEDICATED:
|
|
return "XBDM_MUSTBEDEDICATED";
|
|
case XBDM_CANNOTCONNECT:
|
|
return "XBDM_CANNOTCONNECT";
|
|
case XBDM_CONNECTIONLOST:
|
|
return "XBDM_CONNECTIONLOST";
|
|
case XBDM_FILEERROR:
|
|
return "XBDM_FILEERROR";
|
|
case XBDM_ENDOFLIST:
|
|
return "XBDM_ENDOFLIST";
|
|
case XBDM_BUFFER_TOO_SMALL:
|
|
return "XBDM_BUFFER_TOO_SMALL";
|
|
case XBDM_NOTXBEFILE:
|
|
return "XBDM_NOTXBEFILE";
|
|
case XBDM_MEMSETINCOMPLETE:
|
|
return "XBDM_MEMSETINCOMPLETE";
|
|
case XBDM_NOXBOXNAME:
|
|
return "XBDM_NOXBOXNAME";
|
|
case XBDM_NOERRORSTRING:
|
|
return "XBDM_NOERRORSTRING";
|
|
|
|
default:
|
|
return "Unknown Error";
|
|
|
|
}
|
|
}
|
|
|
|
// XBDM_NOERR code are different on Xenon and Xbox !!!
|
|
#define BAIL(hr,b) if(hr != XBDM_NOERR && hr != 0x02da0000) {compileErr.Format(b " : DmError Reported 0x%x (%s)",res,XBDMErrToString(hr));return hr;}
|
|
|
|
unsigned int CompileFxXBox(const char *shaderName,const char*cmd, const XString& xsIn,XString& compileErr){
|
|
|
|
char pth[_MAX_PATH];
|
|
char src[_MAX_PATH];
|
|
char err[_MAX_PATH];
|
|
|
|
GetTempPath(_MAX_PATH,pth);
|
|
GetTempFileName(pth, "efc", 0,src);
|
|
|
|
_makepath(err,NULL,pth,"efc",".err");
|
|
::DeleteFile(err);
|
|
|
|
VxFile fSrc;
|
|
fSrc.Open(src,VxFile::WRITEONLY);
|
|
XASSERT(fSrc.IsValid());
|
|
fSrc.Write(xsIn.CStr(),xsIn.Length());
|
|
fSrc.Close();
|
|
|
|
HRESULT res = XBDM_NOERR;
|
|
|
|
// Create File to the Xbox
|
|
res = XboxDmSendFile(src,"XZ:\\tempfx.fx");
|
|
BAIL(res,"Cannot copy Fx File to target Xbox")
|
|
|
|
char resp[2048];
|
|
DWORD sz = 2048;
|
|
|
|
XString s(COMMANDPREFIX "fxc '");
|
|
s += shaderName;
|
|
s += "'";
|
|
|
|
PDM_CONNECTION pdcon = NULL;
|
|
|
|
XboxDmSetConnectionTimeout(10000,5000);
|
|
|
|
HRESULT hr = XboxDmOpenConnection(&pdcon);
|
|
if(pdcon){
|
|
hr = XboxDmDedicateConnection(pdcon,"XSHA");
|
|
if(XBDM_DEDICATED == hr){
|
|
hr = XboxDmSendCommand(pdcon,s.CStr(),resp,&sz);
|
|
}
|
|
XboxDmCloseConnection(pdcon);
|
|
}
|
|
|
|
BAIL(hr,"Execute compilation command on target Xbox. Please check DevClient is running on the target Xbox.")
|
|
compileErr = &resp[7]; // eat 200- OK or 200- KO
|
|
|
|
return sz ? E_FAIL: S_OK;
|
|
}
|
|
|
|
unsigned int CompileFxXenon(const char *shaderName,const char*cmd, const XString& xsIn,XString& compileErr){
|
|
|
|
char pth[_MAX_PATH];
|
|
char src[_MAX_PATH];
|
|
char err[_MAX_PATH];
|
|
|
|
GetTempPath(_MAX_PATH,pth);
|
|
GetTempFileName(pth, "efc", 0,src);
|
|
|
|
_makepath(err,NULL,pth,"efc",".err");
|
|
::DeleteFile(err);
|
|
|
|
VxFile fSrc;
|
|
fSrc.Open(src,VxFile::WRITEONLY);
|
|
XASSERT(fSrc.IsValid());
|
|
fSrc.Write(xsIn.CStr(),xsIn.Length());
|
|
fSrc.Close();
|
|
|
|
HRESULT res = XBDM_NOERR;
|
|
|
|
// Create File to the Xbox
|
|
res = XenonDmSendFile(src,"DEVKIT:\\tempfx.fx");
|
|
BAIL(res,"Cannot copy Fx File to target Xenon")
|
|
|
|
char resp[2048];
|
|
DWORD sz = 2048;
|
|
|
|
XString s(COMMANDPREFIX "fxc '");
|
|
s += shaderName;
|
|
s += "'";
|
|
|
|
PDM_CONNECTION pdcon = NULL;
|
|
|
|
XenonDmSetConnectionTimeout(10000,5000);
|
|
|
|
HRESULT hr = XenonDmOpenConnection(&pdcon);
|
|
if(pdcon){
|
|
hr = XenonDmDedicateConnection(pdcon,"XSHA");
|
|
if(XBDM_DEDICATED == hr || 0x02da0005 == hr){
|
|
hr = XenonDmSendCommand(pdcon,s.CStr(),resp,&sz);
|
|
}
|
|
XenonDmCloseConnection(pdcon);
|
|
}
|
|
|
|
BAIL(hr,"Execute compilation command on target Xenon. Please check DevClientXenon is running on the target Xenon.")
|
|
compileErr = &resp[7]; // eat 200- OK or 200- KO
|
|
|
|
return sz ? E_FAIL: S_OK;
|
|
}
|
|
|
|
unsigned int CompileFx(const char *shaderName, const char*cmd, const XString& xsIn,XString& compileErr)
|
|
{
|
|
char pth[_MAX_PATH];
|
|
char src[_MAX_PATH];
|
|
char err[_MAX_PATH];
|
|
|
|
GetTempPath(_MAX_PATH,pth);
|
|
GetTempFileName(pth, "efc", 0,src);
|
|
|
|
_makepath(err,NULL,pth,"efc",".err");
|
|
::DeleteFile(err);
|
|
|
|
VxFile fSrc;
|
|
fSrc.Open(src,VxFile::WRITEONLY);
|
|
XASSERT(fSrc.IsValid());
|
|
fSrc.Write(xsIn.CStr(),xsIn.Length());
|
|
fSrc.Close();
|
|
|
|
XString tmp;
|
|
tmp << '"';
|
|
tmp << CKGetStartPath();
|
|
tmp << cmd;
|
|
tmp << "\" ";
|
|
tmp << src;
|
|
tmp << " ";
|
|
tmp << err;
|
|
|
|
HRESULT res = DoWinExec(tmp.CStr());
|
|
|
|
|
|
VxFile fErr;
|
|
DWORD sz = 0;
|
|
fErr.Open(err,VxFile::READONLY);
|
|
if(fErr.IsValid()){
|
|
|
|
sz = fErr.Size();
|
|
if(sz){
|
|
compileErr.Resize((unsigned short)sz);
|
|
fErr.Read(compileErr.Str(),sz);
|
|
|
|
// Format the error
|
|
compileErr.Replace(src,"");
|
|
|
|
char s[3];
|
|
s[0] = 0x0D;
|
|
s[1] = 0x0A;
|
|
|
|
s[2] = 0x00;
|
|
compileErr.Replace(s,"\n");
|
|
|
|
|
|
}else{
|
|
compileErr = "";
|
|
}
|
|
|
|
fErr.Close();
|
|
}
|
|
|
|
::DeleteFile(src);
|
|
::DeleteFile(err);
|
|
|
|
return sz ? E_FAIL: S_OK;
|
|
}
|
|
|
|
void ShaderEditorToolbarDlg::OnBnClickedHide()
|
|
{
|
|
if(m_Editor==NULL) return;
|
|
|
|
CKContext* context = m_Editor->GetCKContext();
|
|
CKDWORD ret = context->SendInterfaceMessage(CKUIM_MESSAGEBOX, (CKDWORD)"Be careful, you are protecting content.\n\n You should really check that the \"File Options / Protect Content Password\" variable\n in the variable manager is already set to the desired password before clicking the OK button.\n\n", (CKDWORD)"Warning!", 0);
|
|
if(ret==IDOK) {
|
|
CKShader* shader = m_Editor->GetCurrentShader();
|
|
CKHideContentManager::Hide(shader->GetProtectable());
|
|
m_Editor->UpdateWindowText(shader->GetText().CStr());
|
|
GetInterface()->SetProjectModified(TRUE);
|
|
}
|
|
}
|
|
|
|
void ShaderEditorToolbarDlg::OnBnClickedClarify()
|
|
{
|
|
if(m_Editor==NULL) return;
|
|
|
|
CKShader* shader = m_Editor->GetCurrentShader();
|
|
if(shader) {
|
|
if(CKHideContentManager::CheckAgainst(shader->GetProtectable(), CKHideContentManager::GetClearPass())) {
|
|
CKContext* context = m_Editor->GetCKContext();
|
|
CKVariableManager* varMan = context->GetVariableManager();
|
|
if(varMan) {
|
|
XString clearPass;
|
|
varMan->GetStringValue("File Options/Protect Content Password", clearPass);
|
|
shader->UnLock(clearPass.CStr());
|
|
GetInterface()->SetProjectModified(TRUE);
|
|
}
|
|
}
|
|
}
|
|
m_Editor->UpdateWindowText(shader->GetText().CStr());
|
|
}
|