void VertexDataHelper::BuildPathVertexData(APath aPath, QOpenGLBuffer* linesVbo, QOpenGLVertexArrayObject* linesVao, QVector3D vecCol)
{
	if (aPath.points.size() == 0) { return; }
	bool isInit = false;
	if (!linesVao->isCreated())
	{
		linesVao->create();
		linesVao->bind();
		isInit = true;
	}
	size_t path_length = aPath.points.size();
	QVector<VertexData> data;
	for (uint a = 0; a < path_length - 1; a++)
	{
		//if (a < _points.size() - 1) { lines.push_back(ALine(_points[a], _points[a + 1])); }
		//else { lines.push_back(ALine(_points[a], _points[0])); }
		data.append(VertexData(QVector3D(aPath.points[a].x, aPath.points[a].y, 0), QVector2D(), vecCol));
		data.append(VertexData(QVector3D(aPath.points[a + 1].x, aPath.points[a + 1].y, 0), QVector2D(), vecCol));
	}
	if (aPath.isClosed)
	{
		data.append(VertexData(QVector3D(aPath.points[path_length - 1].x, aPath.points[path_length - 1].y, 0), QVector2D(), vecCol));
		data.append(VertexData(QVector3D(aPath.points[0].x, aPath.points[0].y, 0), QVector2D(), vecCol));
	}
	BuildVboWithColor(data, linesVbo);
	if (isInit) { linesVao->release(); }
}
void VertexDataHelper::BuildQuadsVertexData(std::vector<ABox> boxes, QOpenGLBuffer* vbo, QOpenGLVertexArrayObject* vao)
{
	if (vao->isCreated()) { vao->destroy(); }

	vao->create();
	vao->bind();

	QVector<VertexData> data;
	// this diagram is wrong
	/*
	(0, 0)           (witdh, 0)
	ptB ------------ ptD
	|				  |
	|				  |
	|				  |
	|				  |
	|				  |
	ptA ------------ ptC
	(0, height)      (width, height)
	*/
	for (uint a = 0; a < boxes.size(); a++)
	{
		data.append(VertexData(QVector3D(boxes[a]._ptA.x, boxes[a]._ptA.y, 0), QVector2D(0, 1)));
		data.append(VertexData(QVector3D(boxes[a]._ptB.x, boxes[a]._ptB.y, 0), QVector2D(0, 0)));
		data.append(VertexData(QVector3D(boxes[a]._ptD.x, boxes[a]._ptD.y, 0), QVector2D(1, 0))); // flipped
		data.append(VertexData(QVector3D(boxes[a]._ptC.x, boxes[a]._ptC.y, 0), QVector2D(1, 1))); // flipped		
	}

	BuildVboWithTexture(data, vbo);

	vao->release();
}
Exemplo n.º 3
0
Scene::Scene()
{
    initializeOpenGLFunctions();

    this->setSkyBox(NULL);
    m_root.setName ("root");
    this->setRenderType (DEFERRED_SHADING);
    m_mainRenderTarget = new RenderTarget();
    m_mainRenderTarget->setType (RenderTarget::TargetType::ON_SCREEN);
    bloom_fbo1 = new RenderBuffer(1024,768);
    bloom_fbo2 = new RenderBuffer(1024,768);
    bloom_fbo3 = new RenderBuffer(1024,768);
    TMesh * mesh = new TMesh();
    mesh->pushVertex (VertexData(QVector3D(-1,-1,0),QVector2D(0,0)));
    mesh->pushVertex (VertexData(QVector3D(1,-1,0),QVector2D(1,0)));
    mesh->pushVertex (VertexData(QVector3D(1,1,0),QVector2D(1,1)));
    mesh->pushVertex (VertexData(QVector3D(-1,1,0),QVector2D(0,1)));
    mesh->pushIndex (0);
    mesh->pushIndex (1);
    mesh->pushIndex (2);
    mesh->pushIndex (0);
    mesh->pushIndex (2);
    mesh->pushIndex (3);
    mesh->setMaterial (MaterialPool::getInstance ()->createOrGetMaterial ("default"));
    mesh->finishWithoutNormal ();
    m_quad = new Entity();
    m_quad->addMesh (mesh);

    m_guiCamera = new Camera();
    m_guiCamera->setOrtho (0,1024,0,768,0.01,1000);
    m_guiCamera->setPos (QVector3D(0,0,0));

    m_renderType = DEFERRED_SHADING;
}
Exemplo n.º 4
0
    void WireBoundingBox::_initWireBoundingBox()
    {
        mRenderOp.vertexData = OGRE_NEW VertexData();

        mRenderOp.indexData = 0;
        mRenderOp.vertexData->vertexCount = 24; 
        mRenderOp.vertexData->vertexStart = 0; 
        mRenderOp.operationType = RenderOperation::OT_LINE_LIST; 
        mRenderOp.useIndexes = false; 
        mRenderOp.useGlobalInstancingVertexBufferIsAvailable = false;

        VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
        VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding;

        decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);


        HardwareVertexBufferSharedPtr vbuf = 
            HardwareBufferManager::getSingleton().createVertexBuffer(
                decl->getVertexSize(POSITION_BINDING),
                mRenderOp.vertexData->vertexCount,
                HardwareBuffer::HBU_STATIC_WRITE_ONLY);

        // Bind buffer
        bind->setBinding(POSITION_BINDING, vbuf);

        // set basic white material
        this->setMaterial("BaseWhiteNoLighting");


        
    }
