- Most recent version is in with index buffer supportlegacy
@@ -103,14 +103,12 @@ public: | |||||
m_shader->SetUniform(m_mvp, m_matrix); | m_shader->SetUniform(m_mvp, m_matrix); | ||||
m_lines_ibo->Bind(); | m_lines_ibo->Bind(); | ||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Lines, 0, 0, | |||||
m_mesh.count(), 0, m_lines_indices.count()); | |||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Lines, m_lines_indices.count()); | |||||
m_lines_ibo->Unbind(); | m_lines_ibo->Unbind(); | ||||
m_shader->SetUniform(m_mvp, m_matrix * mat4::scale(0.5f)); | m_shader->SetUniform(m_mvp, m_matrix * mat4::scale(0.5f)); | ||||
m_faces_ibo->Bind(); | m_faces_ibo->Bind(); | ||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, | |||||
m_mesh.count(), 0, m_faces_indices.count()); | |||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, m_faces_indices.count()); | |||||
m_faces_ibo->Unbind(); | m_faces_ibo->Unbind(); | ||||
m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
@@ -199,14 +199,12 @@ public: | |||||
m_shader->SetUniform(m_mvp, m_matrix); | m_shader->SetUniform(m_mvp, m_matrix); | ||||
m_lines_ibo->Bind(); | m_lines_ibo->Bind(); | ||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Lines, 0, 0, | |||||
m_mesh.count(), 0, m_lines_indices.count()); | |||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Lines, m_lines_indices.count()); | |||||
m_lines_ibo->Unbind(); | m_lines_ibo->Unbind(); | ||||
m_shader->SetUniform(m_mvp, m_matrix * mat4::scale(0.5f)); | m_shader->SetUniform(m_mvp, m_matrix * mat4::scale(0.5f)); | ||||
m_faces_ibo->Bind(); | m_faces_ibo->Bind(); | ||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, | |||||
m_mesh.count(), 0, m_faces_indices.count()); | |||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, m_faces_indices.count()); | |||||
m_faces_ibo->Unbind(); | m_faces_ibo->Unbind(); | ||||
m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
@@ -44,6 +44,14 @@ public: | |||||
ImGui::SetNextWindowFocus(); | ImGui::SetNextWindowFocus(); | ||||
ImGui::Begin("testature"); | ImGui::Begin("testature"); | ||||
{ | { | ||||
if (ImGui::IsWindowHovered()) | |||||
ImGui::Text("Hovered: true"); | |||||
else | |||||
ImGui::Text("Hovered: false"); | |||||
if (ImGui::IsWindowFocused()) | |||||
ImGui::Text("Focused: true"); | |||||
else | |||||
ImGui::Text("Focused: false"); | |||||
ImGui::Text("Hello, world!"); | ImGui::Text("Hello, world!"); | ||||
ImGui::Text("prout!"); | ImGui::Text("prout!"); | ||||
ImGui::Text("prout!%i", 100); | ImGui::Text("prout!%i", 100); | ||||
@@ -58,10 +66,20 @@ public: | |||||
ImGui::Text("Ctrl: %s", io.KeyCtrl ? "true" : "false"); | ImGui::Text("Ctrl: %s", io.KeyCtrl ? "true" : "false"); | ||||
ImGui::Text("Clipboard %s", LolImGui::GetClipboard()); | ImGui::Text("Clipboard %s", LolImGui::GetClipboard()); | ||||
ImGui::InputText("base input", buf, 512); | ImGui::InputText("base input", buf, 512); | ||||
if (ImGui::IsItemActive()) | |||||
} | |||||
ImGui::End(); | |||||
ImGui::Begin("SO FUN !!"); | |||||
{ | |||||
if (ImGui::IsWindowHovered()) | |||||
ImGui::Text("Hovered: true"); | |||||
else | |||||
ImGui::Text("Hovered: false"); | |||||
if (ImGui::IsWindowFocused()) | |||||
ImGui::Text("Focused: true"); | ImGui::Text("Focused: true"); | ||||
else | else | ||||
ImGui::Text("Focused: false"); | ImGui::Text("Focused: false"); | ||||
ImGui::Text("poucka!"); | |||||
ImGui::Text(" poucka!"); | |||||
} | } | ||||
ImGui::End(); | ImGui::End(); | ||||
} | } | ||||
@@ -4,7 +4,12 @@ Size=400,400 | |||||
Collapsed=0 | Collapsed=0 | ||||
[testature] | [testature] | ||||
Pos=140,75 | |||||
Size=197,287 | |||||
Pos=266,15 | |||||
Size=494,359 | |||||
Collapsed=0 | |||||
[SO FUN !!] | |||||
Pos=30,24 | |||||
Size=113,99 | |||||
Collapsed=0 | Collapsed=0 | ||||
@@ -454,7 +454,7 @@ void GpuEasyMeshData::RenderMeshData(mat4 const &model, int render_mode) | |||||
vdecl->SetStream(vbo, Attribs[0], Attribs[1], Attribs[2], Attribs[3]); | vdecl->SetStream(vbo, Attribs[0], Attribs[1], Attribs[2], Attribs[3]); | ||||
m_ibo->Bind(); | m_ibo->Bind(); | ||||
vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, m_vertexcount, 0, m_indexcount); | |||||
vdecl->DrawIndexedElements(MeshPrimitive::Triangles, m_indexcount); | |||||
m_ibo->Unbind(); | m_ibo->Unbind(); | ||||
vdecl->Unbind(); | vdecl->Unbind(); | ||||
} | } | ||||
@@ -103,45 +103,30 @@ void VertexDeclaration::DrawElements(MeshPrimitive type, int skip, int count) | |||||
} | } | ||||
} | } | ||||
void VertexDeclaration::DrawIndexedElements_(MeshPrimitive type, int count, const short* skip) | |||||
{ | |||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, skip); | |||||
} | |||||
void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int vbase, | |||||
int vskip, int vcount, | |||||
int skip, int count) | |||||
void VertexDeclaration::DrawIndexedElements(MeshPrimitive type, int count, const short* skip, short typeSize) | |||||
{ | { | ||||
if (count <= 0) | if (count <= 0) | ||||
return; | return; | ||||
uint32_t elementType = typeSize == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT; | |||||
/* FIXME: this has nothing to do here! */ | /* FIXME: this has nothing to do here! */ | ||||
switch (type.ToScalar()) | switch (type.ToScalar()) | ||||
{ | { | ||||
case MeshPrimitive::Triangles: | case MeshPrimitive::Triangles: | ||||
/* FIXME: ignores most of the arguments! */ | |||||
UNUSED(vbase, vskip, vcount, skip); | |||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT, 0); | |||||
glDrawElements(GL_TRIANGLES, count, elementType, skip); | |||||
break; | break; | ||||
case MeshPrimitive::TriangleStrips: | case MeshPrimitive::TriangleStrips: | ||||
/* FIXME: ignores most of the arguments! */ | |||||
UNUSED(vbase, vskip, vcount, skip); | |||||
glDrawElements(GL_TRIANGLE_STRIP, count, GL_UNSIGNED_SHORT, 0); | |||||
break; | |||||
glDrawElements(GL_TRIANGLE_STRIP, count, elementType, skip); | |||||
break; | |||||
case MeshPrimitive::TriangleFans: | case MeshPrimitive::TriangleFans: | ||||
/* FIXME: ignores most of the arguments! */ | |||||
UNUSED(vbase, vskip, vcount, skip); | |||||
glDrawElements(GL_TRIANGLE_FAN, count, GL_UNSIGNED_SHORT, 0); | |||||
glDrawElements(GL_TRIANGLE_FAN, count, elementType, skip); | |||||
break; | break; | ||||
case MeshPrimitive::Points: | case MeshPrimitive::Points: | ||||
/* FIXME: ignores most of the arguments! */ | |||||
UNUSED(vbase, vskip, vcount, skip); | |||||
glDrawElements(GL_POINTS, count, GL_UNSIGNED_SHORT, 0); | |||||
glDrawElements(GL_POINTS, count, elementType, skip); | |||||
break; | break; | ||||
case MeshPrimitive::Lines: | case MeshPrimitive::Lines: | ||||
/* FIXME: ignores most of the arguments! */ | |||||
UNUSED(vbase, vskip, vcount, skip); | |||||
glDrawElements(GL_LINES, count, GL_UNSIGNED_SHORT, 0); | |||||
glDrawElements(GL_LINES, count, elementType, skip); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
@@ -212,9 +212,7 @@ public: | |||||
/* Draw elements. See MeshPrimitive for a list of all available | /* Draw elements. See MeshPrimitive for a list of all available | ||||
* types. Both skip and count are numbers of indices, not primitives. */ | * types. Both skip and count are numbers of indices, not primitives. */ | ||||
void DrawIndexedElements_(MeshPrimitive type, int count, const short* skip); | |||||
void DrawIndexedElements(MeshPrimitive type, int vbase, int vskip, | |||||
int vcount, int skip, int count); | |||||
void DrawIndexedElements(MeshPrimitive type, int count, const short* skip = nullptr, short typeSize = 2); | |||||
void Unbind(); | void Unbind(); | ||||
void SetStream(VertexBuffer *vb, ShaderAttrib attr1, | void SetStream(VertexBuffer *vb, ShaderAttrib attr1, | ||||
@@ -78,7 +78,6 @@ LolImGui::LolImGui() | |||||
Ticker::Ref(m_controller = new Controller("ImGui_Controller")); | Ticker::Ref(m_controller = new Controller("ImGui_Controller")); | ||||
m_controller->Init(m_profile); | m_controller->Init(m_profile); | ||||
//InputDevice::CaptureMouse(true); | |||||
m_mouse = InputDevice::GetMouse(); | m_mouse = InputDevice::GetMouse(); | ||||
m_keyboard = InputDevice::GetKeyboard(); | m_keyboard = InputDevice::GetKeyboard(); | ||||
@@ -234,7 +233,7 @@ void LolImGui::TickGame(float seconds) | |||||
cursor.y = 1.f - cursor.y; | cursor.y = 1.f - cursor.y; | ||||
cursor *= video_size; | cursor *= video_size; | ||||
io.MousePos = ImVec2(cursor.x, cursor.y); | io.MousePos = ImVec2(cursor.x, cursor.y); | ||||
msg::debug("%.2f/%.2f\n", io.MousePos.x, io.MousePos.y); | |||||
//msg::debug("%.2f/%.2f\n", io.MousePos.x, io.MousePos.y); | |||||
io.MouseWheel = m_controller->GetAxisValue(LolImGuiAxis::Scroll); | io.MouseWheel = m_controller->GetAxisValue(LolImGuiAxis::Scroll); | ||||
for (int i = LolImGuiKey::MOUSE_KEY_START; i < LolImGuiKey::MOUSE_KEY_END; ++i) | for (int i = LolImGuiKey::MOUSE_KEY_START; i < LolImGuiKey::MOUSE_KEY_END; ++i) | ||||
@@ -247,11 +246,13 @@ void LolImGui::TickGame(float seconds) | |||||
case LolImGuiKey::Focus: | case LolImGuiKey::Focus: | ||||
if (m_controller->IsKeyReleased(i)) | if (m_controller->IsKeyReleased(i)) | ||||
{ | { | ||||
msg::debug("Not focused .....\n"); | |||||
//msg::debug("Not focused .....\n"); | |||||
io.MousePos = ImVec2(-1.f, -1.f); | io.MousePos = ImVec2(-1.f, -1.f); | ||||
} | } | ||||
else | else | ||||
msg::debug("Focused !!\n"); | |||||
{ | |||||
//msg::debug("Focused !!\n"); | |||||
} | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
@@ -309,10 +310,8 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) | |||||
String code; | String code; | ||||
m_builder.Build(code); | m_builder.Build(code); | ||||
msg::debug("\nCREATED SHADER:\n%s\n", code.C()); | |||||
m_shader = Shader::Create(m_builder.GetName(), code); | m_shader = Shader::Create(m_builder.GetName(), code); | ||||
ASSERT(m_shader); | ASSERT(m_shader); | ||||
msg::debug("\nPATCHED SHADER:\n%s\n", code.C()); | |||||
m_ortho.m_uniform = m_shader->GetUniformLocation(m_ortho.m_var); | m_ortho.m_uniform = m_shader->GetUniformLocation(m_ortho.m_var); | ||||
m_texture.m_uniform = m_shader->GetUniformLocation(m_texture.m_var); | m_texture.m_uniform = m_shader->GetUniformLocation(m_texture.m_var); | ||||
@@ -359,8 +358,8 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) | |||||
vbo->Unlock(); | vbo->Unlock(); | ||||
IndexBuffer *ibo = new IndexBuffer(cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); | IndexBuffer *ibo = new IndexBuffer(cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); | ||||
uint16_t *indices = (uint16_t *)ibo->Lock(0, 0); | |||||
memcpy(vert, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); | |||||
ImDrawIdx *indices = (ImDrawIdx *)ibo->Lock(0, 0); | |||||
memcpy(indices, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx)); | |||||
ibo->Unlock(); | ibo->Unlock(); | ||||
m_font->Bind(); | m_font->Bind(); | ||||
@@ -371,12 +370,16 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) | |||||
const ImDrawIdx* idx_buffer_offset = 0; | const ImDrawIdx* idx_buffer_offset = 0; | ||||
for (size_t cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) | for (size_t cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) | ||||
{ | { | ||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; | |||||
const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[(int)cmd_i]; | |||||
#ifdef SHOW_IMGUI_DEBUG | #ifdef SHOW_IMGUI_DEBUG | ||||
//----------------------------------------------------------------- | //----------------------------------------------------------------- | ||||
//<Debug render> -------------------------------------------------- | //<Debug render> -------------------------------------------------- | ||||
//----------------------------------------------------------------- | //----------------------------------------------------------------- | ||||
//Doesn't work anymore ...... | |||||
static uint32_t idx_buffer_offset_i = 0; | |||||
if (cmd_i == 0) | |||||
idx_buffer_offset_i = 0; | |||||
float mod = -200.f; | float mod = -200.f; | ||||
vec3 off = vec3(vec2(-size.x, -size.y), 0.f); | vec3 off = vec3(vec2(-size.x, -size.y), 0.f); | ||||
vec3 pos[4] = { | vec3 pos[4] = { | ||||
@@ -387,29 +390,32 @@ void LolImGui::RenderDrawListsMethod(ImDrawData* draw_data) | |||||
}; | }; | ||||
for (int i = 0; i < 4; ++i) | for (int i = 0; i < 4; ++i) | ||||
Debug::DrawLine(pos[i], pos[(i + 1) % 4], Color::white); | Debug::DrawLine(pos[i], pos[(i + 1) % 4], Color::white); | ||||
ImDrawVert* buf = (ImDrawVert*)(vtx_buffer + vtx_offset); | |||||
ImDrawVert* buf = vert; | |||||
for (uint16_t i = 0; i < pcmd->ElemCount; i += 3) | for (uint16_t i = 0; i < pcmd->ElemCount; i += 3) | ||||
{ | { | ||||
uint16_t ib = indices[idx_buffer_offset_i + i]; | |||||
vec2 pos[3]; | vec2 pos[3]; | ||||
pos[0] = vec2(buf[i + 0].pos.x, buf[i + 0].pos.y); | |||||
pos[1] = vec2(buf[i + 1].pos.x, buf[i + 1].pos.y); | |||||
pos[2] = vec2(buf[i + 2].pos.x, buf[i + 2].pos.y); | |||||
pos[0] = vec2(buf[ib + 0].pos.x, buf[ib + 0].pos.y); | |||||
pos[1] = vec2(buf[ib + 1].pos.x, buf[ib + 1].pos.y); | |||||
pos[2] = vec2(buf[ib + 2].pos.x, buf[ib + 2].pos.y); | |||||
vec4 col[3]; | vec4 col[3]; | ||||
col[0] = vec4(Color::FromRGBA32(buf[i + 0].col).arg, 1.f); | |||||
col[1] = vec4(Color::FromRGBA32(buf[i + 1].col).arg, 1.f); | |||||
col[2] = vec4(Color::FromRGBA32(buf[i + 2].col).arg, 1.f); | |||||
col[0] = vec4(Color::FromRGBA32(buf[ib + 0].col).arg, 1.f); | |||||
col[1] = vec4(Color::FromRGBA32(buf[ib + 1].col).arg, 1.f); | |||||
col[2] = vec4(Color::FromRGBA32(buf[ib + 2].col).arg, 1.f); | |||||
Debug::DrawLine((off + vec3(pos[0], 0.f)) / mod, (off + vec3(pos[1], 0.f)) / mod, col[0]); | Debug::DrawLine((off + vec3(pos[0], 0.f)) / mod, (off + vec3(pos[1], 0.f)) / mod, col[0]); | ||||
Debug::DrawLine((off + vec3(pos[1], 0.f)) / mod, (off + vec3(pos[2], 0.f)) / mod, col[1]); | Debug::DrawLine((off + vec3(pos[1], 0.f)) / mod, (off + vec3(pos[2], 0.f)) / mod, col[1]); | ||||
Debug::DrawLine((off + vec3(pos[2], 0.f)) / mod, (off + vec3(pos[0], 0.f)) / mod, col[2]); | Debug::DrawLine((off + vec3(pos[2], 0.f)) / mod, (off + vec3(pos[0], 0.f)) / mod, col[2]); | ||||
} | } | ||||
//----------------------------------------------------------------- | |||||
idx_buffer_offset_i += pcmd->ElemCount; | |||||
//----------------------------------------------------------------- | |||||
//<\Debug render> ------------------------------------------------- | //<\Debug render> ------------------------------------------------- | ||||
//----------------------------------------------------------------- | //----------------------------------------------------------------- | ||||
#endif //SHOW_IMGUI_DEBUG | #endif //SHOW_IMGUI_DEBUG | ||||
Debug::DrawLine(vec2::zero, vec2::axis_x, Color::green); | |||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, pcmd->ElemCount, (const short*)idx_buffer_offset); | |||||
m_vdecl->DrawIndexedElements_(MeshPrimitive::Triangles, pcmd->ElemCount, (const short*)idx_buffer_offset); | |||||
//m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, 0, 0, pcmd->ElemCount); | |||||
//m_vdecl->DrawElements(MeshPrimitive::Triangles, (int)idx_buffer_offset, pcmd->ElemCount); | |||||
idx_buffer_offset += pcmd->ElemCount; | idx_buffer_offset += pcmd->ElemCount; | ||||
} | } | ||||
@@ -146,8 +146,7 @@ void SubMesh::Render() | |||||
m_ibo->Bind(); | m_ibo->Bind(); | ||||
m_vdecl->Bind(); | m_vdecl->Bind(); | ||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, 0, 0, vertex_count, | |||||
0, m_ibo->GetSize() / sizeof(uint16_t)); | |||||
m_vdecl->DrawIndexedElements(MeshPrimitive::Triangles, m_ibo->GetSize() / sizeof(uint16_t)); | |||||
m_vdecl->Unbind(); | m_vdecl->Unbind(); | ||||
m_ibo->Unbind(); | m_ibo->Unbind(); | ||||
} | } | ||||