Start fixing speedmeter

This commit is contained in:
Vincent Lejeune 2014-10-17 18:19:23 +02:00
parent 3694758f56
commit f67f207d4b
3 changed files with 102 additions and 3 deletions

View File

@ -655,6 +655,39 @@ void draw2DImage(const video::ITexture* texture, const core::rect<s32>& 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<s32>& position,
const core::rect<s32>* clip)
{

View File

@ -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<s32> needs these includes
#include <rect.h>
#include "utils/vec3.hpp"
@ -153,6 +215,10 @@ void draw2DImage(const irr::video::ITexture* texture, const irr::core::rect<s32>
const irr::core::rect<s32>& sourceRect, const irr::core::rect<s32>* 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<s32>& position,
const irr::core::rect<s32>* clip = 0);

View File

@ -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