Exemplo n.º 5
0
	//-------------------------------------------------------------------------------//
	void OverlayPanelElement::initialise(const String& texName, float width, float height, float left, float top)
	{
		mTexture = TextureMgr::getSingletonPtr()->getByName(texName);
		setSize(width, height);
		setPosition(left, top);
		mIsVisible = true;

		if(!mIsInitialised)
		{
			mRenderData.vertexData = TITAN_NEW VertexData();
			VertexDeclaration* decl = mRenderData.vertexData->vertexDecl;
			decl->addElement(0,0, VET_FLOAT3, VES_POSITION);

			mRenderData.vertexData->vertexStart = 0;
			mRenderData.vertexData->vertexCount = 4;

			VertexBufferPtr vbuf = HardwareBufferMgr::getSingletonPtr()->createVertexBuffer(decl->getVertexSize(0), mRenderData.vertexData->vertexCount,
				HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
			mRenderData.vertexData->vertexBufferBinding->setBinding(0, vbuf);

			mRenderData.useIndex = false;
			mRenderData.operationType = OT_TRIANGLE_STRIP;

			mIsInitialised = true;
		}

		notifyGeometryOld();
	}
	//-----------------------------------------------------------------------
	BillboardChain::BillboardChain(const String& name, size_t maxElements,
		size_t numberOfChains, bool useTextureCoords, bool useColours, bool dynamic)
		:MovableObject(name),
		mMaxElementsPerChain(maxElements),
		mChainCount(numberOfChains),
		mUseTexCoords(useTextureCoords),
		mUseVertexColour(useColours),
		mDynamic(dynamic),
		mVertexDeclDirty(true),
		mBuffersNeedRecreating(true),
		mBoundsDirty(true),
		mIndexContentDirty(true),
		mRadius(0.0f),
		mTexCoordDir(TCD_U),
		mFaceCamera(true),
		mNormalBase(Vector3::UNIT_X)
	{
		mVertexData = OGRE_NEW VertexData();
		mIndexData = OGRE_NEW IndexData();

		mOtherTexCoordRange[0] = 0.0f;
		mOtherTexCoordRange[1] = 1.0f;

		setupChainContainers();

		mVertexData->vertexStart = 0;
		// index data set up later
		// set basic white material
		//this->setMaterialName("BaseWhiteNoLighting");

	}
Exemplo n.º 7
0
    //---------------------------------------------------------------------
    void PanelOverlayElement::initialise(void)
    {
        bool init = !mInitialised;

        OverlayContainer::initialise();
        if (init)
        {
            // Setup render op in advance
            mRenderOp.vertexData = OGRE_NEW VertexData();
            // Vertex declaration: 1 position, add texcoords later depending on #layers
            // Create as separate buffers so we can lock & discard separately
            VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
            decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);

            // Basic vertex data
            mRenderOp.vertexData->vertexStart = 0;
            mRenderOp.vertexData->vertexCount = 4;
            // No indexes & issue as a strip
            mRenderOp.useIndexes = false;
            mRenderOp.operationType = RenderOperation::OT_TRIANGLE_STRIP;
            mRenderOp.useGlobalInstancingVertexBufferIsAvailable = false;

            mInitialised = true;

            _restoreManualHardwareResources();
        }
    }
Exemplo n.º 8
0
    void TextAreaOverlayElement::initialise(void)
    {
        if (!mInitialised)
        {
            // Set up the render op
            // Combine positions and texture coords since they tend to change together
            // since character sizes are different
            mRenderOp.vertexData = OGRE_NEW VertexData();
            VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
            size_t offset = 0;
            // Positions
            decl->addElement(POS_TEX_BINDING, offset, VET_FLOAT3, VES_POSITION);
            offset += VertexElement::getTypeSize(VET_FLOAT3);
            // Texcoords
            decl->addElement(POS_TEX_BINDING, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
            // Colours - store these in a separate buffer because they change less often
            decl->addElement(COLOUR_BINDING, 0, VET_COLOUR, VES_DIFFUSE);

            mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
            mRenderOp.useIndexes = false;
            mRenderOp.vertexData->vertexStart = 0;
            mRenderOp.useGlobalInstancingVertexBufferIsAvailable = false;
            // Vertex buffer will be created in checkMemoryAllocation
            mRenderOp.srcRenderable = this;
            checkMemoryAllocation( DEFAULT_INITIAL_CHARS );

            mInitialised = true;
        }

    }
Exemplo n.º 9
0
 /** 
  * \brief Creates a vertex containing the vertex data and returns the id
  * of the new vertex id. Vertex ids are assigned in increasing order with
  * the first vertex having id 0.
  * Vertices are placed in atom vid % num_atoms
  */
 vertex_id_type add_vertex(const VertexData& vdata = VertexData()) {
   vertex_id_type v = numv.inc_ret_last();
   uint16_t owner = v % atoms.size();
   atoms[owner]->add_vertex(v, owner, vdata);
   atoms[owner]->set_owner(v, owner);
   return v;
 }
Exemplo n.º 10
0
    //---------------------------------------------------------------------
    void PanelOverlayElement::initialise(void)
    {
		bool init = !mInitialised;

		OverlayContainer::initialise();
		if (init)
		{
			// Setup render op in advance
			mRenderOp.vertexData = OGRE_NEW VertexData();
			// Vertex declaration: 1 position, add texcoords later depending on #layers
			// Create as separate buffers so we can lock & discard separately
			VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
			decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);

			// Basic vertex data
			mRenderOp.vertexData->vertexStart = 0;
			mRenderOp.vertexData->vertexCount = 4;

			// Vertex buffer #1
			HardwareVertexBufferSharedPtr vbuf =
				HardwareBufferManager::getSingleton().createVertexBuffer(
				decl->getVertexSize(POSITION_BINDING), mRenderOp.vertexData->vertexCount,
				HardwareBuffer::HBU_STATIC_WRITE_ONLY// mostly static except during resizing
				);
			// Bind buffer
			mRenderOp.vertexData->vertexBufferBinding->setBinding(POSITION_BINDING, vbuf);

			// No indexes & issue as a strip
			mRenderOp.useIndexes = false;
			mRenderOp.operationType = RenderOperation::OT_TRIANGLE_STRIP;

			mInitialised = true;
		}
    }
    //---------------------------------------------------------------------
    void BorderPanelOverlayElement::initialise(void)
    {
        bool init = !mInitialised;

        // init mRenderOp2 before calling superclass, as virtual _restoreManualHardwareResources would be called within
        if (init)
        {
            // Setup render op in advance
            mRenderOp2.vertexData = OGRE_NEW VertexData();
            mRenderOp2.vertexData->vertexCount = 4 * 8; // 8 cells, can't necessarily share vertices cos
                                                        // texcoords may differ
            mRenderOp2.vertexData->vertexStart = 0;

            // Vertex declaration
            VertexDeclaration* decl = mRenderOp2.vertexData->vertexDeclaration;
            // Position and texture coords each have their own buffers to allow
            // each to be edited separately with the discard flag
            decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);
            decl->addElement(TEXCOORD_BINDING, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);

            // Index data
            mRenderOp2.operationType = RenderOperation::OT_TRIANGLE_LIST;
            mRenderOp2.useIndexes = true;
            mRenderOp2.indexData = OGRE_NEW IndexData();
            mRenderOp2.indexData->indexCount = 8 * 6;
            mRenderOp2.indexData->indexStart = 0;
            mRenderOp2.useGlobalInstancingVertexBufferIsAvailable = false;

            // Create sub-object for rendering border
            mBorderRenderable = OGRE_NEW BorderRenderable(this);
        }

        // superclass will handle the interior panel area and call _restoreManualHardwareResources
        PanelOverlayElement::initialise();
    }
