Beispiel #1
0
//----------------------------------------------------------------------
bool FontManager::Initialise(const glm::ivec2& screenResolution)
{
  this->screenResolution = screenResolution;

  if (!effect.Load("assets\\effects\\fonteffect.glsl", "RenderFont"))
  {
    LOG("did not load font rendering effect\n");
    return false;
  }
  // Since the screen resolution does not change at runtime, set this now...
  effect.ScreenSize->Set(glm::vec2(screenResolution));
  effect.GlyphTexture->Set(GlyphTextureSlot);

  sampler = boost::make_shared<Sampler2D>();
  sampler->SetMagFilter(GL_LINEAR);
  sampler->SetMinFilter(GL_LINEAR);
  sampler->SetWrapS(GL_CLAMP_TO_EDGE);
  sampler->SetWrapT(GL_CLAMP_TO_EDGE);

  VertexLayout vertexLayout;
  vertexLayout.AddAttribute(vertexAttribute);

  // Initialise vertex buffers for dynamic update...
  for (size_t i = 0; i < bufferCount; ++i)
  {
    boost::shared_ptr<VertexBuffer> vertexBuffer(new VertexBuffer());
    vertexBuffer->Initialise(vertexLayout, VerticesInBuffer, GL_DYNAMIC_DRAW);
    geometry[i].Initialise(vertexBuffer);
  }

  return true;
}
Beispiel #2
0
	bool TextureOverlay::CreateGeometry()
	{
		m_pGeometry						= m_pRenderManager->CreateGeometryData();
		if(m_pGeometry == nullptr)
		{
			return false;
		}

		struct Vertex
		{
			math::Vector3			pos;
			math::Vector2			uv;
		};
		Vertex verts[] = 
		{
			{math::Vector3(0, 0, 0),		math::Vector2(0, 0)},
			{math::Vector3(1, 0, 0),		math::Vector2(1, 0)},
			{math::Vector3(1, 1, 0),		math::Vector2(1, 1)},
			{math::Vector3(0, 1, 0),		math::Vector2(0, 1)},
			{math::Vector3(0, 0, 0),		math::Vector2(0, 0)},
			{math::Vector3(1, 1, 0),		math::Vector2(1, 1)},
		};

		VertexLayout layout;
		layout.AddAttribute(G_FORMAT_R32G32B32_FLOAT);
		layout.AddAttribute(G_FORMAT_R32G32_FLOAT);

		m_pGeometry->BeginGeometry(PT_TRIANGLE_LIST);
		{
			m_pGeometry->AllocVertexBuffer(sizeof(Vertex) * 6, verts, false, layout);
		}

		m_pGeometry->EndGeometry();
		return true;
	}
//////////////////////////////////////////////////////////////////////////
///  Particle Quad
gfx::ModelMesh* ContentManager::getParticleQuad()
{
    if (m_ParticleQuad == nullptr)
    {    
        using namespace gfx;
        VertexLayout layout;
        layout.addElement(VertexElement(eShaderAttribute_Position, eShaderAttributeType_Float, eShaderAttributeTypeComponents_3, 0));

        he::ObjectList<VertexPos> vertices(4);
        vertices.add(VertexPos(vec3(-1, 1, 0.0f)));
        vertices.add(VertexPos(vec3(1, 1, 0.0f)));
        vertices.add(VertexPos(vec3(-1, -1, 0.0f)));
        vertices.add(VertexPos(vec3(1, -1, 0.0f)));

        he::PrimitiveList<uint16> indices(6);
        indices.add(1); indices.add(0); indices.add(2);
        indices.add(1); indices.add(2); indices.add(3);

        ObjectHandle handle(ResourceFactory<ModelMesh>::getInstance()->create());
        m_ParticleQuad = ResourceFactory<ModelMesh>::getInstance()->get(handle);
        m_ParticleQuad->setName(he::String("Particle quad"));

        m_ParticleQuad->init(layout, gfx::MeshDrawMode_Triangles);
        m_ParticleQuad->setVertices(&vertices[0], 4, gfx::MeshUsage_Static, false);
        m_ParticleQuad->setIndices(&indices[0], 6, gfx::IndexStride_UShort, gfx::MeshUsage_Static);
        m_ParticleQuad->setLoaded(eLoadResult_Success);
    }

    m_ParticleQuad->instantiate();
    return m_ParticleQuad;
}
Beispiel #4
0
    static VertexLayout GetVertexLayout( PC_Vertexes& vertexes )
    {
        VertexLayout layout;

        layout.push_back( VertexAttributeProperties( "inPosition", 3, GL_FLOAT, false, sizeof( Vertex3D_PC ), (int) &vertexes[0].position ) );
        layout.push_back( VertexAttributeProperties( "inColor", 4, GL_UNSIGNED_BYTE, true, sizeof( Vertex3D_PC ), (int) &vertexes[0].color ) );

        return layout;
    }
