From f67f207d4b6fcda59bc0396625778213ce4391e0 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Fri, 17 Oct 2014 18:19:23 +0200 Subject: [PATCH] Start fixing speedmeter --- src/graphics/glwrap.cpp | 33 +++++++++++++++++ src/graphics/glwrap.hpp | 66 +++++++++++++++++++++++++++++++++ src/states_screens/race_gui.cpp | 6 +-- 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/src/graphics/glwrap.cpp b/src/graphics/glwrap.cpp index 86a84c5a5..d6d0ef9bf 100644 --- a/src/graphics/glwrap.cpp +++ b/src/graphics/glwrap.cpp @@ -655,6 +655,39 @@ void draw2DImage(const video::ITexture* texture, const core::rect& destRect glGetError(); } +void draw2DVertexPrimitiveList(const void* vertices, + u32 vertexCount, const void* indexList, u32 primitiveCount, + video::E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, video::E_INDEX_TYPE iType) +{ + if (!irr_driver->isGLSL()) + { + irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, vertexCount, indexList, primitiveCount, vType, pType, iType); + return; + } + GLuint tmpvao, tmpvbo, tmpibo; + glGenVertexArrays(1, &tmpvao); + glBindVertexArray(tmpvao); + glGenBuffers(1, &tmpvbo); + glBindBuffer(GL_ARRAY_BUFFER, tmpvbo); + glBufferData(GL_ARRAY_BUFFER, vertexCount * getVertexPitchFromType(vType), vertices, GL_STREAM_DRAW); + glGenBuffers(1, &tmpibo); + glBindBuffer(GL_ARRAY_BUFFER, tmpibo); + glBufferData(GL_ARRAY_BUFFER, primitiveCount * sizeof(u16), indexList, GL_STREAM_DRAW); + + glUseProgram(MeshShader::TransparentShader::getInstance()->Program); + MeshShader::TransparentShader::getInstance()->setUniforms(core::IdentityMatrix, core::IdentityMatrix); + const video::SOverrideMaterial &m = irr_driver->getVideoDriver()->getOverrideMaterial(); + video::ITexture* tex = getUnicolorTexture(video::SColor(255, 255, 255, 255)); + compressTexture(tex, false); + MeshShader::TransparentShader::getInstance()->SetTextureUnits({ getTextureGLuint(tex) }); + glDrawElements(GL_TRIANGLE_FAN, primitiveCount, GL_UNSIGNED_SHORT, 0); + + glDeleteVertexArrays(1, &tmpvao); + glDeleteBuffers(1, &tmpvbo); + glDeleteBuffers(1, &tmpibo); + +} + void GL32_draw2DRectangle(video::SColor color, const core::rect& position, const core::rect* clip) { diff --git a/src/graphics/glwrap.hpp b/src/graphics/glwrap.hpp index 3477b649b..dabf530f8 100644 --- a/src/graphics/glwrap.hpp +++ b/src/graphics/glwrap.hpp @@ -132,6 +132,68 @@ public: void BlitToDefault(size_t, size_t, size_t, size_t); }; +class VertexUtils +{ +public: + static void bindVertexArrayAttrib(enum video::E_VERTEX_TYPE tp) + { + switch (tp) + { + case video::EVT_STANDARD: + // Position + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), 0); + // Normal + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)12); + // Color + glEnableVertexAttribArray(2); + glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(tp), (GLvoid*)24); + // Texcoord + glEnableVertexAttribArray(3); + glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)28); + break; + case video::EVT_2TCOORDS: + // Position + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), 0); + // Normal + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)12); + // Color + glEnableVertexAttribArray(2); + glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(tp), (GLvoid*)24); + // Texcoord + glEnableVertexAttribArray(3); + glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)28); + // SecondTexcoord + glEnableVertexAttribArray(4); + glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)36); + break; + case video::EVT_TANGENTS: + // Position + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), 0); + // Normal + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)12); + // Color + glEnableVertexAttribArray(2); + glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, getVertexPitchFromType(tp), (GLvoid*)24); + // Texcoord + glEnableVertexAttribArray(3); + glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)28); + // Tangent + glEnableVertexAttribArray(5); + glVertexAttribPointer(5, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)36); + // Bitangent + glEnableVertexAttribArray(6); + glVertexAttribPointer(6, 3, GL_FLOAT, GL_FALSE, getVertexPitchFromType(tp), (GLvoid*)48); + break; + } + } +}; + // core::rect needs these includes #include #include "utils/vec3.hpp" @@ -153,6 +215,10 @@ void draw2DImage(const irr::video::ITexture* texture, const irr::core::rect const irr::core::rect& sourceRect, const irr::core::rect* clipRect, const irr::video::SColor* const colors, bool useAlphaChannelOfTexture); +void draw2DVertexPrimitiveList(const void* vertices, + u32 vertexCount, const void* indexList, u32 primitiveCount, + video::E_VERTEX_TYPE vType = video::EVT_STANDARD, scene::E_PRIMITIVE_TYPE pType = scene::EPT_TRIANGLES, video::E_INDEX_TYPE iType = video::EIT_16BIT); + void GL32_draw2DRectangle(irr::video::SColor color, const irr::core::rect& position, const irr::core::rect* clip = 0); diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 5accb0fd0..55b1327a5 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -506,7 +506,7 @@ void RaceGUI::drawEnergyMeter(int x, int y, const AbstractKart *kart, m.setTexture(0, m_gauge_goal); m.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; irr_driver->getVideoDriver()->setMaterial(m); - irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, count, + draw2DVertexPrimitiveList(vertices, count, index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN); } @@ -594,7 +594,7 @@ void RaceGUI::drawEnergyMeter(int x, int y, const AbstractKart *kart, m.setTexture(0, m_gauge_full); m.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; irr_driver->getVideoDriver()->setMaterial(m); - irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, count, + draw2DVertexPrimitiveList(vertices, count, index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN); } @@ -800,7 +800,7 @@ void RaceGUI::drawSpeedEnergyRank(const AbstractKart* kart, m.setTexture(0, m_speed_bar_icon->getTexture()); m.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; irr_driver->getVideoDriver()->setMaterial(m); - irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, count, + draw2DVertexPrimitiveList(vertices, count, index, count-2, video::EVT_STANDARD, scene::EPT_TRIANGLE_FAN); } // drawSpeedEnergyRank