Пример #1
0
bool CScreensaverPlasma::Start()
{
  int speed = kodi::GetSettingInt("speed");
  m_zoom = kodi::GetSettingInt("zoom");
  m_focus = float(kodi::GetSettingInt("focus")) / 50.0f + 0.3f;
  m_maxdiff = 0.004f * float(speed);
  m_resolution = kodi::GetSettingInt("resolution");
  m_aspectRatio = float(Width()) / float(Height());

  std::string fraqShader = kodi::GetAddonPath("resources/shaders/frag.glsl");
  std::string vertShader = kodi::GetAddonPath("resources/shaders/vert.glsl");
  if (!LoadShaderFiles(vertShader, fraqShader) || !CompileAndLink())
    return false;

  glGenBuffers(1, &m_vertexVBO);

  // Initialize pseudorandom number generator
  srand((unsigned)time(nullptr));

  // Initialize constants
  for (int i = 0; i < NUMCONSTS; i++)
  {
    m_ct[i] = rsRandf(PIx2);
    m_cv[i] = rsRandf(0.005f * float(speed)) + 0.0001f;
  }

  m_projMat = glm::mat4(1.0f);
  m_modelMat = glm::mat4(1.0f);

  SetPlasmaSize();

  return true;
}
Пример #2
0
bool CScreensaverCyclone::Start()
{
  int i, j;

  std::string fraqShader = kodi::GetAddonPath("resources/shaders/frag.glsl");
  std::string vertShader = kodi::GetAddonPath("resources/shaders/vert.glsl");
  if (!LoadShaderFiles(vertShader, fraqShader) || !CompileAndLink())
    return false;

  gCycloneSettings.Load();

  srand((unsigned)time(nullptr));

  // Window initialization
  glViewport(X(), Y(), Width(), Height());

  glEnable(GL_DEPTH_TEST);
  glFrontFace(GL_CCW);
  glEnable(GL_CULL_FACE);
  glClearColor(0.0, 0.0, 0.0, 1.0);

  m_modelMat = glm::mat4(1.0f);
  m_projMat = glm::perspective(glm::radians(80.0f), (GLfloat)Height() / (GLfloat)Width(), 50.0f, 3000.0f);
  if (!rsRandi(500))  // Easter egg view
  {
    m_projMat = glm::rotate(m_projMat, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
    m_projMat = glm::translate(m_projMat, glm::vec3(0.0f, -(WIDTH * 2), 0.0f));
  }
  else  // Normal view
    m_projMat = glm::translate(m_projMat, glm::vec3(0.0f, 0.0f, -(WIDTH * 2)));

  Sphere(float(gCycloneSettings.dSize) / 4.0f, 3, 2);
  m_lightingEnabled = 1;

  // Initialize cyclones and their particles
  for (i = 0; i < 13; i++)
    m_fact[i] = float(factorial(i));
  m_cyclones = new CCyclone*[gCycloneSettings.dCyclones];
  m_particles = new CParticle*[gCycloneSettings.dParticles * gCycloneSettings.dCyclones];
  for (i = 0; i < gCycloneSettings.dCyclones; i++)
  {
    m_cyclones[i] = new CCyclone;
    for (j=i*gCycloneSettings.dParticles; j<((i+1)*gCycloneSettings.dParticles); j++)
      m_particles[j] = new CParticle(m_cyclones[i]);
  }

  glGenBuffers(1, &m_vertexVBO);
  glBindBuffer(GL_ARRAY_BUFFER, m_vertexVBO);

  m_lastTime = kodi::time::GetTimeSec<double>();
  m_startOK = true;
  return true;
}
Пример #3
0
bool GLSLShader::Create()
{
    if (isCreateOK() == false)
    {
        bool result = false;
        result = CompileAndLink();
        if (isInitDeepCopyShaderSourceStr() == true)
        {
            if (result == true)
            {
                DiscardShaderSource();
            }
        }
        m_bIsCreateOK = result;
    }
    return isCreateOK();
}
Пример #4
0
bool CScreensaverHufoTunnel::Start()
{
  gSettings.Load();

  std::string fraqShader = kodi::GetAddonPath("resources/shaders/frag.glsl");
  std::string vertShader = kodi::GetAddonPath("resources/shaders/vert.glsl");
  if (!LoadShaderFiles(vertShader, fraqShader) || !CompileAndLink())
    return false;

  // Reset the matrix to something we know.
  float x = (float)Width() / (float)Height();  // Correct the viewing ratio of the window in the X axis.

  // Window initialization
  glViewport(X(), Y(), Width(), Height());

  if (x > XSTD)
    m_modelProjMat = glm::ortho(-x, x, -1.0f, 1.0f);  // Reset to a 2D screen space.
  else
    m_modelProjMat = glm::ortho(-XSTD, XSTD, -XSTD / x, XSTD / x);  // Reset to a 2D screen space.

  if (!gSettings.dWireframe)
  {
    if (gSettings.dTexture)
    {
      unsigned char *l_tex;
      if (gSettings.dTexture == 1)
      {
        LOAD_TEXTURE (l_tex, swirlmap, swirlmap_compressedsize, swirlmap_size)
        gli::texture Texture(gli::TARGET_2D, gli::FORMAT_RGB8_UNORM_PACK8, gli::texture::extent_type(128, 128, 1), 1, 1, 1);
        std::memcpy(Texture.data(), l_tex, Texture.size());
        m_texture = kodi::gui::gl::Load(Texture);
      }
      else
      {
        LOAD_TEXTURE (l_tex, marblemap, marblemap_compressedsize, marblemap_size)
        gli::texture Texture(gli::TARGET_2D, gli::FORMAT_RGB8_UNORM_PACK8, gli::texture::extent_type(256, 256, 1), 1, 1, 1);
        std::memcpy(Texture.data(), l_tex, Texture.size());
        m_texture = kodi::gui::gl::Load(Texture);
      }
      FREE_TEXTURE (l_tex)
    }
    else
    {
Пример #5
0
int _tmain(int argc, _TCHAR* argv[])
#endif
{
	int32_t iRet = RETVALUE_SUCCESS;
	
#ifdef __APPLE__
	_TCHAR** argv = convertArguments( argc, argvOriginal );
#endif
	

	//Initialize argument handler
	ArgumentHandler argumenthandler( ARRAYSIZE( options ), options );

	//Initialize a parser interface
	cri::CParser* parser = new cri::CParser;

	//Initialize error handler
	cri::CErrorPool *error = new cri::CErrorPool;
	error->setErrorTable( cri::g_ErrorTable_English, sizeof( cri::g_ErrorTable_English ) 
													 / sizeof( cri::g_ErrorTable_English[ 0 ] ) );
	//parse args
	argumenthandler.setErrorHandler( error );
	int32_t iArgOffset = argumenthandler.parse( argc, argv );

	//Set error output configuration
	error->suppressErrorLine( g_bsuppressErrorLine );

	if( !g_bSuppressBanner )
	{
		CRISCRIPT_VERSIONS ver = parser->getVersions();
		cout << "CriScript compiler and linker ver.";
		cout << ver.major << ".";
		cout << ver.minor << ".";
		cout << ver.revision << ".";
		cout << ver.build << "\n";
		cout << "CRI Middleware inc. 2008" << endl;
	}
	
	if( argc <= iArgOffset )
	{
		if( error->hasError() )
			error->dumpError();
		delete( error );

		//Output help info
		cout << endl;
		cout << "cscl.exe [options] source" << endl;
		cout << "Option switch:" << endl;
		for( int32_t i = 0; i < ARRAYSIZE( options ); ++ i )
		{
			wcout << options[ i ].strOption << " : " << options[ i ].strDescription << endl; 
		}

		delete( parser );

#ifdef __APPLE__
		deleteArguments( argc, argv );	
#endif
        return RETVALUE_SUCCESS;
	}


	//Open the target file
#ifdef __APPLE__
	ifstream fin ( argvOriginal[ iArgOffset ], ios::in | ios::binary );
#else
	ifstream fin ( argv[ iArgOffset ], ios::in | ios::binary );
#endif
    if( !fin )
	{
		wstring strArg1( argv[ iArgOffset ] );
		wstring strNull( L"" );
		error->report( ERROR_FILENOTFOUND, 0, 0, strArg1,
												strNull,
												strArg1 );
		error->dumpError();
		delete( error );
		delete( parser );

#ifdef __APPLE__
		deleteArguments( argc, argv );	
#endif
        return RETVALUE_TOOL_ERROR;
    }

	//Check file endianness;
	//Note that wchar_t is 4 byte in OSX.
	uint16_t c;
	fin.read( (char*)&c, sizeof( uint16_t ) );

	bool bSourceEndiannness = false;
	switch( c )
	{
	case 0xfeff:
		//Little endian
		break;
	case 0xfffe:
		//Big endian
		bSourceEndiannness = true;
		break;
	default:
		{
		wstring strArg1( argv[ iArgOffset ] );
		wstring strNull( L"" );
		error->report( ERROR_INVALIDFILEENCODING, 0, 0, strArg1,
												strNull,
												strArg1 );
		error->dumpError();
		delete( error );
        
		}
			delete( parser );
#ifdef __APPLE__
			deleteArguments( argc, argv );	
#endif
			return RETVALUE_TOOL_ERROR;
	}

	//Initialize the lexer
	cri::CFileStreamLexer *lex = new cri::CFileStreamLexer;
	
	//test	
	lex->init();
	
	lex->setEndianness( bSourceEndiannness );

	//Initialize the codegen
	cri::CCilCodeGen *codegen = new cri::CCilCodeGen;

	//Initialize the parser engine
	parser->init( lex, codegen, error );
	
	//Set filestream to the lexer
	lex->setStream( &fin, &wstring( argv[ iArgOffset ] ) );

#ifdef DEBUG_PARSING
	//debug
	cri::yydebug = 1;
#endif
	if( !g_bPerformLinkage )
	{
		iRet = Compile( parser, fin );
		g_bPerformExecution = false;
	}
	else
	{
		iRet = CompileAndLink( parser, fin );
	}

	if( error->hasError() )
	{
		error->dumpError();
		cout << "Compile failed." << endl;
		iRet = RETVALUE_COMPILE_ERROR;
	}
	else
	{
		if( error->hasInformation() )
		{
			iRet = RETVALUE_COMPILE_WARNING;
			cout << "Compile succeeded but with some warnings" << endl;
		}
		else
		{
			iRet = RETVALUE_SUCCESS;
			cout << "Compile succeeded." << endl;
		}
		
		error->dumpError();
	}

	if( g_bPerformExecution && iRet != RETVALUE_COMPILE_ERROR )
	{
		cri::CCilVm *vm = new cri::CCilVm;
		cri::CCilDebugger *debugger = new cri::CCilDebugger;

		vm->setILPool( &*parser->getILPool().begin(), parser->getILPool().size() );
		//Note:
		//setSymbolInformation need to be invoked before SetMetaData() for now
		vm->setSymbolInformation( parser->getSymbolInformation() );
		vm->setMetaData( parser->getMetaData() );

		cout << "-----------------------------------------------------------------\n";
		cri::CCilDisasm * disasm = new cri::CCilDisasm;
		disasm->setILStream( &*parser->getILPool().begin(), parser->getILPool().size() );
		disasm->setSymbolInformation( parser->getSymbolInformation() );
		disasm->setMetaData( parser->getMetaData() );
		disasm->dumpDisasm();
		cout << "-----------------------------------------------------------------\n";

		iRet = vm->execute();
		iRet = vm->getExitCode(); 

		debugger->attach( vm );
		debugger->setSymbolInformation( parser->getSymbolInformation() );
		debugger->setMetaData( parser->getMetaData() );
		
		debugger->debugDumpStats();
		debugger->debugDumpStaticFields( 0 );	//dump all fields
		debugger->debugDumpObjects( 0 );		//dump all objects

		delete( disasm );
		delete( debugger );
		delete( vm );
	}

	delete( lex );
	delete( error );
	delete( codegen );
	delete( parser );
	
#ifdef __APPLE__
	deleteArguments( argc, argv );	
#endif
		
	return iRet;
}