Exemplo n.º 12
0
/// add vertex, associate given Octnode with the vertex, and return index
unsigned int GLData::addVertex(GLVertex v, Octnode* n) {
    // add vertex with empty polygon-list.
    unsigned int idx = vertexArray[workIndex].size();
    vertexArray[workIndex].append(v);
    vertexDataArray.append( VertexData() );
    vertexDataArray[idx].node = n;
    assert( vertexArray[workIndex].size() == vertexDataArray.size() );
    return idx; // return index of newly appended vertex
}
void VertexDataHelper::BuildTrianglesVertexData(std::vector<ATriangle> triangles, QOpenGLBuffer* vbo, QOpenGLVertexArrayObject* vao, QVector3D vecCol)
{
	if (vao->isCreated()) { vao->destroy(); }

	vao->create();
	vao->bind();

	QVector<VertexData> data;
	for (uint a = 0; a < triangles.size(); a++)
	{
		data.append(VertexData(QVector3D(triangles[a]._ptA.x, triangles[a]._ptA.y, 0), QVector2D(), vecCol));
		data.append(VertexData(QVector3D(triangles[a]._ptB.x, triangles[a]._ptB.y, 0), QVector2D(), vecCol));
		data.append(VertexData(QVector3D(triangles[a]._ptC.x, triangles[a]._ptC.y, 0), QVector2D(), vecCol));
	}

	BuildVboWithColor(data, vbo);

	vao->release();
}
Exemplo n.º 14
0
void GUIFrame::setRenderRect()
{
    m_mesh->clear();
	unsigned short indices[] = {
         0,1,2,  0,2,3,
    };
    auto w = m_contentSize.x;
    auto h = m_contentSize.y;
    VertexData vertices[] = {
        // front
		VertexData(vec3(0, 0,  -1.0f), m_color),  // v0
        VertexData(vec3( w,  0,  -1.0f), m_color), // v1
        VertexData(vec3( w,  h,  -1.0f), m_color),  // v2
        VertexData(vec3( 0, h,  -1.0f), m_color)// v3
    };
    m_mesh->addVertices(vertices,sizeof(vertices)/sizeof(VertexData));
    m_mesh->addIndices(indices,sizeof(indices)/sizeof(unsigned short));
    m_mesh->finish();
}
	//---------------------------------------------------------------------
	void PrefabFactory::createPlane(Mesh* mesh)
	{
		SubMesh* sub = mesh->createSubMesh();
		float vertices[32] = {
			-100, -100, 0,	// pos
			0,0,1,			// normal
			0,1,			// texcoord
			100, -100, 0,
			0,0,1,
			1,1,
			100,  100, 0,
			0,0,1,
			1,0,
			-100,  100, 0 ,
			0,0,1,
			0,0 
		};
		mesh->sharedVertexData = OGRE_NEW VertexData();
		mesh->sharedVertexData->vertexCount = 4;
		VertexDeclaration* decl = mesh->sharedVertexData->vertexDeclaration;
		VertexBufferBinding* bind = mesh->sharedVertexData->vertexBufferBinding;

		size_t offset = 0;
		decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
		offset += VertexElement::getTypeSize(VET_FLOAT3);
		decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
		offset += VertexElement::getTypeSize(VET_FLOAT3);
		decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
		offset += VertexElement::getTypeSize(VET_FLOAT2);

		HardwareVertexBufferSharedPtr vbuf = 
			HardwareBufferManager::getSingleton().createVertexBuffer(
			offset, 4, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
		bind->setBinding(0, vbuf);

		vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);

		sub->useSharedVertices = true;
		HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
			createIndexBuffer(
			HardwareIndexBuffer::IT_16BIT, 
			6, 
			HardwareBuffer::HBU_STATIC_WRITE_ONLY);

		unsigned short faces[6] = {0,1,2,
			0,2,3 };
		sub->indexData->indexBuffer = ibuf;
		sub->indexData->indexCount = 6;
		sub->indexData->indexStart =0;
		ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);

		mesh->_setBounds(AxisAlignedBox(-100,-100,0,100,100,0), true);
		mesh->_setBoundingSphereRadius(Math::Sqrt(100*100+100*100));
	}
