Commit a3752f04 authored by Gargaj's avatar Gargaj
Browse files

add texture previewing feature

parent 9cb5fa76
......@@ -139,7 +139,7 @@ void ShaderEditor::Initialise( SHADEREDITOR_OPTIONS &options )
sFontFile = options.sFontPath;
nOpacity = options.nOpacity;
Initialise();
wMain.SetPosition(options.rect);
SetPosition( options.rect );
}
void ShaderEditor::SetVerticalScrollPos()
......@@ -329,4 +329,9 @@ void ShaderEditor::ButtonUp( Scintilla::Point pt, unsigned int curTime, bool ctr
Font * ShaderEditor::GetTextFont()
{
return &vs.styles[ STYLE_DEFAULT ].font;
}
\ No newline at end of file
}
void ShaderEditor::SetPosition( Scintilla::PRectangle rect )
{
wMain.SetPosition(rect);
}
......@@ -69,6 +69,9 @@ public:
void Initialise();
void Initialise(SHADEREDITOR_OPTIONS &options);
void SetPosition( Scintilla::PRectangle rect );
void SetVerticalScrollPos();
void SetHorizontalScrollPos();
bool ModifyScrollBars(int nMax, int nPage);
......
......@@ -47,6 +47,7 @@ int main()
unsigned char nOpacity = 0xC0;
int nDebugOutputHeight = 200;
int nTexPreviewWidth = 64;
char szConfig[65535];
FILE * fConf = fopen("config.json","rb");
......@@ -129,16 +130,18 @@ int main()
int nMargin = 20;
bool bTexPreviewVisible = true;
SHADEREDITOR_OPTIONS options;
options.sFontPath = sFontPath;
options.nFontSize = nFontSize;
options.nOpacity = nOpacity;
options.rect = Scintilla::PRectangle( nMargin, nMargin, settings.nWidth - nMargin, settings.nHeight - nMargin * 2 - nDebugOutputHeight );
options.rect = Scintilla::PRectangle( nMargin, nMargin, settings.nWidth - nMargin - nTexPreviewWidth - nMargin, settings.nHeight - nMargin * 2 - nDebugOutputHeight );
ShaderEditor mShaderEditor( surface );
mShaderEditor.Initialise( options );
mShaderEditor.SetText( szShader );
options.rect = Scintilla::PRectangle( nMargin, settings.nHeight - nMargin - nDebugOutputHeight, settings.nWidth - nMargin, settings.nHeight - nMargin );
options.rect = Scintilla::PRectangle( nMargin, settings.nHeight - nMargin - nDebugOutputHeight, settings.nWidth - nMargin - nTexPreviewWidth - nMargin, settings.nHeight - nMargin );
ShaderEditor mDebugOutput( surface );
mDebugOutput.Initialise( options );
mDebugOutput.SetText( "" );
......@@ -175,7 +178,22 @@ int main()
for(int i=0; i<Renderer::keyEventBufferCount; i++)
{
if (Renderer::keyEventBuffer[i].scanCode == 286) // F5
if (Renderer::keyEventBuffer[i].scanCode == 283) // F2
{
if (bTexPreviewVisible)
{
mShaderEditor.SetPosition( Scintilla::PRectangle( nMargin, nMargin, settings.nWidth - nMargin, settings.nHeight - nMargin * 2 - nDebugOutputHeight ) );
mDebugOutput .SetPosition( Scintilla::PRectangle( nMargin, settings.nHeight - nMargin - nDebugOutputHeight, settings.nWidth - nMargin, settings.nHeight - nMargin ) );
bTexPreviewVisible = false;
}
else
{
mShaderEditor.SetPosition( Scintilla::PRectangle( nMargin, nMargin, settings.nWidth - nMargin - nTexPreviewWidth - nMargin, settings.nHeight - nMargin * 2 - nDebugOutputHeight ) );
mDebugOutput .SetPosition( Scintilla::PRectangle( nMargin, settings.nHeight - nMargin - nDebugOutputHeight, settings.nWidth - nMargin - nTexPreviewWidth - nMargin, settings.nHeight - nMargin ) );
bTexPreviewVisible = true;
}
}
else if (Renderer::keyEventBuffer[i].scanCode == 286) // F5
{
mShaderEditor.GetText(szShader,65535);
if (Renderer::ReloadShader( szShader, strlen(szShader), szError, 4096 ))
......@@ -255,7 +273,28 @@ int main()
mDebugOutput.Paint();
Renderer::SetTextRenderingViewport( Scintilla::PRectangle(0,0,Renderer::nWidth,Renderer::nHeight) );
char szHelp[] = "F5 - recompile shader F11 - hide GUI";
if (bTexPreviewVisible)
{
int y1 = nMargin;
int x1 = settings.nWidth - nMargin - nTexPreviewWidth;
int x2 = settings.nWidth - nMargin;
for (std::map<std::string, Renderer::Texture*>::iterator it = textures.begin(); it != textures.end(); it++)
{
int y2 = y1 + nTexPreviewWidth * (it->second->width / (float)it->second->height);
Renderer::BindTexture( it->second );
Renderer::RenderQuad(
Renderer::Vertex( x1, y1, 0xFFFFFFFF, 0.0, 0.0 ),
Renderer::Vertex( x2, y1, 0xFFFFFFFF, 1.0, 0.0 ),
Renderer::Vertex( x2, y2, 0xFFFFFFFF, 1.0, 1.0 ),
Renderer::Vertex( x1, y2, 0xFFFFFFFF, 0.0, 1.0 )
);
surface->DrawTextNoClip( Scintilla::PRectangle(x1,y1,x2,y2), *mShaderEditor.GetTextFont(), y2 - 5.0, it->first.c_str(), it->first.length(), 0xffFFFFFF, 0x00000000);
y1 = y2 + nMargin;
}
}
char szHelp[] = "F2 - toggle texture preview F5 - recompile shader F11 - hide GUI";
surface->DrawTextNoClip( Scintilla::PRectangle(20,Renderer::nHeight - 20,100,Renderer::nHeight), *mShaderEditor.GetTextFont(), Renderer::nHeight - 5.0, szHelp, strlen(szHelp), 0x80FFFFFF, 0x00000000);
}
......
......@@ -161,6 +161,7 @@ namespace Renderer
// case VK_LEFTBRACKET: sciKey = '['; break;
// case VK_BACKSLASH: sciKey = '\\'; break;
// case VK_RIGHTBRACKET: sciKey = ']'; break;
case VK_F2: sciKey = 283; break;
case VK_F5: sciKey = 286; break;
case VK_F11: sciKey = 292; break;
case VK_SHIFT:
......@@ -491,7 +492,7 @@ namespace Renderer
"SamplerState smp;\n"
"float4 main( float4 position : SV_POSITION, float4 Color: COLOR, float2 TexCoord : TEXCOORD0, float Factor : TEXCOORD1 ) : SV_TARGET\n"
"{\n"
" float4 v4Texture = float4( Color.rgb, Color.a * tex.Sample(smp,TexCoord).a );\n"
" float4 v4Texture = Color * tex.Sample(smp,TexCoord);//float4( Color.rgb, Color.a * .a );\n"
" float4 v4Color = Color;\n"
" return lerp( v4Texture, v4Color, Factor );\n"
"}\n";
......@@ -888,22 +889,27 @@ namespace Renderer
ZeroMemory(&desc,sizeof(D3D11_TEXTURE2D_DESC));
desc.Width = w;
desc.Height = h;
desc.Format = DXGI_FORMAT_A8_UNORM;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.SampleDesc.Count = 1;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
unsigned int * p = new unsigned int[ w * h ];
for (int i=0; i < w * h; i++)
p[i] = (data[i] << 24) | 0xFFFFFF;
D3D11_SUBRESOURCE_DATA subData;
ZeroMemory(&subData,sizeof(D3D11_SUBRESOURCE_DATA));
subData.pSysMem = data;
subData.SysMemPitch = w * sizeof(unsigned char);
subData.pSysMem = p;
subData.SysMemPitch = w * sizeof(unsigned int);
ID3D11Texture2D * pTex = NULL;
if (pDevice->CreateTexture2D( &desc, &subData, &pTex ) != S_OK)
return NULL;
delete[] p;
DX11Texture * tex = new DX11Texture();
tex->width = w;
tex->height = h;
......@@ -995,6 +1001,7 @@ namespace Renderer
lastTexture = tex;
if (tex)
{
__FlushRenderCache();
DX11Texture * pTex = (DX11Texture *) tex;
pContext->PSSetShaderResources( 0, 1, &pTex->pResourceView );
}
......
......@@ -151,6 +151,7 @@ namespace Renderer
// case VK_LEFTBRACKET: sciKey = '['; break;
// case VK_BACKSLASH: sciKey = '\\'; break;
// case VK_RIGHTBRACKET: sciKey = ']'; break;
case VK_F2: sciKey = 283; break;
case VK_F5: sciKey = 286; break;
case VK_F11: sciKey = 292; break;
case VK_SHIFT:
......@@ -586,19 +587,25 @@ namespace Renderer
Texture * CreateA8TextureFromData( int w, int h, unsigned char * data )
{
LPDIRECT3DTEXTURE9 pTex = NULL;
pDevice->CreateTexture( w, h, 0, NULL, D3DFMT_A8, D3DPOOL_MANAGED, &pTex, NULL );
pDevice->CreateTexture( w, h, 0, NULL, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &pTex, NULL );
if (!pTex)
return NULL;
D3DLOCKED_RECT rect;
pTex->LockRect( 0, &rect, NULL, NULL );
//memset( rect.pBits, 0, w * sizeof(float) );
unsigned char * src = data;
unsigned char * dst = (unsigned char *)rect.pBits;
for (int i=0; i<h; i++)
{
memcpy( dst, src, w * sizeof(unsigned char) );
unsigned char * srcLine = src;
unsigned int * dstLine = (unsigned int *)dst;
for (int j=0; j<w; j++)
{
*dstLine = (*srcLine << 24) | 0xFFFFFF;
srcLine++;
dstLine++;
}
src += w * sizeof(unsigned char);
dst += rect.Pitch;
}
......@@ -634,8 +641,9 @@ namespace Renderer
D3DXMatrixOrthoOffCenterLH( (D3DXMATRIX*)&mat, 0, nWidth, nHeight, 0, -1.0f, 1.0f );
pDevice->SetTransform( D3DTS_PROJECTION, &mat );
pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment