Ejemplo n.º 1
0
void Shader::draw( VBO& geometry, GLenum renderType ){

    bindGeometry( &geometry );
    
    VertexAttributeBase* attr = NULL;
    if(geometry.getAttr("indices") == NULL ){
        glDrawArrays( renderType, 0, (attr)? attr->count : 0 );
    }
    else{
        attr = geometry.getAttr("indices");
        
        //bind and draw the indices
        attr->bind();
        glIndexPointer( GL_UNSIGNED_INT, 0, 0);
        glDrawElements( renderType, attr->count, GL_UNSIGNED_INT, 0);
        
        //unbind
        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0);
    }
    
    //unbind all the buffers and attributes
    attr = NULL;
//    for(a_it = attributes.begin(); a_it != attributes.end(); a_it++){
//        glDisableVertexAttribArray( a_it->second );
//        glBindBuffer( GL_ARRAY_BUFFER, 0 );
//    }
}
Ejemplo n.º 2
0
void VBO::DrawVertices(VBO& vertexBuffer, const GLenum mode, const GLsizei count) {

    vertexBuffer.EnableVertexAttribInterleavedWithBind();

    vertexBuffer.DrawVertices(mode, count);

    vertexBuffer.DisableVertexAttribInterleavedWithBind();
}
Ejemplo n.º 3
0
VBO* VBO::CreateIndex(const GLenum type) {
    VBO* indexBuffer = new VBO();

    indexBuffer->SetTarget(GL_ELEMENT_ARRAY_BUFFER);
    indexBuffer->SetType(type);
    indexBuffer->SetUsage(GL_STATIC_DRAW);

    return indexBuffer;
}
Ejemplo n.º 4
0
TEST_F(TransformFeedbackTest, test)
{
    std::ifstream       vsFile("data/transform_feedback.vert");
    std::ifstream       gsFile("data/transform_feedback.geom");
    Shader              vertex(GL_VERTEX_SHADER);
    Shader              geometry(GL_GEOMETRY_SHADER);
    ShaderProgram       shader;
    Query               query(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
    VAO                 vao;
    VBO                 vbo;
    TFBO                tfbo;
    const GLchar*       feedbackVaryings[] = { "outValue" };
    GLfloat             data[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
    GLfloat             feedback[15];
    GLuint              primitives;

    ASSERT_TRUE(vertex.compile(vsFile));
    ASSERT_TRUE(geometry.compile(gsFile));
    shader.attach(vertex);
    shader.attach(geometry);

    shader.setTransformFeedbackVaryings(1, feedbackVaryings, GL_INTERLEAVED_ATTRIBS);
    ASSERT_TRUE(shader.link());
    shader.use();
    shader.printDebug();

    vao.bind();

    vbo.bind();
    vbo.setData(sizeof(data), data, GL_STATIC_DRAW);

    GLint inputAttrib = shader.getAttribLocation("inValue");

    vao.enableAttrib(inputAttrib);
    glVertexAttribPointer(inputAttrib, 1, GL_FLOAT, GL_FALSE, 0, 0);

    tfbo.setData(sizeof(data) * 3, nullptr, GL_STATIC_READ);
    tfbo.bindBufferBase(0);

    mogl::enable(GL_RASTERIZER_DISCARD);
    query.begin();
    TransformFeedback::begin(GL_TRIANGLES);
    glDrawArrays(GL_POINTS, 0, 5);
    TransformFeedback::end();
    query.end();
    mogl::disable(GL_RASTERIZER_DISCARD);
    mogl::Sync::flush();

    primitives = query.get<GLuint>(GL_QUERY_RESULT);
    tfbo.getSubData(0, sizeof(feedback), feedback);
    std::cout << primitives << " primitives written" << std::endl;
    for (unsigned int i = 0; i < 15; ++i)
        std::cout << feedback[i] << std::endl;
}
Ejemplo n.º 5
0
void UBOShaderInterface::SetUpBuffer(VBO &buffer)
{
	assert(!buffer.Created());

	buffer.Create();

	buffer.Bind(GL_UNIFORM_BUFFER);

	glBufferData(GL_UNIFORM_BUFFER, m_blockSize, NULL, GL_STREAM_DRAW);

	// Allocate VBO using this size
	buffer.Unbind();
}
Ejemplo n.º 6
0
VBOScene::VBOScene()
// Start of user code super class
// End of user code
{
	// Start of user code constructor
    cameras.push_back(new TrackBallCamera());
    doubleBuffer = new DoubleBuffer();
    doubleBuffer->getVertexBuffer()->init();
    VBO* vBO = new VoxelVBO();
    vBO->setInstanceSize(6);
    doubleBuffer->setVBO(vBO);
    updateCamera = true;
    bindBuffer = false;
    // End of user code
}
Ejemplo n.º 7
0
/// assuming vao is already bound
void ParticleBilboard::setVaoPointers(VBO &vbo, u32 start){
	vbo.attrib(1).pointer_float(4, (sizeof(ParticleBilboard)), (void*)offsetof(ParticleBilboard, position)).divisor(1)
		.attrib(2).pointer_float(4, (sizeof(ParticleBilboard)), (void*)offsetof(ParticleBilboard, velocity)).divisor(1)
		.attrib(3).pointer_float(1, (sizeof(ParticleBilboard)), (void*)offsetof(ParticleBilboard, lifetime)).divisor(1)
		.attrib(4).pointer_float(1, (sizeof(ParticleBilboard)), (void*)offsetof(ParticleBilboard, layer)).divisor(1)
		.attrib(5).pointer_float(1, (sizeof(ParticleBilboard)), (void*)offsetof(ParticleBilboard, size)).divisor(1);
}
Ejemplo n.º 8
0
    virtual void draw() override {
//        float effTheta = theta + deltaSinceLastUpdate().in(Seconds);
        float effTheta = theta;
//        float effTheta = epochNanosSteady() * 1000000.0f;
//        float effTheta = glfwGetTime();
        AxGL::checkError();
        modelview = glm::lookAt(
                glm::vec3(0.0f,0.0f,-10.0f),
                glm::vec3(0.0f,0.0f,0.0f),
                glm::vec3(0.0f,1.0f,0.0f)
        );
        modelview = glm::rotate(modelview,effTheta,glm::vec3(0.0f,0.0f,-1.0f));

        projection = glm::perspective(45.0f,AxGL::aspectRatio(),0.5f,200.0f);

        glDisable(GL_DEPTH_TEST);

        texture->bind();
        AxGL::checkError();
        shader->bind();
        AxGL::checkError();
        shader->setUniform("ModelViewMatrix", modelview);
        shader->setUniform("ProjectionMatrix", projection);
        shader->setUniform("tex0",0);
        AxGL::checkError();
        vbo.drawElements();
        AxGL::checkError();
    }
Ejemplo n.º 9
0
void
PrimitiveRenderer::bind(const VBO & vbo) {
  if (vbo.hasVertexArrayObjects()) {
    int a = vbo.getVertexArrayId();
    if (!a) {
      cerr << "trying to bind zero vao" << endl;
      assert(0);
    } else if (a != current_vertex_array) {
      current_vertex_array = a;
      glBindVertexArray(a);
    }
  } else {
    glBindBuffer(GL_ARRAY_BUFFER, vbo.getVertexBufferId());
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.getIndexBufferId());
    vbo.setPointers();
  }
}
Ejemplo n.º 10
0
VBO::VBO(const VBO& vbo) :
	m_data_size(vbo.m_data_size),
	m_nbElts(vbo.m_nbElts),
	m_lock(false)
{
	unsigned int nbbytes =  sizeof(float) * m_data_size * m_nbElts;

	glGenBuffers(1, &(*m_id));

	vbo.bind();
	void* src = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);

	bind();
	glBufferData(GL_ARRAY_BUFFER, nbbytes, src, GL_STREAM_DRAW);

	vbo.bind();
	glUnmapBuffer(GL_ARRAY_BUFFER);
}
Ejemplo n.º 11
0
void RAS_StorageVBO::IndexPrimitives(RAS_MeshSlot& ms)
{
	RAS_MeshSlot::iterator it;
	VBO *vbo;

	for (ms.begin(it); !ms.end(it); ms.next(it))
	{
		vbo = m_vbo_lookup[it.array];

		if (vbo == 0)
			m_vbo_lookup[it.array] = vbo = new VBO(it.array, it.totindex);

		// Update the vbo
		if (ms.m_mesh->MeshModified())
		{
			vbo->UpdateData();
		}

		vbo->Draw(*m_texco_num, m_texco, *m_attrib_num, m_attrib, m_attrib_layer);
	}
}
Ejemplo n.º 12
0
bool commitVBO(U32 chunkCount, GLenum usage, GLuint& handleOut, size_t& offsetOut) {
    if (chunkCount < VBO::MAX_VBO_CHUNK_COUNT) {
        for (VBO& vbo : g_globalVBOs) {
            if (vbo.allocateChunks(chunkCount, usage, offsetOut)) {
                handleOut = vbo.handle();
                return true;
            }
        }

        VBO vbo;
        if (vbo.allocateChunks(chunkCount, usage, offsetOut)) {
            handleOut = vbo.handle();
            g_globalVBOs.push_back(vbo);
            return true;
        }
    } else {
        VBO vbo;
        if (vbo.allocateWhole(chunkCount, usage)) {
            offsetOut = 0;
            handleOut = vbo.handle();
            g_globalVBOs.push_back(vbo);
            return true;
        }
    }

    return false;
}
Ejemplo n.º 13
0
void init() {

    camera.position[2] = 15;

    libpng_version();

    light0.slot = GL_LIGHT0;
    light0.setDiffuse(1.0, 1.0, 1.0, 1.0);
    light0.setPosition(0.0, 0.0, 1.0, 0.0);
    light0.load();
    light0.enable();

    glewInit();

    loadObj((char*) "models/350z.obj", &mesh);
    VBOfromMesh(vbo, mesh);

    vbo.generate();

    int w, h;
    test_texture = texture_bank.findOrReg((char*) "textures/350z/vinyls.png");
    //test_texture = PNG_load((const char*) "textures/vinyls.png", &w, &h);

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, test_texture);

    programID = loadShaders("shaders/vertex.glsl", "shaders/fragment.glsl");
    glUseProgram(programID);

    uTex = glGetUniformLocation(programID, "texDiff");
    glUniform1i(uTex, 0);

    uProjection = glGetUniformLocation(programID, "projection");
    uView = glGetUniformLocation(programID, "view");
    uModel = glGetUniformLocation(programID, "model");

    uLightPos = glGetUniformLocation(programID, "lightPos");
    uLightDiff = glGetUniformLocation(programID, "lightDiff");
    uLightSpec = glGetUniformLocation(programID, "lightSpec");

    uCameraPosition = glGetUniformLocation(programID, "cameraPosition");

    glEnable(GL_LIGHTING);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_ALPHA_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

    glEnable(GL_DEPTH_TEST);
}
Ejemplo n.º 14
0
    virtual void init() override {
        auto va = vbo.addQuad();

        if (vbo.changeState(VBOs::Dirty, VBOs::Updating)) {
            va[0].position = glm::vec3(-5.0f,-5.0f,0.0f);
            va[1].position = glm::vec3(5.0f,-5.0f,0.0f);
            va[2].position = glm::vec3(5.0f,5.0f,0.0f);
            va[3].position = glm::vec3(-5.0f,5.0f,0.0f);

            va[0].texCoord = glm::vec2(0.0f,0.0f);
            va[1].texCoord = glm::vec2(1.0f,0.0f);
            va[2].texCoord = glm::vec2(1.0f,1.0f);
            va[3].texCoord = glm::vec2(0.0f,1.0f);

            for (int i = 0; i < 4; ++i) {
//                va[i].setColor(i/4.0f,0.0f,0.0f,1.0f);
                va[i].setColor(1.0f,1.0f,1.0f,1.0f);
            }

            vbo.changeState(VBOs::Updating,VBOs::Updated);
        } else {
            Noto::error("VBO was in wrong initial state");
        }
    }