Beispiel #5
0
VertexLayout VertexLayout::GetDefaultTerrainVertexLayout()
{
	const int structSize = sizeof(VertexDataTerrain);

	VertexLayout layout;
	layout.AddEntry("position", 0, 3, Float, false, structSize, (const void*)(offsetof(VertexDataTerrain, Position)));
	layout.AddEntry("uv", 1, 2, Float, false, structSize, (const void*)(offsetof(VertexDataTerrain, UV)));

	return layout;
}
Beispiel #6
0
VertexLayout VertexLayout::GetDefaultSpriteVertexLayout()
{
	const int structSize = sizeof(VertexDataS);

	VertexLayout layout;
	layout.AddEntry("position", 0, 3, Float, false, structSize, (const void*)(offsetof(VertexDataS, Position)));
	layout.AddEntry("color", 1, 4, Ubyte, true, structSize, (const void*)(offsetof(VertexDataS, Color)));
	layout.AddEntry("uv", 3, 2, Float, false, structSize, (const void*)(offsetof(VertexDataS, UV)));
	layout.AddEntry("textureID", 4, 1, Float, false, structSize, (const void*)(offsetof(VertexDataS, TextureID)));

	return layout;
}
Beispiel #7
0
VertexLayout VertexLayout::GetDefaultMeshVertexLayout()
{
	const int structSize = sizeof(VertexData);

	VertexLayout layout;
	layout.AddEntry("position", 0, 3, Float, false, structSize, (const void*)(offsetof(VertexData, Position)));
	layout.AddEntry("color", 1, 4, Ubyte, true, structSize, (const void*)(offsetof(VertexData, Color)));
	layout.AddEntry("normal", 2, 3, Float, false, structSize, (const void*)(offsetof(VertexData, Normal)));
	layout.AddEntry("uv", 3, 2, Float, false, structSize, (const void*)(offsetof(VertexData, UV)));

	return layout;
}
Beispiel #8
0
    static VertexLayout GetVertexLayout()
    {
        static VertexLayout layout;

        if (layout.size() == 0)
        {
            layout.push_back( VertexAttributeProperties( "inPosition", 3, GL_FLOAT, false, sizeof( Vertex3D_PC ), offsetof( Vertex3D_PC, position ) ) );
            layout.push_back( VertexAttributeProperties( "inColor", 4, GL_UNSIGNED_BYTE, true, sizeof( Vertex3D_PC ), offsetof( Vertex3D_PC, color ) ) );
        }

        return layout;

    }
Beispiel #9
0
    static VertexLayout GetVertexLayout()
    {
        static VertexLayout layout;

        if (layout.size() == 0)
        {
            layout.push_back( VertexAttributeProperties( "inPosition", 3, GL_FLOAT, false, sizeof( Vertex3D_PUN ), offsetof( Vertex3D_PUN, position ) ) );
            layout.push_back( VertexAttributeProperties( "inUV", 2, GL_FLOAT, false, sizeof( Vertex3D_PUN ), offsetof( Vertex3D_PUN, uv ) ) );
            layout.push_back( VertexAttributeProperties( "inNormal", 3, GL_FLOAT, true, sizeof( Vertex3D_PUN ), offsetof( Vertex3D_PUN, normal ) ) );
        }


        return layout;

    }
