Exemplo n.º 1
0
void Geometry_UpdateVertexPositions( SGeometry *geometry, uint firstVertex, uint vertexCount, const void *data )
{
	uint 	index;
	GLuint 	vertexArrayObject;
	GLuint 	vertexBuffer;
	uint 	offset;
	uint 	size;

	Prof_Start( PROF_GEOMETRY_UPDATE );

	OVR::GL_CheckErrors( "before Geometry_UpdateVertexPositions" );

	index = geometry->updateIndex % BUFFER_COUNT;

	vertexArrayObject = geometry->vertexArrayObjects[index];
	assert( vertexArrayObject );

	glBindVertexArrayOES_( vertexArrayObject );

	vertexBuffer = geometry->vertexBuffers[index];
	assert( vertexBuffer );

	glBindBuffer( GL_ARRAY_BUFFER, vertexBuffer );

	offset = firstVertex * sizeof( float ) * 3;
	size = vertexCount * sizeof( float ) * 3;

	glBufferSubData( GL_ARRAY_BUFFER, offset, size, data );

	glBindVertexArrayOES_( 0 );

	OVR::GL_CheckErrors( "after Geometry_UpdateVertexPositions" );

	Prof_Stop( PROF_GEOMETRY_UPDATE );
}
Exemplo n.º 2
0
void Geometry_Present( SGeometry *geometry )
{
	Prof_Start( PROF_GEOMETRY_PRESENT );

	assert( geometry );

	geometry->drawIndex = geometry->updateIndex;

	Prof_Stop( PROF_GEOMETRY_PRESENT );
}
Exemplo n.º 3
0
void Geometry_Resize( SGeometry *geometry, uint vertexCount, uint indexCount )
{
	Prof_Start( PROF_GEOMETRY_RESIZE );

	OVR::GL_CheckErrors( "before Geometry_Resize" );

	Geometry_ResizeVertexBuffer( geometry, vertexCount );
	Geometry_ResizeIndexBuffer( geometry, indexCount );
	Geometry_MakeVertexArrayObject( geometry );

	OVR::GL_CheckErrors( "after Geometry_Resize" );

	Prof_Stop( PROF_GEOMETRY_RESIZE );
}
Exemplo n.º 4
0
void
main()
{
    Proc_PID	pid;
    int		i;

    /*
     * Initialize variables specific to a given kernel.  
     * IMPORTANT: Only variable assignments and nothing else can be
     *		  done in this routine.
     */
    Main_InitVars();

    /*
     * Initialize machine dependent info.  MUST BE CALLED HERE!!!.
     */
    Mach_Init();
    Sync_Init();

    /*
     * Initialize the debugger.
     */
    Dbg_Init();

    /*
     * Initialize the system module, particularly the fact that there is an
     * implicit DISABLE_INTR on every processor.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Sys_Init().\n");
    }
    Sys_Init();

    /*
     * Now allow memory to be allocated by the "Vm_BootAlloc" call.  Memory
     * can be allocated by this method until "Vm_Init" is called.  After this
     * then the normal memory allocator must be used.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Vm_BootInit().\n");
    }
    Vm_BootInit();

    /*
     * Initialize all devices.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Dev_Init().\n");
    }
    Dev_Init();

    /*
     *  Initialize the mappings of keys to call dump routines.
     *  Must be after Dev_Init. 
     */
    if (main_DoDumpInit) {
	if (main_PrintInitRoutines) {
	    Mach_MonPrintf("Calling Dump_Init().\n");
	}
	Dump_Init();
    }

    /*
     * Initialize the timer, signal, process, scheduling and synchronization
     * modules' data structures.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Proc_Init().\n");
    }
    Proc_Init();
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Sync_LockStatInit().\n");
    }
    Sync_LockStatInit();
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Timer_Init().\n");
    }
    Timer_Init();
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Sig_Init().\n");
    }
    Sig_Init();
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Sched_Init().\n");
    }
    Sched_Init();

    /*
     * Sys_Printfs are not allowed before this point.
     */  
    main_PanicOK++;
    printf("Sprite kernel: %s\n", SpriteVersion());

    /*
     * Set up bins for the memory allocator.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Fs_Bin\n");
    }
    Fs_Bin();
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Net_Bin\n");
    }
    Net_Bin();

    /*
     * Initialize virtual memory.  After this point must use the normal
     * memory allocator to allocate memory.  If you use Vm_BootAlloc then
     * will get a panic into the debugger.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Vm_Init\n");
    }
    Vm_Init();

    /*
     * malloc can be called from this point on.
     */

    /*
     * Initialize the main process. Must be called before any new 
     * processes are created.
     * Dependencies: Proc_InitTable, Sched_Init, Vm_Init, Mem_Init
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Proc_InitMainProc\n");
    }
    Proc_InitMainProc();

    /*
     * Initialize the network and the routes.  It would be nice if we
     * could call Net_Init earlier so that we can use the debugger earlier
     * but we must call Vm_Init first.  VM could be changed so that we
     * could move the call earlier however.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Net_Init\n");
    }
    Net_Init();
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Net_RouteInit\n");
    }
    Net_RouteInit();

    /*
     * Enable server process manager.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Proc_ServerInit\n");
    }
    Proc_ServerInit();

    /*
     * Initialize the recovery module.  Do before Rpc and after Vm_Init.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Recov_Init\n");
    }
    Recov_Init();

    /*
     * Initialize the data structures for the Rpc system.  This uses
     * Vm_RawAlloc to so it must be called after Vm_Init.
     * Dependencies: Timer_Init, Vm_Init, Net_Init, Recov_Init
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Rpc_Init\n");
    }
    Rpc_Init();

    /*
     * Configure devices that may or may not exist.  This needs to be
     * done after Proc_InitMainProc because the initialization routines
     * use SetJump which uses the proc table entry for the main process.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Dev_Config\n");
    }
    Dev_Config();

    /*
     * Initialize profiling after the timer and vm stuff is set up.
     * Dependencies: Timer_Init, Vm_Init
     */
    if (main_DoProf) {
	Prof_Init();
    }
    /*
     *  Allow interrupts from now on.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Enabling interrupts\n");
    }
    ENABLE_INTR();

    if (main_Debug) {
	DBG_CALL;
    }

    /*
     * Sleep for a few seconds to calibrate the idle time ticks.
     */
    Sched_TimeTicks();

    /*
     * Start profiling, if desired.
     */
    if (main_DoProf) {
        (void) Prof_Start();
    }

    /*
     * Do an initial RPC to get a boot timestamp.  This allows
     * servers to detect when we crash and reboot.  This will set the
     * system clock too, although rdate is usually done from user level later.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Call Rpc_Start\n");
    }
    Rpc_Start();

    /*
     * Initialize the file system. 
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Call Fs_Init\n");
    }
    Fs_Init();

    /*
     * Before starting up any more processes get a current directory
     * for the main process.  Subsequent new procs will inherit it.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Call Fs_ProcInit\n");
    }
    Fs_ProcInit();
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Bunch of call funcs\n");
    }
    /*
     * Start the clock daemon and the routine that opens up the swap directory.
     */
    Proc_CallFunc(Vm_Clock, (ClientData) NIL, 0);
    Proc_CallFunc(Vm_OpenSwapDirectory, (ClientData) NIL, 0);

    /*
     * Start the process that synchronizes the filesystem caches
     * with the data kept on disk.
     */
    Proc_CallFunc(Fsutil_SyncProc, (ClientData) NIL, 0);

    /*
     * Create a few RPC server processes and the Rpc_Daemon process which
     * will create more server processes if needed.
     */
    if (main_NumRpcServers > 0) {
	for (i=0 ; i<main_NumRpcServers ; i++) {
	    (void) Rpc_CreateServer((int *) &pid);
	}
    }
    (void) Proc_NewProc((Address) Rpc_Daemon, PROC_KERNEL, FALSE, &pid,
	"Rpc_Daemon", FALSE);
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Creating Proc server procs\n");
    }

    /*
     * Create processes  to execute functions.
     */
    (void) Proc_ServerProcCreate(FSCACHE_MAX_CLEANER_PROCS + 
					VM_MAX_PAGE_OUT_PROCS);

    /*
     * Create a recovery process to monitor other hosts.  Can't use
     * Proc_CallFunc's to do this because they can be used up waiting
     * for page faults against down servers.  (Alternatively the VM
     * code could be fixed up to retry page faults later instead of
     * letting the Proc_ServerProc wait for recovery.)
     */
    (void) Proc_NewProc((Address) Recov_Proc, PROC_KERNEL, FALSE, &pid,
			"Recov_Proc", FALSE);

    /*
     * Set up process migration recovery management.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Proc_MigInit\n");
    }
    Proc_MigInit();

    /*
     * Call the routine to start test kernel processes.
     */

    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Calling Main_HookRoutine\n");
    }
    Main_HookRoutine();

    /*
     * Print out the amount of memory used.
     */
    printf("MEMORY %d bytes allocated for kernel\n", 
		vmMemEnd - mach_KernStart);

    /*
     * Start up the first user process.
     */
    if (main_PrintInitRoutines) {
	Mach_MonPrintf("Creating Init\n");
    }
    (void) Proc_NewProc((Address) Init, PROC_KERNEL, FALSE, &pid,
	                "Init", FALSE);

    (void) Sync_WaitTime(time_OneYear);
    printf("Main exiting\n");
    Proc_Exit(0);
}
Exemplo n.º 5
0
void Entity_DrawEntity( SEntity *entity, const OVR::Matrix4f &view )
{
    STexture 	*texture;
    SGeometry	*geometry;
    uint 		geometryIndex;
    uint 		textureIndex;
    GLuint 		texId;
    float 		uScale;
    float 		vScale;
    GLuint 		vertexArrayObject;
    int 		triCount;
    int 		indexOffset;
    int 		batchTriCount;
    int 		triCountLeft;

    Prof_Start( PROF_DRAW_ENTITY );

    assert( entity );

    OVR::GL_CheckErrors( "before Entity_DrawEntity" );

    geometry = Registry_GetGeometry( entity->geometryRef );
    assert( geometry );

    geometryIndex = geometry->drawIndex % BUFFER_COUNT;

    vertexArrayObject = geometry->vertexArrayObjects[geometryIndex];
    if ( !vertexArrayObject )
    {
        Prof_Stop( PROF_DRAW_ENTITY );
        return;
    }

    glUseProgram( s_ent.shader.program );

    glUniformMatrix4fv( s_ent.shader.uMvp, 1, GL_FALSE, view.Transposed().M[0] );

    glBindVertexArrayOES_( vertexArrayObject );

    glActiveTexture( GL_TEXTURE0 );

    if ( entity->textureRef != S_NULL_REF )
    {
        texture = Registry_GetTexture( entity->textureRef );
        assert( texture );

        textureIndex = texture->drawIndex % BUFFER_COUNT;
        texId = texture->texId[textureIndex];

        glBindTexture( GL_TEXTURE_2D, texId );

        if ( texId )
        {
            assert( texture->texWidth[textureIndex] );
            assert( texture->texHeight[textureIndex] );

            uScale = (float)texture->width / texture->texWidth[textureIndex];
            vScale = (float)texture->height / texture->texHeight[textureIndex];

            glUniform4f( s_ent.shader.uColor, uScale, vScale, 1.0f, 1.0f );
        }
        else
        {
            glUniform4f( s_ent.shader.uColor, 1.0f, 1.0f, 1.0f, 1.0f );
        }

        if ( texture->format == SxTextureFormat_R8G8B8A8 ||
                texture->format == SxTextureFormat_R8G8B8A8_SRGB )
        {
            glEnable( GL_BLEND );
            glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        }
    }
    else
    {
        glBindTexture( GL_TEXTURE_2D, 0 );
        glUniform4f( s_ent.shader.uColor, 1.0f, 1.0f, 1.0f, 1.0f );
        glDisable( GL_BLEND );
    }

    indexOffset = 0;
    triCount = geometry->indexCounts[geometryIndex] / 3;

    triCountLeft = triCount;

    while ( triCountLeft )
    {
#if USE_SPLIT_DRAW
        batchTriCount = S_Min( triCountLeft, S_Max( 1, triCount / 10 ) );
#else // #if USE_SPLIT_DRAW
        batchTriCount = triCount;
#endif // #else // #if USE_SPLIT_DRAW

        glDrawElements( GL_TRIANGLES, batchTriCount * 3, GL_UNSIGNED_SHORT, (void *)indexOffset );

        indexOffset += batchTriCount * sizeof( ushort ) * 3;
        triCountLeft -= batchTriCount;
    }

    glBindVertexArrayOES_( 0 );

    glBindTexture( GL_TEXTURE_2D, 0 );

    glDisable( GL_BLEND );

    OVR::GL_CheckErrors( "after Entity_DrawEntity" );

    Prof_Stop( PROF_DRAW_ENTITY );
}