示例#1
0
文件: Mesh.cpp 项目: jomanto/le2
Mesh::Mesh()
{
  BufferLayout layout;
  layout.add(ET_vec3_f32, UT_position);
  layout.add(ET_vec2_f32, UT_texcoord0);
  init(layout, ET_u16);
}
示例#2
0
DrawContext::DrawContext(Context* ctx)
{
  glContext = ctx;
  
  _textBuffer = new TextBuffer;
  
  // load some common shaders
  colorShader = Application::instance()->resourceManager->shader("resources/glsl/color");
  textureShader = Application::instance()->resourceManager->shader("resources/glsl/texture");
  
  // create buffers for efficient quad drawing. Vertex and index buffers are reused as often as possible
  BufferLayout layout;
  layout.add(ET_vec2_f32, UT_position);
  layout.add(ET_vec2_f32, UT_texcoord0);
  bgquad = Mesh::create(layout, ET_u16);
  bgquad->resetSize(4, 6);
  bgquad->indexBuffer->drawMode = GL_TRIANGLES;
  
  bgquad->set(0, UT_position, Vec2(0,0));
  bgquad->set(1, UT_position, Vec2(1,0));
  bgquad->set(2, UT_position, Vec2(1,1));
  bgquad->set(3, UT_position, Vec2(0,1));
  
  bgquad->set(0,UT_texcoord0, Vec2(0,0));
  bgquad->set(1,UT_texcoord0, Vec2(1,0));
  bgquad->set(2,UT_texcoord0, Vec2(1,1));
  bgquad->set(3,UT_texcoord0, Vec2(0,1));
  
  bgquad->set(0, UT_index, (u16)0);
  bgquad->set(1, UT_index, (u16)1);
  bgquad->set(2, UT_index, (u16)2);
  bgquad->set(3, UT_index, (u16)2);
  bgquad->set(4, UT_index, (u16)3);
  bgquad->set(5, UT_index, (u16)0);
  
  bgquad->material->shader = colorShader;
  bgquad->material->color = whiteColor;
  bgquad->material->blendPremultiplied();
  
  textMesh.reset(new TextMesh);
  textMesh->material->shader = textureShader;
  textMesh->material->color = whiteColor;
  
  _flipX = false;
  _flipY = false;
  updateTexCoords();
  
  ninePatch.reset(new NinePatch);
  ninePatch->flip = true;
  ninePatch->material->shader = textureShader;
  ninePatch->material->blendPremultiplied();
}
示例#3
0
文件: NinePatch.cpp 项目: jomanto/le2
void NinePatch::init()
{
  BufferLayout layout;
  layout.add(ET_vec2_f32, UT_position);
  layout.add(ET_vec2_f32, UT_texcoord0);
  this->resetBuffers(layout, ET_u16);

  indexBuffer->drawMode = GL_TRIANGLES;

  u32 numVertices = 16; // draw it on paper and you'll see it's correct
  uint32_t numQuads = 9; // it's a 3x3 matrix of quads
  uint32_t numTris = numQuads*2; // each quad is drawn with two tris
  u32 numIndices = numTris*3; // currently, each tri is drawn with 3 indices

  this->vertexBuffer->reset(numVertices);
  this->indexBuffer->reset(numIndices);

//  updateTexCoords();
  updateIndices();

}
示例#4
0
HybridIndexBuffer::HybridIndexBuffer(ElementType et)
{
  // an indexbuffer only ever has one attribute with usage type index in a single partition
  // only the element type can vary, to optimize the buffer for hardware requirements or
  // mesh sizes.
  BufferLayout layout;
  layout.add(et, UT_index);
  switch(et)
  {
    case ET_u8:type = GL_UNSIGNED_BYTE;break;
    case ET_u16:type = GL_UNSIGNED_SHORT;break;
    case ET_u32:type = GL_UNSIGNED_INT;break;
    default:
      ASSERT(false,"only u8, u16, u32 are allowed");
  }
  drawMode = GL_TRIANGLES;
  init(GL_ELEMENT_ARRAY_BUFFER, layout);
}
HybridIndexBuffer::HybridIndexBuffer(ElementType et)
{
  // an indexbuffer only ever has one attribute with usage type index in a single partition
  // only the element type can vary, to optimize the buffer for hardware requirements or
  // mesh sizes.
  BufferLayout layout;
  layout.add(et, UT_index);
  switch(et)
  {
    case ET_u8:type = GL_UNSIGNED_BYTE;break;
    case ET_u16:type = GL_UNSIGNED_SHORT;break;
    case ET_u32:type = GL_UNSIGNED_INT;break;
    default:
      lost::common::StringStream os;
      os << "only u8, u16, u32 are allowed";
      LOGTHROW(std::runtime_error(os.str().c_str()));
  }
  drawMode = GL_TRIANGLES;
  init(GL_ELEMENT_ARRAY_BUFFER, layout);
  BB_INC(bb_hib_key);
}