Exemplo n.º 16
0
	//-----------------------------------------------------------------------------
	//-----------------------------------------------------------------------------
	//-----------------------------------------------------------------------------
	ManualObject::ManualObjectSection::ManualObjectSection(ManualObject* parent,
		const String& materialName, RenderOperation::OperationType opType, const String & groupName)
		: mParent(parent), mMaterialName(materialName), mGroupName(groupName), m32BitIndices(false)
	{
		mRenderOperation.operationType = opType;
		// default to no indexes unless we're told
		mRenderOperation.useIndexes = false;
		mRenderOperation.vertexData = OGRE_NEW VertexData();
		mRenderOperation.vertexData->vertexCount = 0;

	}
void VertexDataHelper::BuildLinesVertexData(std::vector<ALine> lines, QOpenGLBuffer* linesVbo, QOpenGLVertexArrayObject* linesVao, QVector3D vecCol)
{
	bool isInit = false;
	if (!linesVao->isCreated())
	{
		linesVao->create();
		linesVao->bind();
		isInit = true;
	}

	QVector<VertexData> data;
	for (uint a = 0; a < lines.size(); a++)
	{
		data.append(VertexData(QVector3D(lines[a].XA, lines[a].YA, 0), QVector2D(), vecCol));
		data.append(VertexData(QVector3D(lines[a].XB, lines[a].YB, 0), QVector2D(), vecCol));
	}

	BuildVboWithColor(data, linesVbo);

	if (isInit) { linesVao->release(); }
}
size_t VertexDataHelper::BuildPathsVertexData(std::vector<APath> paths, QOpenGLBuffer* linesVbo, QOpenGLVertexArrayObject* linesVao, std::vector<QVector3D> colors)
{
	if (paths.size() == 0) { return 0; }

	bool isInit = false;
	if (!linesVao->isCreated())
	{
		linesVao->create();
		linesVao->bind();
		isInit = true;
	}

	QVector<VertexData> data;
	for (size_t a = 0; a < paths.size(); a++)
	{
		// your code here
		APath aPath = paths[a];
		QVector3D vecCol = colors[a];

		size_t path_length = aPath.points.size();

		for (uint a = 0; a < path_length - 1; a++)
		{
			//if (a < _points.size() - 1) { lines.push_back(ALine(_points[a], _points[a + 1])); }
			//else { lines.push_back(ALine(_points[a], _points[0])); }
			data.append(VertexData(QVector3D(aPath.points[a].x, aPath.points[a].y, 0), QVector2D(), vecCol));
			data.append(VertexData(QVector3D(aPath.points[a + 1].x, aPath.points[a + 1].y, 0), QVector2D(), vecCol));
		}
		if (aPath.isClosed)
		{
			data.append(VertexData(QVector3D(aPath.points[path_length - 1].x, aPath.points[path_length - 1].y, 0), QVector2D(), vecCol));
			data.append(VertexData(QVector3D(aPath.points[0].x, aPath.points[0].y, 0), QVector2D(), vecCol));
		}
	}

	BuildVboWithColor(data, linesVbo);
	if (isInit) { linesVao->release(); }

	return data.size();
}
void VertexDataHelper::BuildLinesVertexData(std::vector<AVector> points, QOpenGLBuffer* linesVbo, QOpenGLVertexArrayObject* linesVao, QVector3D vecCol)
{
	if (points.size() == 0) { return; }

	bool isInit = false;
	if (!linesVao->isCreated())
	{
		linesVao->create();
		linesVao->bind();
		isInit = true;
	}

	QVector<VertexData> data;
	for (uint a = 0; a < points.size() - 1; a++)
	{
		data.append(VertexData(QVector3D(points[a].x, points[a].y, 0), QVector2D(), vecCol));
		data.append(VertexData(QVector3D(points[a + 1].x, points[a + 1].y, 0), QVector2D(), vecCol));
	}

	BuildVboWithColor(data, linesVbo);

	if (isInit) { linesVao->release(); }
}
Exemplo n.º 20
0
void GLWidget::PrepareLinesVBO(std::vector<ALine> lines, QOpenGLBuffer* linesVbo, QOpenGLVertexArrayObject* linesVao, QVector3D vecCol)
{    
    bool isInit = false;
    if(!linesVao->isCreated())
    {
        linesVao->create();
        linesVao->bind();
        isInit = true;
    }

    QVector<VertexData> data;
    for(uint a = 0; a < lines.size(); a++)
    {
        data.append(VertexData(QVector3D(lines[a].XA, lines[a].YA,  0), QVector2D(), vecCol));
        data.append(VertexData(QVector3D(lines[a].XB, lines[a].YB,  0), QVector2D(), vecCol));
    }

    linesVbo->create();
    linesVbo->bind();
    linesVbo->allocate(data.data(), data.size() * sizeof(VertexData));

    quintptr offset = 0;

    _shaderProgram->enableAttributeArray(_vertexLocation);
    _shaderProgram->setAttributeBuffer(_vertexLocation, GL_FLOAT, 0, 3, sizeof(VertexData));

    offset += sizeof(QVector3D);
    offset += sizeof(QVector2D);

    _shaderProgram->enableAttributeArray(_colorLocation);
    _shaderProgram->setAttributeBuffer(_colorLocation, GL_FLOAT, offset, 3, sizeof(VertexData));

    if(isInit)
    {
        linesVao->release();
    }
}
Exemplo n.º 21
0
	//-----------------------------------------------------------------------------
	//--------------------------------------------------------------------------
	ManualObject::ManualObjectSectionShadowRenderable::ManualObjectSectionShadowRenderable(
		ManualObject* parent, HardwareIndexBufferSharedPtr* indexBuffer,
		const VertexData* vertexData, bool createSeparateLightCap,
		bool isLightCap)
		: mParent(parent)
	{
		// Initialise render op
		mRenderOp.indexData = OGRE_NEW IndexData();
		mRenderOp.indexData->indexBuffer = *indexBuffer;
		mRenderOp.indexData->indexStart = 0;
		// index start and count are sorted out later

		// Create vertex data which just references position component (and 2 component)
		mRenderOp.vertexData = OGRE_NEW VertexData();
		// Map in position data
		mRenderOp.vertexData->vertexDeclaration->addElement(0,0,VET_FLOAT3, VES_POSITION);
		ushort origPosBind =
			vertexData->vertexDeclaration->findElementBySemantic(VES_POSITION)->getSource();
		mPositionBuffer = vertexData->vertexBufferBinding->getBuffer(origPosBind);
		mRenderOp.vertexData->vertexBufferBinding->setBinding(0, mPositionBuffer);
		// Map in w-coord buffer (if present)
		if(!vertexData->hardwareShadowVolWBuffer.isNull())
		{
			mRenderOp.vertexData->vertexDeclaration->addElement(1,0,VET_FLOAT1, VES_TEXTURE_COORDINATES, 0);
			mWBuffer = vertexData->hardwareShadowVolWBuffer;
			mRenderOp.vertexData->vertexBufferBinding->setBinding(1, mWBuffer);
		}
		// Use same vertex start as input
		mRenderOp.vertexData->vertexStart = vertexData->vertexStart;

		if (isLightCap)
		{
			// Use original vertex count, no extrusion
			mRenderOp.vertexData->vertexCount = vertexData->vertexCount;
		}
		else
		{
			// Vertex count must take into account the doubling of the buffer,
			// because second half of the buffer is the extruded copy
			mRenderOp.vertexData->vertexCount =
				vertexData->vertexCount * 2;
			if (createSeparateLightCap)
			{
				// Create child light cap
				mLightCap = OGRE_NEW ManualObjectSectionShadowRenderable(parent,
					indexBuffer, vertexData, false, true);
			}
		}
	}