Ejemplo n.º 15
0
VBO* VBO::CreateInterleaved(const std::vector<GLuint>& sizes, const GLenum usage){

    VBO* buffer = new VBO();

    buffer->SetTarget(GL_ARRAY_BUFFER);
    buffer->SetType(GL_FLOAT);
    buffer->SetUsage(usage);

    buffer->m_sizes = sizes;

    buffer->m_offsets.reserve(sizes.size());

    GLuint totalOffset = 0;
    for(size_t i = 0; i <buffer->m_sizes.size(); ++i) {

	buffer->m_offsets.push_back(totalOffset);
        totalOffset += buffer->m_sizes[i] * sizeof(GLfloat);


    }
    buffer->STRIDE = totalOffset;

    return buffer;
}
Ejemplo n.º 16
0
int main_test(){
  Context context;
  StopWatch swatch;
  World world;
  CameraControl ev;
  glPointSize(2.0);
  ev.cam.position = vec(0.0f,0.0f,5.0f);
  mouse_move_spawner.register_listener(&ev);
  key_event_handler.register_listener(&ev);
  
  FlatShader3D flat;
  flat.SetProjection(ProjectionMatrix(0.01,0.01,0.01,200000.0));
  
  GameObject * go = new GameObjectTest(context);
  
  go->GravityBound = false;
  go->aabb.pos[0] += 0.1;
  go->aabb.pos[2] += 0.1;
  go->aabb.pos[1] -= 4.0;
  go->aabb.size = vec(20.0,2.0,20.0);
  go->aabb.mass = 100000.0;
  go->Tetra.TRS = TMatrix(vec(10.0f,0.0f,10.0f)) * SMatrix(vec(10.0f,1.0f,10.0f));
  world.InsertObject(go);

  go = new GameObjectTest(context);
  go->GravityBound = false;
  go->aabb.size = vec(2.0,2.0,2.0);
  go->Tetra = Tetragon();
  world.InsertObject(go);
  VBO stars = context.Stars;
  while(true){
    Matrix<float,4> cameraMatrix;
    go->aabb.pos = -ev.cam.position.As<double>() - vec(0.0,0.0,0.0);
    print(go->aabb.pos);
    auto goList = world.GetNearbyObjects(vec(0.0,0.0,0.0),5000000.0);
    world.PhysicsUpdate(vec(0.0,0.0,0.0),500000,0.1);

    for(auto go : goList){
      go.Get()->DoUpdate(world);
    }

    //ev.cam.position = go->aabb.pos.As<float>() + vec(0.0f,-2.0f,0.0f);
    print(go->aabb.pos);
    swatch.Reset();
    swatch.Start();
    ClearBuffer(vec(0.0f,0.0f,0.0f,1.0f));
    cameraMatrix = ev.GetCamera().getTransformMatrix();
    /*cameraMatrix[3][0] = 0;
    cameraMatrix[3][1] = 0;
    cameraMatrix[3][2] = 0;
    */
    flat.SetCamera(cameraMatrix);   
    
    flat.SetModelView(Matrix<float,4>::Eye());
    context.StarColors.Bind(0);
    stars.BindBuffer(0);
    VertexBufferObject::DrawBuffers(DrawMethod::Points,100);
    flat.SetCamera(ev.GetCamera().getTransformMatrix());   
    goList = world.GetNearbyObjects(vec(0.0,0.0,0.0),5000000.0);
    for(auto go: goList){
      go.Get()->Draw(flat);
    }
    SwapBuffers();
    Sleep(1/30.0 - swatch.ElapsedSeconds());
  }
}
Ejemplo n.º 17
0
	// write output to VBO
	void write(VBO& vbo, GLenum usage = GL_STATIC_DRAW) {
		vbo.data(GL_ARRAY_BUFFER, _array, usage);
	}
