Example #1
0
SCProg::SCProg(const std::string &src_file)
{
    #ifndef __APPLE__
     AbstractBuffer * src = new FileBuffer(std::string("./shaders/")+src_file);

    d_ready  = false;
    d_program = glCreateProgram();
    d_shader  = glCreateShader (GL_COMPUTE_SHADER);
    const char * source = (const char *) src->buffer();
    int len = strlen(source);

    glShaderSource (d_shader,1 , &source, &len);

    delete src; // bad 

    glCompileShader(d_shader);

    GLint compileStatus;
    GLint compileLogsz;
    glGetShaderiv ( d_shader, GL_COMPILE_STATUS, &compileStatus );
    glGetShaderiv ( d_shader, GL_INFO_LOG_LENGTH, &compileLogsz );
    char *errorLog;
    if ( compileStatus == 0 )
    {
        GLint logRecived;
        errorLog = (char *)calloc(compileLogsz,sizeof(char));
        glGetShaderInfoLog(d_shader,compileLogsz,&logRecived, errorLog);
        std::string e_log(errorLog);
        free(errorLog);
        LOGE("Compute shader build failed:\n",e_log.c_str());
        /*TODO proper cleanup*/
        return;
    }

    glAttachShader(d_program, d_shader);
    GLint linkStatus;
    GLint linkLogsz;
    glLinkProgram (d_program);
    glGetProgramiv ( d_program, GL_LINK_STATUS, &linkStatus );
    glGetProgramiv ( d_program, GL_INFO_LOG_LENGTH, &linkLogsz);


    if ( linkStatus == 0 )
    {
        GLint logRecived;
        errorLog = (char *)calloc(linkLogsz,sizeof(char));
        glGetProgramInfoLog(d_program,linkLogsz,&logRecived, errorLog);
        std::string e_log(errorLog);
        free(errorLog);
        LOGE("Compute shader link failed: %s\n",e_log.c_str());
        return;
    }
    #endif
    d_ready = true;
}
Example #2
0
uint32 TargetManager::TimeToLock(ShipRef ship, SystemEntity *target) const {

    EvilNumber scanRes = ship->GetAttribute(AttrScanResolution);
    EvilNumber sigRad(500);

	if( target->Item().get() != NULL )
		if( target->Item()->HasAttribute(AttrSignatureRadius) )
			sigRad = target->Item()->GetAttribute(AttrSignatureRadius);

    EvilNumber time = ( EvilNumber(40000) / ( scanRes ) ) /( EvilNumber::pow( e_log( sigRad + e_sqrt( sigRad * sigRad + 1) ), 2) );

	return static_cast<uint32>(time.get_float() * 1000); // Timer uses ms instead of seconds
}