Exemplo n.º 22
0
std::shared_ptr<TextField> TextField::create(std::shared_ptr<Skin> skin, std::shared_ptr<WrappableText> default_text, std::shared_ptr<WrappableText> typed_text, glm::vec4 background_color, float padding, float screen_width, float screen_height, float x_pos, float y_pos, float width, float height, const unsigned int layer) {
    auto vertex_data = VertexData();
    vertex_data.addVec(VertexData::DATA_TYPE::GEOMETRY, generateRect(screen_width, screen_height, 0, 0, width, height));
    vertex_data.addVec(VertexData::DATA_TYPE::TEX_COORDS, basisTexCoords());

    default_text->setSize(width - (2.0 * padding), height - (2.0 * padding));
    typed_text->setSize(width - (2.0 * padding), height - (2.0 * padding));
    typed_text->setText("");

    auto field = std::make_shared<TextField>(default_text, typed_text, vertex_data, skin, layer);
    field->setColor(background_color);
    field->setAnchorPoint(glm::vec2(x_pos, y_pos));
    field->setWidth(width);
    field->setHeight(height);
    field->setTextPadding(padding);

    return field;
}
Exemplo n.º 23
0
    //------------------------------------------------------------------------
    void TerrainBatch::createGpuVertexData()
    {
        if ( !mGpuVertexData )
        {
            DefaultTerrainTilesGpuBufferAllocator& gpuBufferAllocator 
                                                = mSurfaceManager->getDefaultTerrainTilesGpuBufferAllocator();
            mOneVertexSize                      = mTileRender->getOneVertexSize();
            Ogre::VertexData* tileVertexData    = mTileRender->getCpuVertexData();

            /////////////////////////////////////////////////////////////////////////////

            mGpuVertexData  = OGRE_NEW VertexData();


            // copy vertex buffers
            // get new buffers
            HardwareVertexBufferSharedPtr destPosBuf;
            gpuBufferAllocator.allocateVertexBuffers(mOneVertexSize, mVertexTotalNum, destPosBuf);

            // set bindings
            mGpuVertexData->vertexBufferBinding->setBinding( TerrainTileRender::POSITION_BUFFER, destPosBuf);

            // Basic vertex info
            mGpuVertexData->vertexStart = 0;
            mGpuVertexData->vertexCount = mVertexTotalNum;

            // Copy elements
            const VertexDeclaration::VertexElementList elems = 
                tileVertexData->vertexDeclaration->getElements();
            VertexDeclaration::VertexElementList::const_iterator ei, eiend;
            eiend = elems.end();
            for (ei = elems.begin(); ei != eiend; ++ei)
            {
                mGpuVertexData->vertexDeclaration->addElement(
                    ei->getSource(),
                    ei->getOffset(),
                    ei->getType(),
                    ei->getSemantic(),
                    ei->getIndex() );
            }
        }
    }
void VertexDataHelper::BuildPointsVertexData(std::vector<AVector> points, QOpenGLBuffer* ptsVbo, QOpenGLVertexArrayObject* ptsVao, QVector3D vecCol)
{
	bool isInit = false;
	if (!ptsVao->isCreated())
	{
		ptsVao->create();
		ptsVao->bind();
		isInit = true;
	}

	QVector<VertexData> data;
	for (uint a = 0; a < points.size(); a++)
	{
		data.append(VertexData(QVector3D(points[a].x, points[a].y, 0), QVector2D(), vecCol));
	}

	BuildVboWithColor(data, ptsVbo);

	if (isInit) { ptsVao->release(); }
}
Exemplo n.º 25
0
	//------------------------------------------------------------------------------//
	void GeoTerrainSection::_createConnectorRend()
	{
		for(int i = 0;i < GeoTerrain::TotalSides; ++i)
		{
			mConnectorRends[i].setCreator(this);
			mConnectorRends[i].setSectionPos(mSectionPos);
			RenderData* rend = mConnectorRends[i].getRenderData();
			rend->vertexData = TITAN_NEW VertexData(mCreator->getVertexDecl(),mVertexBufferBinding);
			rend->vertexData->vertexCount = mCreator->getHorzVertexData()->getNumVertices();

			rend->useIndex = true;
			rend->indexData = TITAN_NEW IndexData();
			rend->indexData->indexStart = 0;

			Vector4 uvScaleOffset = Vector4((float)1.0f/(mCreator->getSectorCountX()+1),
				(float)1.0f/(mCreator->getSectorCountZ()+1),
				(float)mSectorX,
				(float)mSectorZ);
			mConnectorRends[i].setCustomShaderParam(0, uvScaleOffset);
		}
	}