Beispiel #10
0
		bool Impl_SkyDome::CreateSkyDome()
		{
			std::vector<math::Vector3>	vb;
			std::vector<uint32>			ib;
			MeshUtil::CreateUnitIcoSphere(5, vb, ib, true);

			if(vb.size() == 0)
			{
				return false;
			}

			VertexLayout layout;
			layout.AddAttribute(G_FORMAT_R32G32B32_FLOAT);

			m_pRD = m_pManager->alloc_object<RenderData>();

			m_pRD->geometry = m_pManager->GetRenderManager()->CreateGeometryData();

			m_pRD->geometry->BeginGeometry(PT_TRIANGLE_LIST);
			{
				if(false == m_pRD->geometry->AllocVertexBuffer(sizeof(math::Vector3) * vb.size(), vb.data(), false, layout))
				{
					return false;
				}
				if(false == m_pRD->geometry->AllocIndexBuffer(sizeof(uint32) * ib.size(), ib.data(), false, G_FORMAT_R32_UINT))
				{
					return false;
				}
			}
			m_pRD->geometry->EndGeometry();

			m_pRD->base_vertex = 0;
			m_pRD->vertex_count = vb.size();
			
			m_pRD->start_index = 0;
			m_pRD->index_count = ib.size();
			m_pRD->world_matrix.MakeIdentity();

			m_pRD->material = m_pManager->GetRenderManager()->CreateMaterialFromFile("./assets/atmosphere/material/skydome.material");

			m_pWorldPos = m_pRD->material->GetParameterByName("world_pos");
			return true;
		}
Beispiel #11
0
void Vao::initialize(RenderState& rs, ShaderProgram& _program, const VertexOffsets& _vertexOffsets,
                     VertexLayout& _layout, GLuint _vertexBuffer, GLuint _indexBuffer) {

    m_glVAOs.resize(_vertexOffsets.size());

    GL::genVertexArrays(m_glVAOs.size(), m_glVAOs.data());

    fastmap<std::string, GLuint> locations;

    // FIXME (use a bindAttrib instead of getLocation) to make those locations shader independent
    for (auto& attrib : _layout.getAttribs()) {
        GLint location = _program.getAttribLocation(attrib.name);
        locations[attrib.name] = location;
    }

    rs.vertexBuffer(_vertexBuffer);

    int vertexOffset = 0;
    for (size_t i = 0; i < _vertexOffsets.size(); ++i) {
        auto vertexIndexOffset = _vertexOffsets[i];
        int nVerts = vertexIndexOffset.second;
        GL::bindVertexArray(m_glVAOs[i]);

        // ELEMENT_ARRAY_BUFFER must be bound after bindVertexArray to be used by VAO
        if (_indexBuffer != 0) {
            rs.indexBufferUnset(_indexBuffer);
            rs.indexBuffer(_indexBuffer);
        }

        // Enable vertex layout on the specified locations
        _layout.enable(locations, vertexOffset * _layout.getStride());

        vertexOffset += nVerts;
    }

    GL::bindVertexArray(0);

    rs.vertexBuffer(0);
    rs.indexBuffer(0);
}
Beispiel #12
0
    static VertexLayout GetVertexLayout()
    {
        static VertexLayout layout;

        if (layout.size() == 0)
        {
            layout.push_back( VertexAttributeProperties( "inPosition", 3, GL_FLOAT, false, sizeof( Vertex3D_PUCNTB_Bones ), offsetof( Vertex3D_PUCNTB_Bones, position ) ) );
            layout.push_back( VertexAttributeProperties( "inUV", 2, GL_FLOAT, false, sizeof( Vertex3D_PUCNTB_Bones ), offsetof( Vertex3D_PUCNTB_Bones, uv ) ) );
            layout.push_back( VertexAttributeProperties( "inColor", 4, GL_UNSIGNED_BYTE, true, sizeof( Vertex3D_PUCNTB_Bones ), offsetof( Vertex3D_PUCNTB_Bones, color ) ) );
            layout.push_back( VertexAttributeProperties( "inNormal", 3, GL_FLOAT, true, sizeof( Vertex3D_PUCNTB_Bones ), offsetof( Vertex3D_PUCNTB_Bones, normal ) ) );
            layout.push_back( VertexAttributeProperties( "inTangent", 3, GL_FLOAT, true, sizeof( Vertex3D_PUCNTB_Bones ), offsetof( Vertex3D_PUCNTB_Bones, tangent ) ) );
            layout.push_back( VertexAttributeProperties( "inBitangent", 3, GL_FLOAT, true, sizeof( Vertex3D_PUCNTB_Bones ), offsetof( Vertex3D_PUCNTB_Bones, bitangent ) ) );
        }


        return layout;

    }
