コード例 #1
0
ファイル: GUIFontTTFGL.cpp プロジェクト: Karlson2k/xbmc
void CGUIFontTTFGL::LastEnd()
{
#ifdef HAS_GL
  glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);

  glColorPointer   (4, GL_UNSIGNED_BYTE, sizeof(SVertex), (char*)&m_vertex[0] + offsetof(SVertex, r));
  glVertexPointer  (3, GL_FLOAT        , sizeof(SVertex), (char*)&m_vertex[0] + offsetof(SVertex, x));
  glTexCoordPointer(2, GL_FLOAT        , sizeof(SVertex), (char*)&m_vertex[0] + offsetof(SVertex, u));
  glEnableClientState(GL_COLOR_ARRAY);
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  glDrawArrays(GL_QUADS, 0, m_vertex.size());
  glPopClientAttrib();

  glActiveTexture(GL_TEXTURE1);
  glBindTexture(GL_TEXTURE_2D, 0);
  glDisable(GL_TEXTURE_2D);
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, 0);
  glDisable(GL_TEXTURE_2D);
#else
  // GLES 2.0 version.
  g_Windowing.EnableGUIShader(SM_FONTS);

  CreateStaticVertexBuffers();

  GLint posLoc  = g_Windowing.GUIShaderGetPos();
  GLint colLoc  = g_Windowing.GUIShaderGetCol();
  GLint tex0Loc = g_Windowing.GUIShaderGetCoord0();
  GLint modelLoc = g_Windowing.GUIShaderGetModel();

  // Enable the attributes used by this shader
  glEnableVertexAttribArray(posLoc);
  glEnableVertexAttribArray(colLoc);
  glEnableVertexAttribArray(tex0Loc);

  if (m_vertex.size() > 0)
  {
    // Deal with vertices that had to use software clipping
    std::vector<SVertex> vecVertices( 6 * (m_vertex.size() / 4) );
    SVertex *vertices = &vecVertices[0];

    for (size_t i=0; i<m_vertex.size(); i+=4)
    {
      *vertices++ = m_vertex[i];
      *vertices++ = m_vertex[i+1];
      *vertices++ = m_vertex[i+2];

      *vertices++ = m_vertex[i+1];
      *vertices++ = m_vertex[i+3];
      *vertices++ = m_vertex[i+2];
    }

    vertices = &vecVertices[0];

    glVertexAttribPointer(posLoc,  3, GL_FLOAT,         GL_FALSE, sizeof(SVertex), (char*)vertices + offsetof(SVertex, x));
    // Normalize color values. Does not affect Performance at all.
    glVertexAttribPointer(colLoc,  4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(SVertex), (char*)vertices + offsetof(SVertex, r));
    glVertexAttribPointer(tex0Loc, 2, GL_FLOAT,         GL_FALSE, sizeof(SVertex), (char*)vertices + offsetof(SVertex, u));

    glDrawArrays(GL_TRIANGLES, 0, vecVertices.size());
  }
  if (m_vertexTrans.size() > 0)
  {
    // Deal with the vertices that can be hardware clipped and therefore translated

    // Bind our pre-calculated array to GL_ELEMENT_ARRAY_BUFFER
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementArrayHandle);
    // Store currect scissor
    CRect scissor = g_graphicsContext.StereoCorrection(g_graphicsContext.GetScissors());

    for (size_t i = 0; i < m_vertexTrans.size(); i++)
    {
      // Apply the clip rectangle
      CRect clip = g_Windowing.ClipRectToScissorRect(m_vertexTrans[i].clip);
      if (!clip.IsEmpty())
      {
        // intersect with current scissor
        clip.Intersect(scissor);
        // skip empty clip
        if (clip.IsEmpty())
          continue;
        g_Windowing.SetScissors(clip);
      }

      // Apply the translation to the currently active (top-of-stack) model view matrix
      glMatrixModview.Push();
      glMatrixModview.Get().Translatef(m_vertexTrans[i].translateX, m_vertexTrans[i].translateY, m_vertexTrans[i].translateZ);
      glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glMatrixModview.Get());

      // Bind the buffer to the OpenGL context's GL_ARRAY_BUFFER binding point
      glBindBuffer(GL_ARRAY_BUFFER, (GLuint) m_vertexTrans[i].vertexBuffer->bufferHandle);

      // Do the actual drawing operation, split into groups of characters no
      // larger than the pre-determined size of the element array
      for (size_t character = 0; m_vertexTrans[i].vertexBuffer->size > character; character += ELEMENT_ARRAY_MAX_CHAR_INDEX)
      {
        size_t count = m_vertexTrans[i].vertexBuffer->size - character;
        count = std::min<size_t>(count, ELEMENT_ARRAY_MAX_CHAR_INDEX);

        // Set up the offsets of the various vertex attributes within the buffer
        // object bound to GL_ARRAY_BUFFER
        glVertexAttribPointer(posLoc,  3, GL_FLOAT,         GL_FALSE, sizeof(SVertex), (GLvoid *) (character*sizeof(SVertex)*4 + offsetof(SVertex, x)));
        glVertexAttribPointer(colLoc,  4, GL_UNSIGNED_BYTE, GL_TRUE,  sizeof(SVertex), (GLvoid *) (character*sizeof(SVertex)*4 + offsetof(SVertex, r)));
        glVertexAttribPointer(tex0Loc, 2, GL_FLOAT,         GL_FALSE, sizeof(SVertex), (GLvoid *) (character*sizeof(SVertex)*4 + offsetof(SVertex, u)));

        glDrawElements(GL_TRIANGLES, 6 * count, GL_UNSIGNED_SHORT, 0);
      }

      glMatrixModview.Pop();
    }
    // Restore the original scissor rectangle
    g_Windowing.SetScissors(scissor);
    // Restore the original model view matrix
    glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glMatrixModview.Get());
    // Unbind GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  }

  // Disable the attributes used by this shader
  glDisableVertexAttribArray(posLoc);
  glDisableVertexAttribArray(colLoc);
  glDisableVertexAttribArray(tex0Loc);

  g_Windowing.DisableGUIShader();