Exemplo n.º 26
0
	DynamicRenderable::DynamicRenderable(
		VertexDeclaration * pVtxDecl, 
		RenderOperation::OperationType enRenderOpType, 
		bool bIndices, 
		const size_t nLODLevels, 
		const Real fPixelError, 
		const Ogre::String & sName /*= ""*/
	)
	:	LODRenderable(nLODLevels, fPixelError, false, 0, sName),
		_pVtxDecl(pVtxDecl), _pVtxBB(HardwareBufferManager::getSingletonPtr() ->createVertexBufferBinding()),
		_txWorld(Matrix4::IDENTITY),
		_pvMeshData(new MeshData * [nLODLevels])
	{
		for (unsigned c = 0; c < nLODLevels; ++c)
			_pvMeshData[c] = NULL;

		oht_assert_threadmodel(ThrMdl_Single);
		// Initialize render operation
		_renderOp.operationType = enRenderOpType;
		_renderOp.useIndexes = bIndices;
		_renderOp.vertexData = OGRE_NEW VertexData(pVtxDecl, _pVtxBB);
		_renderOp.indexData = &_indexHWData;
	}
Exemplo n.º 27
0
    //-----------------------------------------------------------------------
    void PatchMesh::loadImpl(void)
    {
        SubMesh* sm = this->createSubMesh();
        sm->vertexData = OGRE_NEW VertexData();
        sm->useSharedVertices = false;

        // Set up vertex buffer
        sm->vertexData->vertexStart = 0;
        sm->vertexData->vertexCount = mSurface.getRequiredVertexCount();
        sm->vertexData->vertexDeclaration = mDeclaration;
        HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().
            createVertexBuffer(
                mDeclaration->getVertexSize(0), 
                sm->vertexData->vertexCount, 
                mVertexBufferUsage, 
                mVertexBufferShadowBuffer);
        sm->vertexData->vertexBufferBinding->setBinding(0, vbuf);

        // Set up index buffer
        sm->indexData->indexStart = 0;
        sm->indexData->indexCount = mSurface.getRequiredIndexCount();
        sm->indexData->indexBuffer = HardwareBufferManager::getSingleton().
            createIndexBuffer(
                HardwareIndexBuffer::IT_16BIT, // only 16-bit indexes supported, patches shouldn't be bigger than that
                sm->indexData->indexCount,
                mIndexBufferUsage, 
                mIndexBufferShadowBuffer);
        
        // Build patch
        mSurface.build(vbuf, 0, sm->indexData->indexBuffer, 0);

        // Set bounds
        this->_setBounds(mSurface.getBounds(), true);
        this->_setBoundingSphereRadius(mSurface.getBoundingSphereRadius());

    }
/* *******************************************************************************
 | implement of CGrassSticks
 ******************************************************************************* */