Beispiel #13
0
bool D3DVertexBuffer::create(const VertexLayout& layout, int length, int usage)
{
   mStride = layout.getStride();

   D3D11_BUFFER_DESC desc = {0};
   desc.ByteWidth = mStride * length;
   desc.Usage = D3D11_USAGE_DYNAMIC;
   desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
   desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
   desc.MiscFlags = 0;
   desc.StructureByteStride = 0;

   HRESULT hr = mDevice.getDevice().CreateBuffer(&desc, NULL, &mpBuffer);
   if ( FAILED(hr) )
      return false;

   return true;
}
Beispiel #14
0
void Vao::init(GLuint _vertexBuffer, GLuint _indexBuffer,
    VertexLayout& _layout,
    const std::unordered_map<std::string, GLuint>&
    _locations)
{
    generate();

    // Bind the vertex array for initialization
    bind();

    // Bind the vertex and index buffer
    if (_vertexBuffer) {
        GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer));
    }

    if (_indexBuffer) {
        GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer));
    }

    _layout.enable(_locations);

    // Make sure VAO is not modified outside
    unbind();
}
Beispiel #15
0
	bool Impl_SkyBox::OnAttach()
	{
		m_pRD = m_pManager->alloc_object<RenderData>();

		
		VertexLayout layout;
		layout.AddAttribute(G_FORMAT_R32G32B32_FLOAT);
		
		float size = 1.0f;
		int nVerts = 36;

		math::Vector3 verts[] = 
		{
			math::Vector3(-size, size, -size),
			math::Vector3(size, -size, -size),
			math::Vector3(size, size, -size),

			math::Vector3(-size, size, -size),
			math::Vector3(-size, -size, -size),
			math::Vector3(size, -size, -size),

			math::Vector3(-size, size, size),
			math::Vector3(size, size, size),
			math::Vector3(size, -size, size),

			math::Vector3(-size, size, size),
			math::Vector3(size, -size, size),
			math::Vector3(-size, -size, size),


			math::Vector3(-size, size, size),
			math::Vector3(size, size, -size),
			math::Vector3(size, size, size),

			math::Vector3(-size, size, size),
			math::Vector3(-size, size, -size),
			math::Vector3(size, size, -size),


			math::Vector3(-size, -size, size),
			math::Vector3(size, -size, size),
			math::Vector3(size, -size, -size),

			math::Vector3(-size, -size, size),
			math::Vector3(size, -size, -size),
			math::Vector3(-size, -size, -size),


			math::Vector3(-size, size, size),
			math::Vector3(-size, -size, -size),
			math::Vector3(-size, size, -size),

			math::Vector3(-size, size, size),
			math::Vector3(-size, -size, size),
			math::Vector3(-size, -size, -size),


			math::Vector3(size, size, size),
			math::Vector3(size, size, -size),
			math::Vector3(size, -size, -size),

			math::Vector3(size, size, size),
			math::Vector3(size, -size, -size),
			math::Vector3(size, -size, size),

		};

		m_pRD->geometry = m_pManager->GetRenderManager()->CreateGeometryData();

		m_pRD->geometry->BeginGeometry(PT_TRIANGLE_LIST);
		{
			m_pRD->geometry->AllocVertexBuffer(sizeof(math::Vector3) * 36, verts, false, layout);
		}
		m_pRD->geometry->EndGeometry();

		m_pRD->base_vertex = 0;
		m_pRD->index_count = 0;
		m_pRD->start_index = 0;
		m_pRD->vertex_count = 36;
		m_pRD->world_matrix.MakeIdentity();

		m_pRD->material = m_pManager->GetRenderManager()->CreateMaterialFromFile("./assets/standard/material/skybox.material");

		m_hFrustumCull = m_pManager->AddEventHandler(EV_FRUSTUM_CULL, boost::bind(&Impl_SkyBox::on_event_frustum_cull, this, _1));


		m_pTex = m_pManager->GetRenderManager()->CreateTextureFromFile("./assets/standard/texture/001.dds");

		MaterialParameterPtr pParam = m_pRD->material->GetParameterByName("sky_map");
		
		pParam->SetParameterTexture(m_pTex);
		
		m_pWorldPos = m_pRD->material->GetParameterByName("world_pos");
		return true;
	}
