Fixed some C++ errors and styling in windows demos
This commit is contained in:
parent
9d184a8b91
commit
ef835f7afc
@ -95,61 +95,58 @@ nk_d3d11_render(ID3D11DeviceContext *context, enum nk_anti_aliasing AA)
|
||||
ID3D11DeviceContext_RSSetState(context, d3d11.rasterizer_state);
|
||||
ID3D11DeviceContext_RSSetViewports(context, 1, &d3d11.viewport);
|
||||
|
||||
/* convert from command queue into draw list and draw to screen */
|
||||
{
|
||||
/* load draw vertices & elements directly into vertex + element buffer */
|
||||
D3D11_MAPPED_SUBRESOURCE vertices;
|
||||
D3D11_MAPPED_SUBRESOURCE indices;
|
||||
const struct nk_draw_command *cmd;
|
||||
UINT offset = 0;
|
||||
HRESULT hr;
|
||||
/* Convert from command queue into draw list and draw to screen */
|
||||
{/* load draw vertices & elements directly into vertex + element buffer */
|
||||
D3D11_MAPPED_SUBRESOURCE vertices;
|
||||
D3D11_MAPPED_SUBRESOURCE indices;
|
||||
const struct nk_draw_command *cmd;
|
||||
UINT offset = 0;
|
||||
HRESULT hr;
|
||||
|
||||
hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)d3d11.vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &vertices);
|
||||
assert(SUCCEEDED(hr));
|
||||
hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)d3d11.vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &vertices);
|
||||
NK_ASSERT(SUCCEEDED(hr));
|
||||
hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)d3d11.index_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &indices);
|
||||
NK_ASSERT(SUCCEEDED(hr));
|
||||
|
||||
hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)d3d11.index_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &indices);
|
||||
assert(SUCCEEDED(hr));
|
||||
{/* fill converting configuration */
|
||||
struct nk_convert_config config;
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
config.circle_segment_count = 22;
|
||||
config.curve_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
config.null = d3d11.null;
|
||||
|
||||
{
|
||||
/* fill converting configuration */
|
||||
struct nk_convert_config config;
|
||||
memset(&config, 0, sizeof(config));
|
||||
config.global_alpha = 1.0f;
|
||||
config.shape_AA = AA;
|
||||
config.line_AA = AA;
|
||||
config.circle_segment_count = 22;
|
||||
config.curve_segment_count = 22;
|
||||
config.arc_segment_count = 22;
|
||||
config.null = d3d11.null;
|
||||
|
||||
/* setup buffers to load vertices and elements */
|
||||
{
|
||||
struct nk_buffer vbuf, ibuf;
|
||||
nk_buffer_init_fixed(&vbuf, vertices.pData, (size_t)d3d11.max_vertex_buffer);
|
||||
nk_buffer_init_fixed(&ibuf, indices.pData, (size_t)d3d11.max_index_buffer);
|
||||
nk_convert(&d3d11.ctx, &d3d11.cmds, &vbuf, &ibuf, &config);
|
||||
}
|
||||
}
|
||||
ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)d3d11.vertex_buffer, 0);
|
||||
ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)d3d11.index_buffer, 0);
|
||||
|
||||
/* iterate over and execute each draw command */
|
||||
nk_draw_foreach(cmd, &d3d11.ctx, &d3d11.cmds)
|
||||
{
|
||||
ID3D11ShaderResourceView *texture_view = (ID3D11ShaderResourceView *)cmd->texture.ptr;
|
||||
D3D11_RECT scissor;
|
||||
if (!cmd->elem_count) continue;
|
||||
scissor.left = (LONG)cmd->clip_rect.x;
|
||||
scissor.right = (LONG)(cmd->clip_rect.x + cmd->clip_rect.w);
|
||||
scissor.top = (LONG)cmd->clip_rect.y;
|
||||
scissor.bottom = (LONG)(cmd->clip_rect.y + cmd->clip_rect.h);
|
||||
ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &texture_view);
|
||||
ID3D11DeviceContext_RSSetScissorRects(context, 1, &scissor);
|
||||
ID3D11DeviceContext_DrawIndexed(context, (UINT)cmd->elem_count, offset, 0);
|
||||
offset += cmd->elem_count;
|
||||
}
|
||||
nk_clear(&d3d11.ctx);
|
||||
{/* setup buffers to load vertices and elements */
|
||||
struct nk_buffer vbuf, ibuf;
|
||||
nk_buffer_init_fixed(&vbuf, vertices.pData, (size_t)d3d11.max_vertex_buffer);
|
||||
nk_buffer_init_fixed(&ibuf, indices.pData, (size_t)d3d11.max_index_buffer);
|
||||
nk_convert(&d3d11.ctx, &d3d11.cmds, &vbuf, &ibuf, &config);}
|
||||
}
|
||||
|
||||
ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)d3d11.vertex_buffer, 0);
|
||||
ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)d3d11.index_buffer, 0);
|
||||
|
||||
/* iterate over and execute each draw command */
|
||||
nk_draw_foreach(cmd, &d3d11.ctx, &d3d11.cmds)
|
||||
{
|
||||
D3D11_RECT scissor;
|
||||
ID3D11ShaderResourceView *texture_view = (ID3D11ShaderResourceView *)cmd->texture.ptr;
|
||||
if (!cmd->elem_count) continue;
|
||||
|
||||
scissor.left = (LONG)cmd->clip_rect.x;
|
||||
scissor.right = (LONG)(cmd->clip_rect.x + cmd->clip_rect.w);
|
||||
scissor.top = (LONG)cmd->clip_rect.y;
|
||||
scissor.bottom = (LONG)(cmd->clip_rect.y + cmd->clip_rect.h);
|
||||
|
||||
ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &texture_view);
|
||||
ID3D11DeviceContext_RSSetScissorRects(context, 1, &scissor);
|
||||
ID3D11DeviceContext_DrawIndexed(context, (UINT)cmd->elem_count, offset, 0);
|
||||
offset += cmd->elem_count;
|
||||
}
|
||||
nk_clear(&d3d11.ctx);}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -358,7 +355,7 @@ nk_d3d11_clipbard_paste(nk_handle usr, struct nk_text_edit *edit)
|
||||
int utf8size = WideCharToMultiByte(CP_UTF8, 0, wstr, size / sizeof(wchar_t), NULL, 0, NULL, NULL);
|
||||
if (utf8size)
|
||||
{
|
||||
char* utf8 = malloc(utf8size);
|
||||
char* utf8 = (char*)malloc(utf8size);
|
||||
if (utf8)
|
||||
{
|
||||
WideCharToMultiByte(CP_UTF8, 0, wstr, size / sizeof(wchar_t), utf8, utf8size, NULL, NULL);
|
||||
@ -386,13 +383,12 @@ nk_d3d11_clipbard_copy(nk_handle usr, const char *text, int len)
|
||||
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (wsize + 1) * sizeof(wchar_t));
|
||||
if (mem)
|
||||
{
|
||||
wchar_t* wstr = GlobalLock(mem);
|
||||
wchar_t* wstr = (wchar_t*)GlobalLock(mem);
|
||||
if (wstr)
|
||||
{
|
||||
MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize);
|
||||
wstr[wsize] = 0;
|
||||
GlobalUnlock(mem);
|
||||
|
||||
SetClipboardData(CF_UNICODETEXT, mem);
|
||||
}
|
||||
}
|
||||
@ -417,141 +413,115 @@ nk_d3d11_init(ID3D11Device *device, int width, int height, unsigned int max_vert
|
||||
|
||||
nk_buffer_init_default(&d3d11.cmds);
|
||||
|
||||
/* rasterizer state */
|
||||
{
|
||||
D3D11_RASTERIZER_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.FillMode = D3D11_FILL_SOLID;
|
||||
desc.CullMode = D3D11_CULL_NONE;
|
||||
desc.FrontCounterClockwise = FALSE;
|
||||
desc.DepthBias = 0;
|
||||
desc.DepthBiasClamp = 0;
|
||||
desc.SlopeScaledDepthBias = 0.0f;
|
||||
desc.DepthClipEnable = TRUE;
|
||||
desc.ScissorEnable = TRUE;
|
||||
desc.MultisampleEnable = FALSE;
|
||||
desc.AntialiasedLineEnable = FALSE;
|
||||
|
||||
hr = ID3D11Device_CreateRasterizerState(device,&desc, &d3d11.rasterizer_state);
|
||||
assert(SUCCEEDED(hr));
|
||||
}
|
||||
{/* rasterizer state */
|
||||
D3D11_RASTERIZER_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.FillMode = D3D11_FILL_SOLID;
|
||||
desc.CullMode = D3D11_CULL_NONE;
|
||||
desc.FrontCounterClockwise = FALSE;
|
||||
desc.DepthBias = 0;
|
||||
desc.DepthBiasClamp = 0;
|
||||
desc.SlopeScaledDepthBias = 0.0f;
|
||||
desc.DepthClipEnable = TRUE;
|
||||
desc.ScissorEnable = TRUE;
|
||||
desc.MultisampleEnable = FALSE;
|
||||
desc.AntialiasedLineEnable = FALSE;
|
||||
hr = ID3D11Device_CreateRasterizerState(device,&desc, &d3d11.rasterizer_state);
|
||||
NK_ASSERT(SUCCEEDED(hr));}
|
||||
|
||||
/* vertex shader */
|
||||
{
|
||||
hr = ID3D11Device_CreateVertexShader(device,nk_d3d11_vertex_shader, sizeof(nk_d3d11_vertex_shader), NULL, &d3d11.vertex_shader);
|
||||
assert(SUCCEEDED(hr));
|
||||
}
|
||||
{hr = ID3D11Device_CreateVertexShader(device,nk_d3d11_vertex_shader, sizeof(nk_d3d11_vertex_shader), NULL, &d3d11.vertex_shader);
|
||||
NK_ASSERT(SUCCEEDED(hr));}
|
||||
|
||||
/* input layout */
|
||||
{
|
||||
const D3D11_INPUT_ELEMENT_DESC layout[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(struct nk_draw_vertex, position), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(struct nk_draw_vertex, uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, offsetof(struct nk_draw_vertex, col), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
|
||||
hr = ID3D11Device_CreateInputLayout(device,layout, ARRAYSIZE(layout), nk_d3d11_vertex_shader, sizeof(nk_d3d11_vertex_shader), &d3d11.input_layout);
|
||||
assert(SUCCEEDED(hr));
|
||||
}
|
||||
{const D3D11_INPUT_ELEMENT_DESC layout[] = {
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(struct nk_draw_vertex, position), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, offsetof(struct nk_draw_vertex, uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, offsetof(struct nk_draw_vertex, col), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
hr = ID3D11Device_CreateInputLayout(device,layout, ARRAYSIZE(layout), nk_d3d11_vertex_shader, sizeof(nk_d3d11_vertex_shader), &d3d11.input_layout);
|
||||
NK_ASSERT(SUCCEEDED(hr));}
|
||||
|
||||
/* constant buffer */
|
||||
{
|
||||
float matrix[4*4];
|
||||
{float matrix[4*4];
|
||||
D3D11_BUFFER_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.ByteWidth = sizeof(matrix);
|
||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
D3D11_BUFFER_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.ByteWidth = sizeof(matrix);
|
||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
desc.MiscFlags = 0;
|
||||
{D3D11_SUBRESOURCE_DATA data;
|
||||
data.pSysMem = matrix;
|
||||
data.SysMemPitch = 0;
|
||||
data.SysMemSlicePitch = 0;
|
||||
|
||||
{D3D11_SUBRESOURCE_DATA data;
|
||||
data.pSysMem = matrix;
|
||||
data.SysMemPitch = 0;
|
||||
data.SysMemSlicePitch = 0;
|
||||
|
||||
nk_d3d11_get_projection_matrix(width, height, matrix);
|
||||
|
||||
hr = ID3D11Device_CreateBuffer(device, &desc, &data, &d3d11.const_buffer);
|
||||
assert(SUCCEEDED(hr));}
|
||||
}
|
||||
nk_d3d11_get_projection_matrix(width, height, matrix);
|
||||
hr = ID3D11Device_CreateBuffer(device, &desc, &data, &d3d11.const_buffer);
|
||||
NK_ASSERT(SUCCEEDED(hr));}}
|
||||
|
||||
/* pixel shader */
|
||||
{
|
||||
hr = ID3D11Device_CreatePixelShader(device, nk_d3d11_pixel_shader, sizeof(nk_d3d11_pixel_shader), NULL, &d3d11.pixel_shader);
|
||||
assert(SUCCEEDED(hr));
|
||||
}
|
||||
{hr = ID3D11Device_CreatePixelShader(device, nk_d3d11_pixel_shader, sizeof(nk_d3d11_pixel_shader), NULL, &d3d11.pixel_shader);
|
||||
NK_ASSERT(SUCCEEDED(hr));}
|
||||
|
||||
/* blend state */
|
||||
{
|
||||
D3D11_BLEND_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.AlphaToCoverageEnable = FALSE;
|
||||
desc.RenderTarget[0].BlendEnable = TRUE;
|
||||
desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
||||
desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
|
||||
desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
|
||||
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
||||
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
||||
hr = ID3D11Device_CreateBlendState(device, &desc, &d3d11.blend_state);
|
||||
assert(SUCCEEDED(hr));
|
||||
}
|
||||
{/* blend state */
|
||||
D3D11_BLEND_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.AlphaToCoverageEnable = FALSE;
|
||||
desc.RenderTarget[0].BlendEnable = TRUE;
|
||||
desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
|
||||
desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
|
||||
desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
|
||||
desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
|
||||
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
||||
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
||||
hr = ID3D11Device_CreateBlendState(device, &desc, &d3d11.blend_state);
|
||||
NK_ASSERT(SUCCEEDED(hr));}
|
||||
|
||||
/* vertex buffer */
|
||||
{
|
||||
D3D11_BUFFER_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
desc.ByteWidth = max_vertex_buffer;
|
||||
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
desc.MiscFlags = 0;
|
||||
hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &d3d11.vertex_buffer);
|
||||
assert(SUCCEEDED(hr));
|
||||
}
|
||||
{D3D11_BUFFER_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
desc.ByteWidth = max_vertex_buffer;
|
||||
desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
desc.MiscFlags = 0;
|
||||
hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &d3d11.vertex_buffer);
|
||||
NK_ASSERT(SUCCEEDED(hr));}
|
||||
|
||||
/* index buffer */
|
||||
{
|
||||
D3D11_BUFFER_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
desc.ByteWidth = max_index_buffer;
|
||||
desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &d3d11.index_buffer);
|
||||
assert(SUCCEEDED(hr));
|
||||
}
|
||||
{D3D11_BUFFER_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.Usage = D3D11_USAGE_DYNAMIC;
|
||||
desc.ByteWidth = max_index_buffer;
|
||||
desc.BindFlags = D3D11_BIND_INDEX_BUFFER;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
|
||||
hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &d3d11.index_buffer);
|
||||
NK_ASSERT(SUCCEEDED(hr));}
|
||||
|
||||
/* sampler state */
|
||||
{
|
||||
D3D11_SAMPLER_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
desc.MipLODBias = 0.0f;
|
||||
desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
|
||||
desc.MinLOD = 0.0f;
|
||||
desc.MaxLOD = FLT_MAX;
|
||||
hr = ID3D11Device_CreateSamplerState(device, &desc, &d3d11.sampler_state);
|
||||
assert(SUCCEEDED(hr));
|
||||
}
|
||||
{D3D11_SAMPLER_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
|
||||
desc.MipLODBias = 0.0f;
|
||||
desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
|
||||
desc.MinLOD = 0.0f;
|
||||
desc.MaxLOD = FLT_MAX;
|
||||
hr = ID3D11Device_CreateSamplerState(device, &desc, &d3d11.sampler_state);
|
||||
NK_ASSERT(SUCCEEDED(hr));}
|
||||
|
||||
/* viewport */
|
||||
{
|
||||
d3d11.viewport.TopLeftX = 0.0f;
|
||||
d3d11.viewport.TopLeftY = 0.0f;
|
||||
d3d11.viewport.Width = (float)width;
|
||||
d3d11.viewport.Height = (float)height;
|
||||
d3d11.viewport.MinDepth = 0.0f;
|
||||
d3d11.viewport.MaxDepth = 1.0f;
|
||||
}
|
||||
|
||||
{d3d11.viewport.TopLeftX = 0.0f;
|
||||
d3d11.viewport.TopLeftY = 0.0f;
|
||||
d3d11.viewport.Width = (float)width;
|
||||
d3d11.viewport.Height = (float)height;
|
||||
d3d11.viewport.MinDepth = 0.0f;
|
||||
d3d11.viewport.MaxDepth = 1.0f;}
|
||||
return &d3d11.ctx;
|
||||
}
|
||||
|
||||
@ -570,41 +540,38 @@ nk_d3d11_font_stash_end(void)
|
||||
image = nk_font_atlas_bake(&d3d11.atlas, &w, &h, NK_FONT_ATLAS_RGBA32);
|
||||
|
||||
/* upload font to texture and create texture view */
|
||||
{
|
||||
ID3D11Texture2D *font_texture;
|
||||
HRESULT hr;
|
||||
{ID3D11Texture2D *font_texture;
|
||||
HRESULT hr;
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.Width = (UINT)w;
|
||||
desc.Height = (UINT)h;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
memset(&desc, 0, sizeof(desc));
|
||||
desc.Width = (UINT)w;
|
||||
desc.Height = (UINT)h;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.CPUAccessFlags = 0;
|
||||
|
||||
{D3D11_SUBRESOURCE_DATA data;
|
||||
data.pSysMem = image;
|
||||
data.SysMemPitch = (UINT)(w * 4);
|
||||
data.SysMemSlicePitch = 0;
|
||||
hr = ID3D11Device_CreateTexture2D(d3d11.device, &desc, &data, &font_texture);
|
||||
assert(SUCCEEDED(hr));}
|
||||
{D3D11_SUBRESOURCE_DATA data;
|
||||
data.pSysMem = image;
|
||||
data.SysMemPitch = (UINT)(w * 4);
|
||||
data.SysMemSlicePitch = 0;
|
||||
hr = ID3D11Device_CreateTexture2D(d3d11.device, &desc, &data, &font_texture);
|
||||
assert(SUCCEEDED(hr));}
|
||||
|
||||
{D3D11_SHADER_RESOURCE_VIEW_DESC srv;
|
||||
memset(&srv, 0, sizeof(srv));
|
||||
srv.Format = desc.Format;
|
||||
srv.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srv.Texture2D.MipLevels = 1;
|
||||
srv.Texture2D.MostDetailedMip = 0;
|
||||
hr = ID3D11Device_CreateShaderResourceView(d3d11.device, (ID3D11Resource *)font_texture, &srv, &d3d11.font_texture_view);
|
||||
assert(SUCCEEDED(hr));}
|
||||
|
||||
ID3D11Texture2D_Release(font_texture);
|
||||
}
|
||||
{D3D11_SHADER_RESOURCE_VIEW_DESC srv;
|
||||
memset(&srv, 0, sizeof(srv));
|
||||
srv.Format = desc.Format;
|
||||
srv.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srv.Texture2D.MipLevels = 1;
|
||||
srv.Texture2D.MostDetailedMip = 0;
|
||||
hr = ID3D11Device_CreateShaderResourceView(d3d11.device, (ID3D11Resource *)font_texture, &srv, &d3d11.font_texture_view);
|
||||
assert(SUCCEEDED(hr));}
|
||||
ID3D11Texture2D_Release(font_texture);}
|
||||
|
||||
nk_font_atlas_end(&d3d11.atlas, nk_handle_ptr(d3d11.font_texture_view), &d3d11.null);
|
||||
if (d3d11.atlas.default_font)
|
||||
|
@ -299,8 +299,7 @@ nk_gdi_stroke_curve(HDC dc, struct nk_vec2i p1,
|
||||
HPEN pen = NULL;
|
||||
if (line_thickness == 1) {
|
||||
SetDCPenColor(dc, color);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pen = CreatePen(PS_SOLID, line_thickness, color);
|
||||
SelectObject(dc, pen);
|
||||
}
|
||||
@ -324,7 +323,7 @@ nk_gdi_draw_text(HDC dc, short x, short y, unsigned short w, unsigned short h,
|
||||
if(!text || !font || !len) return;
|
||||
|
||||
wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0);
|
||||
wstr = _alloca(wsize * sizeof(wchar_t));
|
||||
wstr = (WCHAR*)_alloca(wsize * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize);
|
||||
|
||||
SetBkColor(dc, convert_color(cbg));
|
||||
@ -376,7 +375,7 @@ nk_gdifont_get_text_width(nk_handle handle, float height, const char *text, int
|
||||
return 0;
|
||||
|
||||
wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0);
|
||||
wstr = _alloca(wsize * sizeof(wchar_t));
|
||||
wstr = (WCHAR*)_alloca(wsize * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize);
|
||||
if (GetTextExtentPoint32W(font->dc, wstr, wsize, &size))
|
||||
return (float)size.cx;
|
||||
@ -410,7 +409,7 @@ nk_gdi_clipbard_paste(nk_handle usr, struct nk_text_edit *edit)
|
||||
int utf8size = WideCharToMultiByte(CP_UTF8, 0, wstr, (int)(size / sizeof(wchar_t)), NULL, 0, NULL, NULL);
|
||||
if (utf8size)
|
||||
{
|
||||
char* utf8 = malloc(utf8size);
|
||||
char* utf8 = (char*)malloc(utf8size);
|
||||
if (utf8)
|
||||
{
|
||||
WideCharToMultiByte(CP_UTF8, 0, wstr, (int)(size / sizeof(wchar_t)), utf8, utf8size, NULL, NULL);
|
||||
@ -434,10 +433,10 @@ nk_gdi_clipbard_copy(nk_handle usr, const char *text, int len)
|
||||
int wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0);
|
||||
if (wsize)
|
||||
{
|
||||
HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, (wsize + 1) * sizeof(wchar_t));
|
||||
HGLOBAL mem = (HGLOBAL)GlobalAlloc(GMEM_MOVEABLE, (wsize + 1) * sizeof(wchar_t));
|
||||
if (mem)
|
||||
{
|
||||
wchar_t* wstr = GlobalLock(mem);
|
||||
wchar_t* wstr = (wchar_t*)GlobalLock(mem);
|
||||
if (wstr)
|
||||
{
|
||||
MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize);
|
||||
|
@ -525,7 +525,7 @@ nk_gdip_draw_text(short x, short y, unsigned short w, unsigned short h,
|
||||
if(!text || !font || !len) return;
|
||||
|
||||
wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0);
|
||||
wstr = _alloca(wsize * sizeof(wchar_t));
|
||||
wstr = (WCHAR*)_alloca(wsize * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize);
|
||||
|
||||
GdipSetSolidFillColor(gdip.brush, convert_color(cbg));
|
||||
@ -553,7 +553,7 @@ nk_gdipfont_create(const char *name, int size)
|
||||
GpFontFamily *family;
|
||||
|
||||
int wsize = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0);
|
||||
WCHAR* wname = _alloca((wsize + 1) * sizeof(wchar_t));
|
||||
WCHAR* wname = (WCHAR*)_alloca((wsize + 1) * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, name, -1, wname, wsize);
|
||||
wname[wsize] = 0;
|
||||
|
||||
@ -577,7 +577,7 @@ nk_gdipfont_get_text_width(nk_handle handle, float height, const char *text, int
|
||||
|
||||
(void)height;
|
||||
wsize = MultiByteToWideChar(CP_UTF8, 0, text, len, NULL, 0);
|
||||
wstr = _alloca(wsize * sizeof(wchar_t));
|
||||
wstr = (WCHAR*)_alloca(wsize * sizeof(wchar_t));
|
||||
MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize);
|
||||
|
||||
GdipMeasureString(gdip.memory, wstr, wsize, font, &layout, gdip.format, &bbox, NULL, NULL);
|
||||
@ -604,7 +604,7 @@ nk_gdip_clipbard_paste(nk_handle usr, struct nk_text_edit *edit)
|
||||
if (!IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL))
|
||||
return;
|
||||
|
||||
mem = GetClipboardData(CF_UNICODETEXT);
|
||||
mem = (HGLOBAL)GetClipboardData(CF_UNICODETEXT);
|
||||
if (!mem) {
|
||||
CloseClipboard();
|
||||
return;
|
||||
@ -629,7 +629,7 @@ nk_gdip_clipbard_paste(nk_handle usr, struct nk_text_edit *edit)
|
||||
return;
|
||||
}
|
||||
|
||||
utf8 = malloc(utf8size);
|
||||
utf8 = (char*)malloc(utf8size);
|
||||
if (!utf8) {
|
||||
GlobalUnlock(mem);
|
||||
CloseClipboard();
|
||||
@ -660,13 +660,13 @@ nk_gdip_clipbard_copy(nk_handle usr, const char *text, int len)
|
||||
return;
|
||||
}
|
||||
|
||||
mem = GlobalAlloc(GMEM_MOVEABLE, (wsize + 1) * sizeof(wchar_t));
|
||||
mem = (HGLOBAL)GlobalAlloc(GMEM_MOVEABLE, (wsize + 1) * sizeof(wchar_t));
|
||||
if (!mem) {
|
||||
CloseClipboard();
|
||||
return;
|
||||
}
|
||||
|
||||
wstr = GlobalLock(mem);
|
||||
wstr = (wchar_t*)GlobalLock(mem);
|
||||
if (!wstr) {
|
||||
GlobalFree(mem);
|
||||
CloseClipboard();
|
||||
@ -676,10 +676,8 @@ nk_gdip_clipbard_copy(nk_handle usr, const char *text, int len)
|
||||
MultiByteToWideChar(CP_UTF8, 0, text, len, wstr, wsize);
|
||||
wstr[wsize] = 0;
|
||||
GlobalUnlock(mem);
|
||||
|
||||
if (!SetClipboardData(CF_UNICODETEXT, mem))
|
||||
GlobalFree(mem);
|
||||
|
||||
CloseClipboard();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user