Mercurial > mm7
changeset 2523:c532d5242055
Hello from Direct3D 11 :)
author | a.parshin |
---|---|
date | Thu, 09 Oct 2014 23:33:36 +0300 |
parents | b71d0e7837ac |
children | c7264ab7132f |
files | Engine/Graphics/Render.cpp Engine/Graphics/RenderD3D11.cpp Engine/Graphics/RenderD3D11.h Engine/Graphics/RenderStruct.h Engine/Graphics/Shaders/UI.shader Engine/MMT.cpp |
diffstat | 6 files changed, 112 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/Engine/Graphics/Render.cpp Thu Oct 09 19:31:55 2014 +0300 +++ b/Engine/Graphics/Render.cpp Thu Oct 09 23:33:36 2014 +0300 @@ -6394,7 +6394,17 @@ unsigned int g = ((c >> 5) & 63) * 4; unsigned int r = ((c >> 11) & 31) * 8; - return (r << 16) | (g << 8) | b;// + return (r << 16) | (g << 8) | b; +} + +unsigned __int32 Color32_SwapRedBlue(unsigned __int16 color16) +{ + unsigned __int32 c = color16; + unsigned int b = (c & 31) * 8; + unsigned int g = ((c >> 5) & 63) * 4; + unsigned int r = ((c >> 11) & 31) * 8; + + return (b << 16) | (g << 8) | r; } //----- (0040DEF3) --------------------------------------------------------
--- a/Engine/Graphics/RenderD3D11.cpp Thu Oct 09 19:31:55 2014 +0300 +++ b/Engine/Graphics/RenderD3D11.cpp Thu Oct 09 23:33:36 2014 +0300 @@ -149,8 +149,6 @@ void RenderD3D11::DrawTextureNew(float u, float v, RGBTexture *tex) { - ClearTarget(0); - if (!tex->d3d11_srv) { auto desc = tex->d3d11_desc = new D3D11_TEXTURE2D_DESC; @@ -186,8 +184,8 @@ auto src = tex->pPixels + y * tex->uWidth + x; auto dst = (unsigned int *)((char *)map.pData + y * map.RowPitch) + x; - extern unsigned __int32 Color32(unsigned __int16 color16); - *dst = Color32(*src); + extern unsigned __int32 Color32_SwapRedBlue(unsigned __int16 color16); + *dst = 0xFF000000 | Color32_SwapRedBlue(*src); } d3dc->Unmap(ram_texture, 0); @@ -204,8 +202,37 @@ d3dc->OMSetBlendState(ui_blend, blendFactor, 0xFFFFFFFF); d3dc->OMSetDepthStencilState(ui_depthstencil, 1); + + { + struct cb_fast + { + float pos_x; + float pos_y; + float size_x; + float size_y; + }; + + D3D11_MAPPED_SUBRESOURCE map; + d3dc->Map(ui_cb_fast, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); + { + cb_fast data; + { + data.pos_x = u; + data.pos_y = v; + data.size_x = (float)tex->uWidth / window->GetWidth(); + data.size_y = (float)tex->uHeight / window->GetHeight(); + } + memcpy(map.pData, &data, sizeof(data)); + } + d3dc->Unmap(ui_cb_fast, 0); + } + d3dc->VSSetShader(ui_vs, nullptr, 0); + d3dc->VSSetConstantBuffers(0, 1, &ui_cb_fast); + d3dc->PSSetShader(ui_ps, nullptr, 0); + d3dc->PSSetConstantBuffers(0, 1, &ui_cb_fast); + d3dc->PSSetShaderResources(0, 1, &tex->d3d11_srv); uint uOffset = 0; uint uStride = 4 * sizeof(float); @@ -398,8 +425,8 @@ memset(&viewport, 0, sizeof(viewport)); viewport.TopLeftX = game_viewport_x; viewport.TopLeftY = game_viewport_y; - viewport.Width = game_viewport_width; - viewport.Height = game_viewport_height; + viewport.Width = window->GetWidth(); + viewport.Height = window->GetHeight(); viewport.MinDepth = 0; viewport.MaxDepth = 1; d3dc->RSSetViewports(1, &viewport); @@ -415,15 +442,22 @@ { uint uVertexSize = 4 * sizeof(float); - float test_mesh[] = + float ui_mesh[] = { - -1, 1, 0.1, 1, + 1, 1, 0, 0, // pos + 1, 1, 1, 0, // pos + size.x + 1, 1, 0, 1, // pos + size.y + + 1, 1, 0, 1, // pos + size.y + 1, 1, 1, 0, // pos + size.x + 1, 1, 1, 1 // pos + size.xy + /*-1, 1, 0.1, 1, 1, 1, 0.1, 1, -1, -1, 0.1, 1, -1, -1, 0.1, 1, 1, 1, 0.1, 1, - 1, -1, 0.1, 1 + 1, -1, 0.1, 1*/ }; D3D11_BUFFER_DESC vbdesc; @@ -435,14 +469,23 @@ vbdesc.Usage = D3D11_USAGE_DEFAULT; D3D11_SUBRESOURCE_DATA vbdata; - vbdata.pSysMem = test_mesh; + vbdata.pSysMem = ui_mesh; vbdata.SysMemPitch = 0; vbdata.SysMemSlicePitch = 0; d3dd->CreateBuffer(&vbdesc, &vbdata, &ui_vb); } - + D3D11_BUFFER_DESC ui_cb_fast_desc; + ZeroMemory(&ui_cb_fast_desc, sizeof(ui_cb_fast_desc)); + // TODO: Fix Bug Prone size + ui_cb_fast_desc.ByteWidth = 1 * 4 * sizeof(float); + ui_cb_fast_desc.Usage = D3D11_USAGE_DYNAMIC; + ui_cb_fast_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + ui_cb_fast_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + ui_cb_fast_desc.MiscFlags = 0; + ui_cb_fast_desc.StructureByteStride = 0; + d3dd->CreateBuffer(&ui_cb_fast_desc, nullptr, &ui_cb_fast); D3D11_DEPTH_STENCIL_DESC ui_depthstencil_desc; ui_depthstencil_desc.DepthEnable = true;
--- a/Engine/Graphics/RenderD3D11.h Thu Oct 09 19:31:55 2014 +0300 +++ b/Engine/Graphics/RenderD3D11.h Thu Oct 09 23:33:36 2014 +0300 @@ -178,6 +178,7 @@ ID3D11VertexShader *ui_vs; ID3D11PixelShader *ui_ps; + ID3D11Buffer *ui_cb_fast; ID3D11InputLayout *ui_layout; ID3D11Buffer *ui_vb; ID3D11DepthStencilState *ui_depthstencil;
--- a/Engine/Graphics/RenderStruct.h Thu Oct 09 19:31:55 2014 +0300 +++ b/Engine/Graphics/RenderStruct.h Thu Oct 09 23:33:36 2014 +0300 @@ -25,6 +25,7 @@ unsigned __int16 Color16(unsigned __int32 r, unsigned __int32 g, unsigned __int32 b); unsigned __int32 Color32(unsigned __int16 color16); +unsigned __int32 Color32_SwapRedBlue(unsigned __int16 color16); /* 119 */ #pragma pack(push, 1)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Engine/Graphics/Shaders/UI.shader Thu Oct 09 23:33:36 2014 +0300 @@ -0,0 +1,45 @@ +cbuffer fast: register(b0) +{ + float2 position : packoffset(c0.x); + float2 size : packoffset(c0.z); +}; + +cbuffer slow: register(b1) +{ +}; + + +struct VInput +{ + float4 pos: POSITION0; +}; + +struct VOutput +{ + float4 pos: SV_Position0; + float2 uv: TEXCOORD0; +}; + + +VOutput vs(VInput vin) +{ + VOutput vout; + + float2 normalized_pos = vin.pos.xy * position.xy + vin.pos.zw * size.xy; + vout.pos.xy = float2(2, -2) * normalized_pos + float2(-1, 1); + vout.pos.zw = float2(0, 1); + vout.uv = vin.pos.zw; + + return vout; +} + + + + +SamplerState basic_sampler: register(s0); +Texture2D<float4> image: register(t0); + +float4 main(VOutput pin): SV_Target0 +{ + return image.Sample(basic_sampler, pin.uv); +} \ No newline at end of file
--- a/Engine/MMT.cpp Thu Oct 09 19:31:55 2014 +0300 +++ b/Engine/MMT.cpp Thu Oct 09 23:33:36 2014 +0300 @@ -61,19 +61,9 @@ else tex.Load("mm6title.pcx", 2); - //while (true) - //{ pRenderer->BeginScene(); pRenderer->DrawTextureNew(0, 0, &tex); - //MSG msg; - //while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE)) - //{ - // TranslateMessage(&msg); - // DispatchMessageW(&msg); - //} - //} - tex.Release(); MainMenuUI_LoadFontsAndSomeStuff();