Ejemplo n.º 18
0
int	MaxExporter::DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options)
{

	/*if(!suppressPrompts)
		DialogBoxParam(hInstance, 
				MAKEINTRESOURCE(IDD_PANEL), 
				GetActiveWindow(), 
				MaxExporterOptionsDlgProc, (LPARAM)this);*/

	#pragma message(TODO("return TRUE If the file is exported properly"))

	Node::s_nextID = 1;
	ofstream myFile;
	myFile.open("DebugExporter.txt");
	wstring wFileName( name );
	string fileName( wFileName.begin(), wFileName.end() );
	//f= fopen( fileName.c_str(),"wb");
	BinaryFile = loadSave( fileName.c_str() );
	//BinaryFile.saveInt( 5 );
	//BinaryFile.close();
	myFile << "Start Export\n";

	IGameScene* gameScene = GetIGameInterface();
	gameScene->InitialiseIGame();
	int nodeCount = gameScene->GetTopLevelNodeCount();
	myFile << "Number of top level nodes: " << nodeCount << "\n";
	//get all of the materials
	for( int nodeNumber = 0; nodeNumber < nodeCount; ++nodeNumber)
	{
		IGameNode* gameNode = gameScene->GetTopLevelNode( nodeNumber );
		
		Node* myNode = new Node( gameNode );
		m_NodeList.push_back( myNode );
		findFaces( myNode, myFile );
		
	}

	myFile << "Number of materials\n";
	myFile << m_materialSet.size() << "\n";
	

	int totalBatches = 0;
	//myFile<< "Number of triangleBatchMaps: " << m_triangleBatchesPerNode.size() << "\n";
	for( auto nodeIter = m_NodeList.begin(); nodeIter != m_NodeList.end(); ++nodeIter )
	{
		std::map< IGameMaterial*, TriangleBatch* > triangleBatches = (*nodeIter)->m_triangleBatchesPerMaterial;
		myFile << "Invidiual triangleBatch size: " << triangleBatches.size() << "\n";

		for( auto materialIter = m_materialSet.begin(); materialIter != m_materialSet.end(); ++materialIter )
		{
			auto found = triangleBatches.find( * materialIter );
			if( found != triangleBatches.end() )
			{
				++totalBatches;
			}
		}
	}

	BinaryFile.saveInt( m_NodeList.size() );
	myFile << "Number of Nodes: " << m_NodeList.size() << "\n";
	
	for( auto nodeIter = m_NodeList.begin(); nodeIter != m_NodeList.end(); ++nodeIter )
	{
		std::map< IGameMaterial*, TriangleBatch* > triangleBatches = (*nodeIter)->m_triangleBatchesPerMaterial;
		std::map<IGameMaterial*, std::vector< NodeFace > > facesPerMaterial = (*nodeIter)->m_facesPerMaterial;
		IGameNode* currentNode = (*nodeIter)->m_gameNode;
		IGameNode* parentNode;
		GMatrix parentWTM;
		GMatrix toParentMatrix;
		GMatrix worldTM;
		GMatrix localTM;
		int time = gameScene->GetSceneStartTime();
		for( ; time < gameScene->GetSceneEndTime(); time += 4800/30 )
		{
			if( (*nodeIter)->m_parentID != 0 )
			{
				myFile << "Trying to find parent... \n";
				parentNode = (*nodeIter)->m_parent->m_gameNode;
				if( parentNode != nullptr )
				{
					myFile << "Parent found \n";
					parentWTM = parentNode->GetWorldTM( time );
					toParentMatrix = parentWTM.Inverse();

					worldTM = currentNode->GetWorldTM(  time ) * toParentMatrix;

				}

			}
			else
			{
				worldTM = currentNode->GetWorldTM( time );
				
			}
			(*nodeIter)->m_toParentMatrix.push_back( Matrix4x4( worldTM[0], worldTM[1], worldTM[2], worldTM[3] ) );
		}


		localTM = currentNode->GetWorldTM().Inverse();
		(*nodeIter)->m_worldToLocal = Matrix4x4(  localTM[0], localTM[1], localTM[2], localTM[3] );
		

		//Save the node
		BinaryFile.saveNode( *nodeIter, myFile );
		BinaryFile.saveInt( (*nodeIter)->m_triangleBatchesPerMaterial.size() );
	
		for( auto materialIter = m_materialSet.begin(); materialIter != m_materialSet.end(); ++materialIter )
		{
			//Set the current material's VBO and IBO
			//
			IGameMaterial* currentMaterial = *materialIter;
			TriangleBatch* currentBatch = triangleBatches[ currentMaterial ];
			
			GMatrix localTMNoTrans = localTM;
			localTMNoTrans.SetRow( 3, Point4( 0,0,0,1) );
			if( currentBatch != nullptr )
			{
				
				MaxMaterial* currentMaxMaterial = currentBatch->m_material;
				VBO* currentVBO = currentBatch->m_vbo;
				IBO* currentIBO = currentBatch->m_ibo;
				vector< NodeFace >& faceVector = facesPerMaterial.find( currentMaterial )->second;

				//Get texture materials and export them
				//
				if( currentMaterial != nullptr )
				{
					int numOfTexMaps = currentMaterial->GetNumberOfTextureMaps();
					myFile << "Number of texture maps: " << numOfTexMaps << "\n";
					for( int i = 0; i < numOfTexMaps; ++i )
					{
						IGameTextureMap* gameTextureMap = currentMaterial->GetIGameTextureMap( i );
						
						if( gameTextureMap != nullptr && gameTextureMap->IsEntitySupported() )
						{
							int stdMapSlot = gameTextureMap->GetStdMapSlot();
							if( stdMapSlot == ID_DI )
							{
								wstring wBitmapFileName;
								wBitmapFileName = gameTextureMap->GetBitmapFileName();
								if( wBitmapFileName.size() > 0 )
								{
									BitmapInfo bi( gameTextureMap->GetBitmapFileName() );
									BMMGetFullFilename( &bi );
									wBitmapFileName = bi.Name();
									std::string fullBitmapFileName( wBitmapFileName.begin(), wBitmapFileName.end() );
									if( fullBitmapFileName.size() > 0 )
									{
										int lastSlash = fullBitmapFileName.find_last_of('\\') + 1;
										if( lastSlash != string::npos )
										{
											const std::string bitmapFileName = fullBitmapFileName.substr( lastSlash );
											wstring nameAsWString( name );
											std::string nameAsString( nameAsWString.begin(), nameAsWString.end() );
											const std::string extension = nameAsString.substr( 0, nameAsString.find_last_of('\\') + 1 );
											std::string newFileName = extension;
											newFileName.append( bitmapFileName );
											wstring wNewFileName(newFileName.begin(), newFileName.end());
											if( CopyFile( wBitmapFileName.c_str(), wNewFileName.c_str(), false ) )
											{
												if( stdMapSlot == ID_DI )
												{
													currentMaxMaterial->m_diffuseTexture = bitmapFileName;
													currentMaxMaterial->bHasDiffuseTexture = true;
												}
											//BinaryFile.saveString( bitmapFileName );
											}
											else
											{
												myFile << GetLastError() << "\n";
												myFile << "copying the file FAILED.\n";
											}
										}
									}	
								}
							}
						}
					}
				}
				
				myFile<< "Number of faces for this material: " << faceVector.size() << "\n";
				for( int face = 0; face < faceVector.size(); ++face )
				{
					FaceEx* meshFace = faceVector[face].m_face;
					IGameMesh* gameMesh = faceVector[face].m_mesh;
					IGameSkin* gameSkin = gameMesh->GetIGameSkin();
					int position, normal, color, texCoordinate, maxPosition;
					for( int i = 0; i < 3; ++i)
					{
						
						maxPosition = (int)meshFace->vert[i];
						
						Point3 tempPos = gameMesh->GetVertex( maxPosition );
						tempPos = tempPos * localTM;
						Vector3D positionVec3( tempPos.x, tempPos.y, tempPos.z );
						position = currentVBO->insertPosition(positionVec3);

						normal = (int)meshFace->norm[i];
						Point3 tempNormal = gameMesh->GetNormal( normal );
						tempNormal = tempNormal * localTMNoTrans;
						tempNormal = tempNormal.Normalize();
						
						Vector3D normalVec3( tempNormal.x, tempNormal.y, tempNormal.z );
						normal = currentVBO->insertNormal(normalVec3);

						//IBO
						texCoordinate = (int)meshFace->texCoord[i];
						Point2 tempTexCoord = gameMesh->GetTexVertex( texCoordinate );
						Vector2 texCoordVec2( tempTexCoord.x, tempTexCoord.y );
						texCoordinate = currentVBO->insertTexCoord(texCoordVec2);
						VertexIndex VI( position, normal, texCoordinate );
						if( gameSkin != nullptr )
						{
							int numberOfBones = gameSkin->GetNumberOfBones( maxPosition );
							for( int boneIndex = 0; boneIndex < numberOfBones; ++boneIndex )
							{
								float boneWeight = gameSkin->GetWeight( maxPosition, boneIndex );
								IGameNode* bone = gameSkin->GetIGameBone( maxPosition, boneIndex );
								myFile << "Bone node ID: " << bone->GetNodeID() << "\n";
								int nodeIDForBone = m_boneIDToNodeID[ bone->GetNodeID() ];
								myFile << "Node ID: " << nodeIDForBone << "\n";
								VI.addBoneWeight( nodeIDForBone, boneWeight );

								/*for( auto boneIter = m_NodeList.begin(); boneIter != m_NodeList.end(); ++boneIter )
								{
									if( (*boneIter)->m_gameNode == bone )
									{
										myFile << "Found the bone!\n"; 
										
									}
								}*/
								
							}
							VI.topBoneWeights();
						}

						int vertIndex = currentVBO->insertVertex( VI );
						currentIBO->addIndex( vertIndex );

					}

				}
				
				BinaryFile.saveTriangleMesh( currentBatch, myFile );
			}
		}

	}
	myFile.close();

	for( int nodeNumber = 0; nodeNumber < nodeCount; ++nodeNumber)
	{
		IGameNode* gameNode = gameScene->GetTopLevelNode( nodeNumber );
		if( gameNode != nullptr )
		{
			tearDown( gameNode );
		}
		
	}

	BinaryFile.close();
	return TRUE;

	//return FALSE;
}
Ejemplo n.º 19
0
void VBOScene::render()
{
	// Start of user code render
    Engine* engine = Engine::getInstance();
    Shader* shader = engine->getShaders()[0];

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    // Enable blending
    //glEnable(GL_BLEND);
    //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    

    if(background != NULL)
        background->render();
    
    //glBindBuffer(GL_ARRAY_BUFFER, 0);
    
    //return;
    
    //3D
    
    glUseProgram(shader->getProgramID());
    
    if(updateCamera)
    {
        glUniformMatrix4fv(shader->getMVPMatrixID(), 1, GL_FALSE, &getSelectedCamera()->getMVP()[0][0]);
        /*glUniformMatrix4fv(shader->getMMatrixID(), 1, GL_FALSE, &getSelectedCamera()->getModel()[0][0]);
        glUniformMatrix4fv(shader->getVMatrixID(), 1, GL_FALSE, &getSelectedCamera()->getView()[0][0]);
        glUniformMatrix4fv(shader->getPMatrixID(), 1, GL_FALSE, &getSelectedCamera()->getProjection()[0][0]);*/
        updateCamera = false;
    }

    //for(int i = 0; i < doubleBuffers.size(); i++)
    {
        glBindBuffer(GL_ARRAY_BUFFER, doubleBuffer->getVertexBuffer()->getId());
        
        VBO* vBO = doubleBuffer->getVBO();
        vector<Attribute*> attributes = vBO->getAttributes();
        for(int i = 0; i < attributes.size(); i++)
            glEnableVertexAttribArray(i);
        
        int size = 0;
        
        int instanceFace = 4;
        
        for(int i = 0; i < attributes.size(); i++)
        {
            if( i == 2 )
                size=0;
            
            float stride = sizeof(GLfloat) * ( (attributes[i]->getDivisor()>0) ? 2 : 4);
            int divisor = attributes[i]->getDivisor();
            GLvoid* offset = (GLvoid*)(sizeof(GLuint) * size + sizeof(GLuint)*(divisor > 0 ? instanceFace*6*4/*72*/ : 0));//32 : 0));
            
            glVertexAttribIPointer( i, attributes[i]->getSize(), GL_UNSIGNED_INT, stride, offset);
            if(attributes[i]->getDivisor()>0)
                glVertexAttribDivisor( i, attributes[i]->getDivisor());
            size += attributes[i]->getSize();
        }
        
        //glBindBuffer(GL_ARRAY_BUFFER, doubleBuffer->getVertexBuffer()->getId());//bufferIDs[i]);
        
        vector<GLuint>* data = doubleBuffer->getVertexBuffer()->getData();
        
        //if(data->size() != oldSize)
        {
            int instanceCountFull = (data->size()-(instanceFace*6*4)/*72*/)/2;
            //int instanceCount = min( instanceCountFull, 140000 );
            glDrawArraysInstanced(GL_TRIANGLES, 0, instanceFace*6, instanceCountFull);
            //glDrawArraysInstanced(GL_TRIANGLES, 0, 18, instanceCount);
            //glDrawArraysInstanced(glDrawArraysInstanced, doubleBuffer->getIndiceBuffer()->getData()->size(), GL_UNSIGNED_INT, (void*)0, (data->size()-32)/4 );
          //  oldSize = data->size();
        }
        
        for(int i = 0; i < attributes.size(); i++)
            glDisableVertexAttribArray(i);
        
        glBindBuffer(GL_ARRAY_BUFFER, 0);
    }
    
    //2D
    if(uI != NULL)
        uI->render();
	// End of user code
}
Ejemplo n.º 20
0
void UBOShaderInterface::BindBufferToSetIndex(VBO &buffer)
{
	glBindBufferBase(GL_UNIFORM_BUFFER, m_bufferBindIndex, buffer.GetID());
}