STKMesh: Rendering implemented although it's a big red shader
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@15000 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
d255f4f049
commit
15dc149799
8
data/shaders/object.frag
Normal file
8
data/shaders/object.frag
Normal file
@ -0,0 +1,8 @@
|
||||
#version 130
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_FragData[0] = vec4(1., 0., 0., 1.);
|
||||
gl_FragData[1] = vec4(0., 0., 0., 1.);
|
||||
gl_FragData[2] = vec4(0., 0., 0., 1.);
|
||||
}
|
9
data/shaders/object.vert
Normal file
9
data/shaders/object.vert
Normal file
@ -0,0 +1,9 @@
|
||||
#version 130
|
||||
uniform mat4 ModelViewProjectionMatrix;
|
||||
|
||||
in vec3 Position;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
|
||||
}
|
@ -3,9 +3,23 @@
|
||||
#include <ISceneManager.h>
|
||||
#include <IMaterialRenderer.h>
|
||||
|
||||
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;
|
||||
|
||||
void init()
|
||||
{
|
||||
initGL();
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/object.vert").c_str(), file_manager->getAsset("shaders/object.frag").c_str());
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void allocateMeshBuffer(scene::IMeshBuffer* mb, GLuint &vbo, GLuint idx)
|
||||
{
|
||||
initGL();
|
||||
GLuint bufferid, indexbufferid;
|
||||
glGenBuffers(1, &bufferid);
|
||||
glGenBuffers(1, &indexbufferid);
|
||||
@ -91,8 +105,22 @@ STKMesh::STKMesh(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::IScene
|
||||
case scene::EPT_QUADS:
|
||||
assert(0 && "Unsupported primitive type");
|
||||
}
|
||||
switch (mb->getVertexType())
|
||||
{
|
||||
case video::EVT_STANDARD:
|
||||
Stride.push_back(sizeof(video::S3DVertex));
|
||||
break;
|
||||
case video::EVT_2TCOORDS:
|
||||
Stride.push_back(sizeof(video::S3DVertex2TCoords));
|
||||
break;
|
||||
case video::EVT_TANGENTS:
|
||||
Stride.push_back(sizeof(video::S3DVertexTangents));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ObjectShader::Program)
|
||||
ObjectShader::init();
|
||||
}
|
||||
|
||||
STKMesh::~STKMesh()
|
||||
{
|
||||
@ -108,11 +136,18 @@ void STKMesh::draw(unsigned i)
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idx);
|
||||
|
||||
/* glNormalPointer(GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(12));
|
||||
glColorPointer(colorSize, GL_UNSIGNED_BYTE, sizeof(S3DVertex2TCoords), buffer_offset(24));
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(28));
|
||||
glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex2TCoords), buffer_offset(0));*/
|
||||
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());
|
||||
glUseProgram(ObjectShader::Program);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, Stride[i], 0);
|
||||
glDisableVertexAttribArray(0);
|
||||
glDrawElements(ptype, count, GL_UNSIGNED_BYTE, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void STKMesh::render()
|
||||
@ -130,6 +165,11 @@ void STKMesh::render()
|
||||
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
|
||||
Box = Mesh->getBoundingBox();
|
||||
|
||||
for (unsigned i = 0; i < index_buffer.size(); i++)
|
||||
{
|
||||
// draw(i);
|
||||
}
|
||||
|
||||
for (u32 i=0; i<Mesh->getMeshBufferCount(); ++i)
|
||||
{
|
||||
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
|
||||
@ -145,6 +185,7 @@ void STKMesh::render()
|
||||
if (transparent == isTransparentPass)
|
||||
{
|
||||
driver->setMaterial(material);
|
||||
// static_cast<irr::video::COpenGLDriver*>(driver)->setRenderStates3DMode();
|
||||
driver->drawMeshBuffer(mb);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ protected:
|
||||
std::vector<GLuint> vertex_buffer, index_buffer;
|
||||
std::vector<GLenum> Primitivetype;
|
||||
std::vector<size_t> Indexcount;
|
||||
std::vector<size_t> Stride;
|
||||
|
||||
void draw(unsigned i);
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user