#endif
}
コード例 #2
0
ファイル: testDamaPlan.cpp プロジェクト: gaschler/mopl
int main(int argc, char** argv)
{
	::dama::XmlFactory damaFactory;
	boost::shared_ptr< ::dama::DamaModel > model = damaFactory.create("data/tasks/config.xml");

	::dama::Timer timer;
	
	/** Configurations */
	//model->debugMode = true;
	
	::std::size_t numRuns = 1;	// 200

	// calculate numRuns seeds (with value in srand you can change the seed set)
	srand(model->groupSeed);
	// srand(time(NULL));
	::std::vector < ::std::size_t > vecSeeds(numRuns, 0);
	for(::std::size_t u=0; u<numRuns; ++u)
		vecSeeds.at(u) = rand();


	// write benchmark header
	std::ofstream benchmarkHeader;
	benchmarkHeader.open("DamaBenchmark.csv", std::ios::app);
	// #iterations: not counted: if sample is unreachable from tree a or is exact a neighbor of tree a or if connected vertex is unreachable from tree b
	benchmarkHeader << "date,robot,nr,seed,solved,tGlobal,tIK,tSampling,tNNSearch,tPropagate,tConnect,iterations,edges,vertices,totalQueries,freeQueries,solVertices,solLength,solLengthMan";
	for(::std::size_t p=0; p<model->vecDamaPrim.size(); ++p)
		benchmarkHeader << "," << model->vecDamaPrim.at(p)->getName() ;
	benchmarkHeader << ::std::endl;
	benchmarkHeader.close();


	::std::vector <bool> vecSolved(numRuns, false);
	::std::vector < ::rl::math::Real > vecTime(numRuns, 0);
	::std::vector < ::std::size_t > vecIterations(numRuns, 0);
	::std::vector < ::std::size_t > vecEdges(numRuns, 0);
	::std::vector < ::std::size_t > vecVertices(numRuns, 0);
	::std::vector < ::std::size_t > vecSolutionVertices(numRuns, 0);
	::std::vector < ::rl::math::Real > vecSolutionLength(numRuns, 0);
	::std::vector < ::rl::math::Real > vecSolutionLengthManipulation(numRuns, 0);
	::std::vector < ::std::vector < ::std::size_t > > vecSolutionManipulationCount(numRuns, ::std::vector < ::std::size_t >(model->vecDamaPrim.size(), 0));


	rl::plan::VectorList path;
	::std::deque< ::std::string > actions;

	/*std::cout << "start: " << (*model->dRrt->start).transpose() << std::endl;
	std::cout << "goal: " << (*model->dRrt->goal).transpose() << std::endl;
	std::cout << "goalDefined: ";
	for(::std::size_t i=0; i<model->dRrt->goalDimDefined->size(); i++)
		std::cout << model->dRrt->goalDimDefined->at(i) << "\t";
	std::cout << std::endl;*/

	for(::std::size_t u=0; u<numRuns; ++u)
	{
		path.clear();
		actions.clear();

		srand(0);
		::std::size_t randSeedNumber = vecSeeds.at(u); //489012115 OR vecSeeds.at(u)
		::boost::mt19937::result_type randSeed = static_cast< ::boost::mt19937::result_type >((double)randSeedNumber);

		if(model->workspaceSampling)
			model->dRrt->setConfig(false, false, false);	// do NOT change this

		model->dRrt->seed(randSeed);
		model->dRrt->resetStatistics();
		model->dRrt->duration = ::std::chrono::duration_cast< ::std::chrono::steady_clock::duration >( ::std::chrono::duration< double >(180.0)); //900.0 //300.0; //1200.0 //boost::lexical_cast< rl::math::Real >(::std::numeric_limits< double >::max());
		// TODO: hierarchical version currently needs this to be redefined ...
		rl::math::Vector startCopy(*(model->dRrt->start));
		model->dRrt->start = &startCopy;
		rl::math::Vector goalCopy(*(model->dRrt->goal));
		model->dRrt->goal = &goalCopy;
		::std::vector < bool > goalDimDefinedCopy(*(model->dRrt->goalDimDefined));
		model->dRrt->goalDimDefined = &goalDimDefinedCopy;
		std::cout << "Start solving nr. " << (u+1) << "/" << numRuns << " with seed " << randSeedNumber << " ... " << std::endl;
		timer.start();
		vecSolved.at(u) = model->dRrt->solveAll(path, actions);
		timer.stop();
		if(vecSolved.at(u))
		{
			::std::string lastAction = "";
			rl::plan::VectorList::iterator i = path.begin();
			rl::plan::VectorList::iterator j = ++path.begin();
			::std::deque< ::std::string >::iterator e = actions.begin();
			for (; i != path.end() && j != path.end() && e != actions.end(); ++i, ++j, ++e)
			{
				::rl::math::Real tempRobotDist = model->cartesianRobotDistance(*i, *j);
				vecSolutionLength.at(u) += tempRobotDist;
				if(*e != ::dama::DamaPrimTransit::getInstance()->getName())
					vecSolutionLengthManipulation.at(u) += tempRobotDist;
				if(lastAction != *e)
				{
					for(::std::size_t p=0; p<vecSolutionManipulationCount.at(u).size(); ++p)
						if(e->substr(0, model->vecDamaPrim.at(p)->getName().size()) == model->vecDamaPrim.at(p)->getName())
							vecSolutionManipulationCount.at(u).at(p) ++;
				}
				lastAction = *e;
			}
		}
		vecTime.at(u) = timer.elapsed();
		vecIterations.at(u) = model->dRrt->getIterationCount();
		vecEdges.at(u) = model->dRrt->getEdgeCount();
		vecVertices.at(u) = model->dRrt->getVertexCount();
		vecSolutionVertices.at(u) = path.size();
		std::cout << "solved: " << vecSolved.at(u) << " \t time: " << vecTime.at(u) << " \t iterations: " << vecIterations.at(u) << " \t edges: " << vecEdges.at(u) << " \t vertices: " << vecVertices.at(u) << " \t vertices (solution): " << vecSolutionVertices.at(u) << " \t length: " << vecSolutionLength.at(u) << " \t length (manipulation only): " << vecSolutionLengthManipulation.at(u) << std::endl;

		// Export statistics to benchmark file
		std::ofstream benchmark;
		benchmark.open("DamaBenchmark.csv", std::ios::app);
#if !QT_KRAMS
		// Current date/time based on current system
		time_t now = time(0);
		// Convert now to tm struct for local timezone
		tm* localtm = localtime(&now);
		benchmark << asctime(localtm) << ",";
#else
		benchmark << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz").toStdString() << ",";
#endif
		benchmark << model->prefixName << ",";
		benchmark << (u+1) << ",";
		benchmark << randSeedNumber << ",";
		benchmark << (vecSolved.at(u) ? "true" : "false") << ",";
		benchmark << vecTime.at(u) << ",";
		benchmark << model->timeIK << ",";
		benchmark << model->dRrt->getTimeSampling() << ",";
		benchmark << model->dRrt->getTimeNNSearch() << ",";
		benchmark << model->dRrt->getTimePropagate() << ",";
		benchmark << model->dRrt->getTimeConnect() << ",";
		benchmark << vecIterations.at(u) << ",";
		benchmark << vecEdges.at(u) << ",";
		benchmark << vecVertices.at(u) << ",";
		benchmark << model->getTotalQueries() << ",";
		benchmark << model->getFreeQueries() << ",";
		benchmark << vecSolutionVertices.at(u) << ",";
		benchmark << vecSolutionLength.at(u) << ",";
		benchmark << vecSolutionLengthManipulation.at(u) << ",";
		for(::std::size_t p=0; p<vecSolutionManipulationCount.at(u).size(); ++p)
			benchmark << vecSolutionManipulationCount.at(u).at(p) << ",";
		benchmark << std::endl;
		benchmark.close();
	}
	
	
	return EXIT_SUCCESS;
}