Beispiel #16
0
void SkyBox::load( const he::String& asset )
{
    HE_ASSERT(m_Drawable == nullptr, "Skybox is loaded twice!");
    m_Drawable = HENew(Drawable)();
    m_Drawable->setLocalScale(vec3(1000000000)); // bounds must be huge
    //////////////////////////////////////////////////////////////////////////
    /// Load Model
    //////////////////////////////////////////////////////////////////////////
    ModelMesh* const cube(
        ResourceFactory<gfx::ModelMesh>::getInstance()->get(ResourceFactory<gfx::ModelMesh>::getInstance()->create()));
    cube->setName(he::String("skybox-") + asset);
    he::PrimitiveList<vec3> vertices(8);
    vertices.add(vec3(-1,  1, -1));
    vertices.add(vec3( 1,  1, -1));
    vertices.add(vec3(-1, -1, -1));
    vertices.add(vec3( 1, -1, -1));

    vertices.add(vec3(-1,  1,  1));
    vertices.add(vec3( 1,  1,  1));
    vertices.add(vec3(-1, -1,  1));
    vertices.add(vec3( 1, -1,  1));

    he::PrimitiveList<uint16> indices(36);
    indices.add(0); indices.add(1); indices.add(2); //front
    indices.add(1); indices.add(3); indices.add(2);

    indices.add(5); indices.add(4); indices.add(7); //back
    indices.add(4); indices.add(6); indices.add(7);

    indices.add(4); indices.add(0); indices.add(6); //left
    indices.add(0); indices.add(2); indices.add(6);

    indices.add(1); indices.add(5); indices.add(3); //right
    indices.add(5); indices.add(7); indices.add(3);

    indices.add(4); indices.add(5); indices.add(0); //top
    indices.add(5); indices.add(1); indices.add(0);

    indices.add(3); indices.add(7); indices.add(2); //bottom
    indices.add(7); indices.add(6); indices.add(2);

    VertexLayout layout;
    layout.addElement(VertexElement(eShaderAttribute_Position, eShaderAttributeType_Float, eShaderAttributeTypeComponents_3, 0));
    cube->init(layout, MeshDrawMode_Triangles);
    cube->setVertices(&vertices[0], static_cast<uint32>(vertices.size()), MeshUsage_Static, false);
    cube->setIndices(&indices[0], static_cast<uint32>(indices.size()), IndexStride_UShort, MeshUsage_Static);
    cube->setLoaded(eLoadResult_Success);
    m_Drawable->setModelMesh(cube);
    cube->release();

    Material* const material(CONTENT->loadMaterial("engine/sky.material"));
    m_Drawable->setMaterial(material);
    material->release();

    const int8 cubeMap(m_Drawable->getMaterial()->findParameter(HEFS::strcubeMap));
    if (cubeMap >= 0)
    {
        const TextureCube* cube(CONTENT->asyncLoadTextureCube(asset));
        m_Drawable->getMaterial()->getParameter(cubeMap).setTextureCube(cube);
        cube->release();
    }
}
Beispiel #17
0
VertexLayout::VertexLayout(const VertexLayout& layout)
{
	for (auto item : layout.GetAttributes())
		_attributes.emplace_back(item);
}
Beispiel #18
0
	GeometryDataPtr EngineApp::CreateCube(float size)
	{
		struct Vertex
		{
			math::Vector3 pos;
			math::Vector3 normal;
			math::Vector2 uv;
			
		};

		size = size / 2.0f;
		Vertex pVerts[] = 
		{
			// front
			{math::Vector3(-size, size, -size), math::Vector3(0, 0, -1), math::Vector2(0, 0), },
			{math::Vector3(size, size, -size), math::Vector3(0, 0, -1), math::Vector2(2, 0),},
			{math::Vector3(size, -size, -size), math::Vector3(0, 0, -1), math::Vector2(2, 2),},
			{math::Vector3(-size, -size, -size), math::Vector3(0, 0, -1), math::Vector2(0, 2),},

			// back
			{math::Vector3(-size, size, size), math::Vector3(0, 0, 1), math::Vector2(0, 0),},
			{math::Vector3(size, size, size), math::Vector3(0, 0, 1), math::Vector2(1, 0),},
			{math::Vector3(size, -size, size), math::Vector3(0, 0, 1), math::Vector2(1, 1),},
			{math::Vector3(-size, -size, size), math::Vector3(0, 0, 1), math::Vector2(0, 1),},

			// top
			{math::Vector3(-size, size, size), math::Vector3(0, 1, 0), math::Vector2(0, 0),},
			{math::Vector3(size, size, size), math::Vector3(0, 1, 0), math::Vector2(1, 0),},
			{math::Vector3(size, size, -size), math::Vector3(0, 1, 0), math::Vector2(1, 1),},
			{math::Vector3(-size, size, -size), math::Vector3(0, 1, 0), math::Vector2(0, 1),},
			// bottom
			{math::Vector3(-size, -size, size), math::Vector3(0, -1, 0), math::Vector2(0, 0),},
			{math::Vector3(size, -size, size), math::Vector3(0, -1, 0), math::Vector2(1, 0),},
			{math::Vector3(size, -size, -size), math::Vector3(0, -1, 0), math::Vector2(1, 1),},
			{math::Vector3(-size, -size, -size), math::Vector3(0, -1, 0), math::Vector2(0, 1),},

			// left
			{math::Vector3(-size, size, size), math::Vector3(-1, 0, 0), math::Vector2(0, 0),},
			{math::Vector3(-size, size, -size), math::Vector3(-1, 0, 0), math::Vector2(1, 0),},
			{math::Vector3(-size, -size, -size), math::Vector3(-1, 0, 0), math::Vector2(1, 1),},
			{math::Vector3(-size, -size, size), math::Vector3(-1, 0, 0), math::Vector2(0, 1),},
			// right
			{math::Vector3(size, size, size), math::Vector3(1, 0, 0), math::Vector2(0, 0),},
			{math::Vector3(size, size, -size), math::Vector3(1, 0, 0), math::Vector2(1, 0),},
			{math::Vector3(size, -size, -size), math::Vector3(1, 0, 0), math::Vector2(1, 1),},
			{math::Vector3(size, -size, size), math::Vector3(1, 0, 0), math::Vector2(0, 1),},
		};

		uint32 pIndice[] = 
		{
			// front
			0, 1, 2,
			0, 2, 3,

			// back
			4, 6, 5, 
			4, 7, 6,


			//top
			8, 9, 10,
			8, 10, 11,

			// bottom
			12, 14, 13,
			12, 15, 14,

			// left
			16, 17, 18,
			16, 18, 19,

			// right
			20, 22, 21,
			20, 23, 22,

		};

		GeometryDataPtr pGeom = m_pGraphics->CreateGeometryData();

		VertexLayout layout;
		layout.AddAttribute(G_FORMAT_R32G32B32_FLOAT);
		layout.AddAttribute(G_FORMAT_R32G32B32_FLOAT);
		layout.AddAttribute(G_FORMAT_R32G32_FLOAT);

		pGeom->BeginGeometry(PT_TRIANGLE_LIST);
		{
			pGeom->AllocIndexBuffer(sizeof(uint32) * 36, pIndice, false, G_FORMAT_R32_UINT);
			pGeom->AllocVertexBuffer(sizeof(Vertex) * 24, pVerts, false, layout);
		}
		pGeom->EndGeometry();

		return pGeom;
	}