STKMesh: Rendering works...sortof

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@15002 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
vincentlj
2014-01-12 00:26:18 +00:00
parent b5a9932169
commit ebaec55f4d
4 changed files with 43 additions and 11 deletions

View File

@@ -1,8 +1,10 @@
#version 130
uniform sampler2D texture;
in vec2 uv;
void main(void)
{
gl_FragData[0] = vec4(1., 0., 0., 1.);
gl_FragData[0] = texture2D(texture, uv);
gl_FragData[1] = vec4(0., 0., 0., 1.);
gl_FragData[2] = vec4(0., 0., 0., 1.);
}

View File

@@ -2,8 +2,11 @@
uniform mat4 ModelViewProjectionMatrix;
in vec3 Position;
in vec2 Texcoord;
out vec2 uv;
void main(void)
{
uv = Texcoord;
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
}

View File

@@ -6,13 +6,17 @@
namespace ObjectShader
{
GLuint Program;
GLuint attrib_position, attrib_velocity, attrib_lifetime, attrib_initial_position, attrib_initial_velocity, attrib_initial_lifetime, attrib_size, attrib_initial_size;
GLuint uniform_sourcematrix, uniform_dt, uniform_level, uniform_size_increase_factor;
GLuint attrib_position, attrib_texcoord;
GLuint uniform_MVP, uniform_texture;
void init()
{
initGL();
Program = LoadProgram(file_manager->getAsset("shaders/object.vert").c_str(), file_manager->getAsset("shaders/object.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_texture = glGetUniformLocation(Program, "texture");
}
}
@@ -117,6 +121,20 @@ STKMesh::STKMesh(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::IScene
Stride.push_back(sizeof(video::S3DVertexTangents));
break;
}
switch (mb->getIndexType())
{
case video::EIT_16BIT:
Indextype.push_back(GL_UNSIGNED_SHORT);
break;
case video::EIT_32BIT:
Indextype.push_back(GL_UNSIGNED_INT);
break;
}
ITexture *tex = mb->getMaterial().getTexture(0);
if (tex)
textures.push_back(static_cast<irr::video::COpenGLTexture*>(tex)->getOpenGLTextureName());
else
textures.push_back(0);
}
if (!ObjectShader::Program)
ObjectShader::init();
@@ -130,6 +148,8 @@ STKMesh::~STKMesh()
void STKMesh::draw(unsigned i)
{
if (!textures[i])
return;
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDisable(GL_CULL_FACE);
@@ -143,12 +163,19 @@ void STKMesh::draw(unsigned i)
core::matrix4 ModelViewProjectionMatrix = irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION);
ModelViewProjectionMatrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW);
ModelViewProjectionMatrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD);
GLuint attrib_pos = glGetUniformLocation(ObjectShader::Program, "ModelViewProjectionMatrix");
glUniformMatrix4fv(attrib_pos, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, Stride[i], 0);
glDrawElements(ptype, count, GL_UNSIGNED_BYTE, 0);
glDisableVertexAttribArray(0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[i]);
glUniform1f(ObjectShader::uniform_texture, 0);
glUniformMatrix4fv(ObjectShader::uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glEnableVertexAttribArray(ObjectShader::attrib_position);
glEnableVertexAttribArray(ObjectShader::attrib_texcoord);
glVertexAttribPointer(ObjectShader::attrib_position, 3, GL_FLOAT, GL_FALSE, Stride[i], 0);
glVertexAttribPointer(ObjectShader::attrib_texcoord, 2, GL_FLOAT, GL_FALSE, Stride[i], (GLvoid*) 28);
glDrawElements(ptype, count, Indextype[i], 0);
glDisableVertexAttribArray(ObjectShader::attrib_position);
glDisableVertexAttribArray(ObjectShader::attrib_texcoord);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
video::SMaterial material;

View File

@@ -11,8 +11,8 @@
class STKMesh : public irr::scene::CMeshSceneNode
{
protected:
std::vector<GLuint> vertex_buffer, index_buffer;
std::vector<GLenum> Primitivetype;
std::vector<GLuint> vertex_buffer, index_buffer, textures;
std::vector<GLenum> Primitivetype, Indextype;
std::vector<size_t> Indexcount;
std::vector<size_t> Stride;