void 
CGrassSticks::createGrassMesh()
{    
	MeshPtr mesh = MeshManager::getSingleton().createManual(GRASS_MESH_NAME, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

	// create a submesh with the grass material
	SubMesh* sm = mesh->createSubMesh();
	sm->setMaterialName("Examples/GrassBlades");
	sm->useSharedVertices = false;
	sm->vertexData = OGRE_NEW VertexData();
	sm->vertexData->vertexStart = 0;
	sm->vertexData->vertexCount = 12;
	sm->indexData->indexCount = 18;

	// specify a vertex format declaration for our mesh: 3 floats for position, 3 floats for normal, 2 floats for UV
	VertexDeclaration* decl = sm->vertexData->vertexDeclaration;
    decl->addElement(0, 0, VET_FLOAT3, VES_POSITION);
    decl->addElement(0, sizeof(float) * 3, VET_FLOAT3, VES_NORMAL);
    decl->addElement(0, sizeof(float) * 6, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);

	// create a vertex buffer
	HardwareVertexBufferSharedPtr vb = HardwareBufferManager::getSingleton().createVertexBuffer
		(decl->getVertexSize(0), sm->vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);

	GrassVertex* verts = (GrassVertex*)vb->lock(HardwareBuffer::HBL_DISCARD);  // start filling in vertex data

	for (unsigned int i = 0; i < 3; i++)  // each grass mesh consists of 3 planes
	{
		// planes intersect along the Y axis with 60 degrees between them
		Real x = Math::Cos(Degree(i * 60)) * GRASS_WIDTH / 2;
		Real z = Math::Sin(Degree(i * 60)) * GRASS_WIDTH / 2;

		for (unsigned int j = 0; j < 4; j++)  // each plane has 4 vertices
		{
			GrassVertex& vert = verts[i * 4 + j];

			vert.x = j < 2 ? -x : x;
			vert.y = j % 2 ? 0 : GRASS_HEIGHT;
			vert.z = j < 2 ? -z : z;

			// all normals point straight up
			vert.nx = 0;
			vert.ny = 1;
			vert.nz = 0;

			vert.u = j < 2 ? 0 : 1;
			vert.v = j % 2;
		}
	}

	vb->unlock();  // commit vertex changes

	sm->vertexData->vertexBufferBinding->setBinding(0, vb);  // bind vertex buffer to our submesh

	// create an index buffer
	sm->indexData->indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer
		(HardwareIndexBuffer::IT_16BIT, sm->indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY);

	// start filling in index data
	Ogre::uint16* indices = (Ogre::uint16*)sm->indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD);

	for (unsigned int i = 0; i < 3; i++)  // each grass mesh consists of 3 planes
	{
		unsigned int off = i * 4;  // each plane consists of 2 triangles

		*indices++ = 0 + off;
		*indices++ = 3 + off;
		*indices++ = 1 + off;

		*indices++ = 0 + off;
		*indices++ = 2 + off;
		*indices++ = 3 + off;
	}

	sm->indexData->indexBuffer->unlock();  // commit index changes

    // update mesh AABB
    Ogre::AxisAlignedBox aabb;
    aabb.setExtents(-1,-1,-1,1,1,1);
    mesh->_setBounds(aabb);

    // Ogre::MeshSerializer serial;
    // serial.exportMesh(mesh.getPointer(), "grass.mesh");
}
	//---------------------------------------------------------------------
	void PrefabFactory::createSphere(Mesh* mesh)
	{
		// sphere creation code taken from the DeferredShading sample, originally from the wiki
		SubMesh *pSphereVertex = mesh->createSubMesh();

		const int NUM_SEGMENTS = 16;
		const int NUM_RINGS = 16;
		const Real SPHERE_RADIUS = 50.0;

		mesh->sharedVertexData = OGRE_NEW VertexData();
		VertexData* vertexData = mesh->sharedVertexData;

		// define the vertex format
		VertexDeclaration* vertexDecl = vertexData->vertexDeclaration;
		size_t currOffset = 0;
		// positions
		vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_POSITION);
		currOffset += VertexElement::getTypeSize(VET_FLOAT3);
		// normals
		vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_NORMAL);
		currOffset += VertexElement::getTypeSize(VET_FLOAT3);
		// two dimensional texture coordinates
		vertexDecl->addElement(0, currOffset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);

		// allocate the vertex buffer
		vertexData->vertexCount = (NUM_RINGS + 1) * (NUM_SEGMENTS+1);
		HardwareVertexBufferSharedPtr vBuf = HardwareBufferManager::getSingleton().createVertexBuffer(vertexDecl->getVertexSize(0), vertexData->vertexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
		VertexBufferBinding* binding = vertexData->vertexBufferBinding;
		binding->setBinding(0, vBuf);
		float* pVertex = static_cast<float*>(vBuf->lock(HardwareBuffer::HBL_DISCARD));

		// allocate index buffer
		pSphereVertex->indexData->indexCount = 6 * NUM_RINGS * (NUM_SEGMENTS + 1);
		pSphereVertex->indexData->indexBuffer = HardwareBufferManager::getSingleton().createIndexBuffer(HardwareIndexBuffer::IT_16BIT, pSphereVertex->indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false);
		HardwareIndexBufferSharedPtr iBuf = pSphereVertex->indexData->indexBuffer;
		unsigned short* pIndices = static_cast<unsigned short*>(iBuf->lock(HardwareBuffer::HBL_DISCARD));

		float fDeltaRingAngle = (Math::PI / NUM_RINGS);
		float fDeltaSegAngle = (2 * Math::PI / NUM_SEGMENTS);
		unsigned short wVerticeIndex = 0 ;

		// Generate the group of rings for the sphere
		for( int ring = 0; ring <= NUM_RINGS; ring++ ) {
			float r0 = SPHERE_RADIUS * sinf (ring * fDeltaRingAngle);
			float y0 = SPHERE_RADIUS * cosf (ring * fDeltaRingAngle);

			// Generate the group of segments for the current ring
			for(int seg = 0; seg <= NUM_SEGMENTS; seg++) {
				float x0 = r0 * sinf(seg * fDeltaSegAngle);
				float z0 = r0 * cosf(seg * fDeltaSegAngle);

				// Add one vertex to the strip which makes up the sphere
				*pVertex++ = x0;
				*pVertex++ = y0;
				*pVertex++ = z0;

				Vector3 vNormal = Vector3(x0, y0, z0).normalisedCopy();
				*pVertex++ = vNormal.x;
				*pVertex++ = vNormal.y;
				*pVertex++ = vNormal.z;

				*pVertex++ = (float) seg / (float) NUM_SEGMENTS;
				*pVertex++ = (float) ring / (float) NUM_RINGS;

				if (ring != NUM_RINGS) {
					// each vertex (except the last) has six indicies pointing to it
					*pIndices++ = wVerticeIndex + NUM_SEGMENTS + 1;
					*pIndices++ = wVerticeIndex;               
					*pIndices++ = wVerticeIndex + NUM_SEGMENTS;
					*pIndices++ = wVerticeIndex + NUM_SEGMENTS + 1;
					*pIndices++ = wVerticeIndex + 1;
					*pIndices++ = wVerticeIndex;
					wVerticeIndex ++;
				}
			}; // end for seg
		} // end for ring

		// Unlock
		vBuf->unlock();
		iBuf->unlock();
		// Generate face list
		pSphereVertex->useSharedVertices = true;

		// the original code was missing this line:
		mesh->_setBounds( AxisAlignedBox( Vector3(-SPHERE_RADIUS, -SPHERE_RADIUS, -SPHERE_RADIUS), 
			Vector3(SPHERE_RADIUS, SPHERE_RADIUS, SPHERE_RADIUS) ), false );

		mesh->_setBoundingSphereRadius(SPHERE_RADIUS);
	}
	//---------------------------------------------------------------------
	void PrefabFactory::createCube(Mesh* mesh)
	{
		SubMesh* sub = mesh->createSubMesh();

		const int NUM_VERTICES = 4 * 6; // 4 vertices per side * 6 sides
		const int NUM_ENTRIES_PER_VERTEX = 8;
		const int NUM_VERTEX_ENTRIES = NUM_VERTICES * NUM_ENTRIES_PER_VERTEX;
		const int NUM_INDICES = 3 * 2 * 6; // 3 indices per face * 2 faces per side * 6 sides

		const Real CUBE_SIZE = 100.0f;
		const Real CUBE_HALF_SIZE = CUBE_SIZE / 2.0f;

		// Create 4 vertices per side instead of 6 that are shared for the whole cube.
		// The reason for this is with only 6 vertices the normals will look bad
		// since each vertex can "point" in a different direction depending on the face it is included in.
		float vertices[NUM_VERTEX_ENTRIES] = {
			// front side
			-CUBE_HALF_SIZE, -CUBE_HALF_SIZE, CUBE_HALF_SIZE,	// pos
			0,0,1,	// normal
			0,1,	// texcoord
			CUBE_HALF_SIZE, -CUBE_HALF_SIZE, CUBE_HALF_SIZE,
			0,0,1,
			1,1,
			CUBE_HALF_SIZE,  CUBE_HALF_SIZE, CUBE_HALF_SIZE,
			0,0,1,
			1,0,
			-CUBE_HALF_SIZE,  CUBE_HALF_SIZE, CUBE_HALF_SIZE ,
			0,0,1,
			0,0,

			// back side
			CUBE_HALF_SIZE, -CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			0,0,-1,
			0,1,
			-CUBE_HALF_SIZE, -CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			0,0,-1,
			1,1,
			-CUBE_HALF_SIZE, CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			0,0,-1,
			1,0,
			CUBE_HALF_SIZE, CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			0,0,-1,
			0,0,

			// left side
			-CUBE_HALF_SIZE, -CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			-1,0,0,
			0,1,
			-CUBE_HALF_SIZE, -CUBE_HALF_SIZE, CUBE_HALF_SIZE,
			-1,0,0,
			1,1,
			-CUBE_HALF_SIZE, CUBE_HALF_SIZE, CUBE_HALF_SIZE,
			-1,0,0,
			1,0,
			-CUBE_HALF_SIZE, CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			-1,0,0,
			0,0, 

			// right side
			CUBE_HALF_SIZE, -CUBE_HALF_SIZE, CUBE_HALF_SIZE,
			1,0,0,
			0,1,
			CUBE_HALF_SIZE, -CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			1,0,0,
			1,1,
			CUBE_HALF_SIZE, CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			1,0,0,
			1,0,
			CUBE_HALF_SIZE, CUBE_HALF_SIZE, CUBE_HALF_SIZE,
			1,0,0,
			0,0,

			// up side
			-CUBE_HALF_SIZE, CUBE_HALF_SIZE, CUBE_HALF_SIZE,
			0,1,0,
			0,1,
			CUBE_HALF_SIZE, CUBE_HALF_SIZE, CUBE_HALF_SIZE,
			0,1,0,
			1,1,
			CUBE_HALF_SIZE, CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			0,1,0,
			1,0,
			-CUBE_HALF_SIZE, CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			0,1,0,
			0,0,

			// down side
			-CUBE_HALF_SIZE, -CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			0,-1,0,
			0,1,
			CUBE_HALF_SIZE, -CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			0,-1,0,
			1,1,
			CUBE_HALF_SIZE, -CUBE_HALF_SIZE, CUBE_HALF_SIZE,
			0,-1,0,
			1,0,
			-CUBE_HALF_SIZE, -CUBE_HALF_SIZE, CUBE_HALF_SIZE,
			0,-1,0,
			0,0 
		};

		mesh->sharedVertexData = OGRE_NEW VertexData();
		mesh->sharedVertexData->vertexCount = NUM_VERTICES;
		VertexDeclaration* decl = mesh->sharedVertexData->vertexDeclaration;
		VertexBufferBinding* bind = mesh->sharedVertexData->vertexBufferBinding;

		size_t offset = 0;
		decl->addElement(0, offset, VET_FLOAT3, VES_POSITION);
		offset += VertexElement::getTypeSize(VET_FLOAT3);
		decl->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
		offset += VertexElement::getTypeSize(VET_FLOAT3);
		decl->addElement(0, offset, VET_FLOAT2, VES_TEXTURE_COORDINATES, 0);
		offset += VertexElement::getTypeSize(VET_FLOAT2);

		HardwareVertexBufferSharedPtr vbuf = 
			HardwareBufferManager::getSingleton().createVertexBuffer(
			offset, NUM_VERTICES, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
		bind->setBinding(0, vbuf);

		vbuf->writeData(0, vbuf->getSizeInBytes(), vertices, true);

		sub->useSharedVertices = true;
		HardwareIndexBufferSharedPtr ibuf = HardwareBufferManager::getSingleton().
			createIndexBuffer(
			HardwareIndexBuffer::IT_16BIT, 
			NUM_INDICES,
			HardwareBuffer::HBU_STATIC_WRITE_ONLY);

		unsigned short faces[NUM_INDICES] = {
			// front
			0,1,2,
			0,2,3,

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

			// left
			8,9,10,
			8,10,11,

			// right
			12,13,14,
			12,14,15,

			// up
			16,17,18,
			16,18,19,

			// down
			20,21,22,
			20,22,23
		};

		sub->indexData->indexBuffer = ibuf;
		sub->indexData->indexCount = NUM_INDICES;
		sub->indexData->indexStart = 0;
		ibuf->writeData(0, ibuf->getSizeInBytes(), faces, true);

		mesh->_setBounds(AxisAlignedBox(-CUBE_HALF_SIZE, -CUBE_HALF_SIZE, -CUBE_HALF_SIZE,
			CUBE_HALF_SIZE, CUBE_HALF_SIZE, CUBE_HALF_SIZE), true);

		mesh->_setBoundingSphereRadius(CUBE_HALF_SIZE);
	}