This commit is contained in:
Бранимир Караџић 2019-07-20 18:37:55 -07:00
parent 1c7c9a0799
commit 89fd7afb09

View File

@ -449,7 +449,8 @@ namespace
const double freq = double(bx::getHPFrequency() );
const float deltaTime = float(frameTime / freq);
imguiBeginFrame(m_mouseState.m_mx
imguiBeginFrame(
m_mouseState.m_mx
, m_mouseState.m_my
, (m_mouseState.m_buttons[entry::MouseButton::Left] ? IMGUI_MBUT_LEFT : 0)
| (m_mouseState.m_buttons[entry::MouseButton::Right] ? IMGUI_MBUT_RIGHT : 0)
@ -469,40 +470,28 @@ namespace
ImVec2(m_width / 5.0f, m_height / 3.0f)
, ImGuiCond_FirstUseEver
);
ImGui::Begin("Settings"
, NULL
, 0
ImGui::Begin("Settings", NULL, 0);
if (ImGui::Checkbox("Debug wireframe", &m_wireframe) )
{
bgfx::setDebug(m_wireframe
? BGFX_DEBUG_WIREFRAME
: BGFX_DEBUG_NONE
);
if (ImGui::Checkbox("Debug wireframe", &m_wireframe)) {
if (m_wireframe) {
bgfx::setDebug(BGFX_DEBUG_WIREFRAME);
}
else {
bgfx::setDebug(BGFX_DEBUG_NONE);
}
}
ImGui::SameLine();
if (ImGui::Checkbox("Cull", &m_cull)) {
if (m_cull) {
m_uniforms.cull = 1.0;
}
else {
m_uniforms.cull = 0.0;
}
if (ImGui::Checkbox("Cull", &m_cull) )
{
m_uniforms.cull = m_cull ? 1.0f : 0.0f;
}
ImGui::SameLine();
if (ImGui::Checkbox("Freeze subdividing", &m_freeze)) {
if (m_freeze) {
m_uniforms.freeze = 1.0;
}
else {
m_uniforms.freeze = 0.0;
}
if (ImGui::Checkbox("Freeze subdividing", &m_freeze) )
{
m_uniforms.freeze = m_freeze ? 1.0f : 0.0f;
}
@ -510,16 +499,16 @@ namespace
int gpuSlider = (int)m_uniforms.gpuSubd;
if (ImGui::SliderInt("Triangle Patch level", &gpuSlider, 0, 3)) {
if (ImGui::SliderInt("Triangle Patch level", &gpuSlider, 0, 3) )
{
m_restart = true;
m_uniforms.gpuSubd = (float)gpuSlider;
m_uniforms.gpuSubd = float(gpuSlider);
}
ImGui::Combo("Shading", &m_shading, s_shaderOptions, 2);
ImGui::Text("Some variables require rebuilding the subdivide buffers and causes a stutter.");
ImGui::End();
if (!ImGui::MouseOverArea() )
@ -551,8 +540,8 @@ namespace
m_uniforms.submit();
// update the subd buffers
if (m_restart) {
if (m_restart)
{
m_pingPong = 1;
bgfx::destroy(m_instancedGeometryVertices);
@ -576,8 +565,8 @@ namespace
m_restart = false;
}
else {
else
{
// update batch
bgfx::setBuffer(3, m_dispatchIndirect, bgfx::Access::ReadWrite);
bgfx::setBuffer(4, m_bufferCounter, bgfx::Access::ReadWrite);
@ -686,8 +675,10 @@ namespace
const bgfx::Memory* mem = bgfx::alloc(w * h * 2 * sizeof(float) );
float* smap = (float*)mem->data;
for (int j = 0; j < h; ++j) {
for (int i = 0; i < w; ++i) {
for (int j = 0; j < h; ++j)
{
for (int i = 0; i < w; ++i)
{
int i1 = bx::max(0, i - 1);
int i2 = bx::min(w - 1, i + 1);
int j1 = bx::max(0, j - 1);
@ -708,12 +699,17 @@ namespace
}
}
m_textures[TEXTURE_SMAP] = bgfx::createTexture2D((uint16_t)w, (uint16_t)h, mipcnt > 1, 1, bgfx::TextureFormat::RG32F,
BGFX_TEXTURE_NONE, mem);
m_textures[TEXTURE_SMAP] = bgfx::createTexture2D(
(uint16_t)w
, (uint16_t)h
, mipcnt > 1
, 1
, bgfx::TextureFormat::RG32F
, BGFX_TEXTURE_NONE
, mem
);
}
/**
* Load the Displacement Texture
*
@ -723,8 +719,15 @@ namespace
{
dmap = imageLoad(m_dmap.pathToFile.getCPtr(), bgfx::TextureFormat::R16);
m_textures[TEXTURE_DMAP] = bgfx::createTexture2D((uint16_t)dmap->m_width, (uint16_t)dmap->m_height, false, 1, bgfx::TextureFormat::R16,
BGFX_TEXTURE_NONE, bgfx::makeRef(dmap->m_data, dmap->m_size));
m_textures[TEXTURE_DMAP] = bgfx::createTexture2D(
(uint16_t)dmap->m_width
, (uint16_t)dmap->m_height
, false
, 1
, bgfx::TextureFormat::R16
, BGFX_TEXTURE_NONE
, bgfx::makeRef(dmap->m_data, dmap->m_size)
);
}
/**
@ -745,35 +748,47 @@ namespace
**/
void loadGeometryBuffers()
{
float vertices[] = {
const float vertices[] =
{
-1.0f, -1.0f, 0.0f, 1.0f,
+1.0f, -1.0f, 0.0f, 1.0f,
+1.0f, +1.0f, 0.0f, 1.0f,
-1.0f, +1.0f, 0.0f, 1.0f
-1.0f, +1.0f, 0.0f, 1.0f,
};
uint32_t indices[] = {
0,
1,
3,
2,
3,
1
};
const uint32_t indices[] = { 0, 1, 3, 2, 3, 1 };
m_geometryDecl.begin().add(bgfx::Attrib::Position, 4, bgfx::AttribType::Float).end();
m_geometryVertices = bgfx::createVertexBuffer(bgfx::copy(vertices, sizeof(vertices)), m_geometryDecl, BGFX_BUFFER_COMPUTE_READ);
m_geometryIndices = bgfx::createIndexBuffer(bgfx::copy(indices, sizeof(indices)), BGFX_BUFFER_COMPUTE_READ | BGFX_BUFFER_INDEX32);
m_geometryVertices = bgfx::createVertexBuffer(
bgfx::copy(vertices, sizeof(vertices) )
, m_geometryDecl
, BGFX_BUFFER_COMPUTE_READ
);
m_geometryIndices = bgfx::createIndexBuffer(
bgfx::copy(indices, sizeof(indices) )
, BGFX_BUFFER_COMPUTE_READ | BGFX_BUFFER_INDEX32
);
}
void loadSubdivisionBuffers()
{
const size_t bufferCapacity = 1 << 27;
const uint32_t bufferCapacity = 1 << 27;
m_bufferSubd[BUFFER_SUBD] = bgfx::createDynamicIndexBuffer(bufferCapacity, BGFX_BUFFER_COMPUTE_READ_WRITE | BGFX_BUFFER_INDEX32);
m_bufferSubd[BUFFER_SUBD + 1] = bgfx::createDynamicIndexBuffer(bufferCapacity, BGFX_BUFFER_COMPUTE_READ_WRITE | BGFX_BUFFER_INDEX32);
m_bufferCulledSubd = bgfx::createDynamicIndexBuffer(bufferCapacity, BGFX_BUFFER_COMPUTE_READ_WRITE | BGFX_BUFFER_INDEX32);
m_bufferSubd[BUFFER_SUBD] = bgfx::createDynamicIndexBuffer(
bufferCapacity
, BGFX_BUFFER_COMPUTE_READ_WRITE | BGFX_BUFFER_INDEX32
);
m_bufferSubd[BUFFER_SUBD + 1] = bgfx::createDynamicIndexBuffer(
bufferCapacity
, BGFX_BUFFER_COMPUTE_READ_WRITE | BGFX_BUFFER_INDEX32
);
m_bufferCulledSubd = bgfx::createDynamicIndexBuffer(
bufferCapacity
, BGFX_BUFFER_COMPUTE_READ_WRITE | BGFX_BUFFER_INDEX32
);
}
/**
@ -827,10 +842,20 @@ namespace
break;
}
m_instancedGeometryDecl.begin().add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float).end();
m_instancedGeometryDecl
.begin()
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
.end();
m_instancedGeometryVertices = bgfx::createVertexBuffer(bgfx::makeRef(vertices, sizeof(float) * 2 * m_instancedMeshVertexCount), m_instancedGeometryDecl);
m_instancedGeometryIndices = bgfx::createIndexBuffer(bgfx::makeRef(indexes, sizeof(uint32_t) * m_instancedMeshPrimitiveCount * 3), BGFX_BUFFER_INDEX32);
m_instancedGeometryVertices = bgfx::createVertexBuffer(
bgfx::makeRef(vertices, sizeof(float) * 2 * m_instancedMeshVertexCount)
, m_instancedGeometryDecl
);
m_instancedGeometryIndices = bgfx::createIndexBuffer(
bgfx::makeRef(indexes, sizeof(uint32_t) * m_instancedMeshPrimitiveCount * 3)
, BGFX_BUFFER_INDEX32
);
}
Uniforms m_uniforms;