Exemple #1
0
void
TexUnpackSurface::TexOrSubImage(bool isSubImage, bool needsRespec, const char* funcName,
                                WebGLTexture* tex, TexImageTarget target, GLint level,
                                const webgl::DriverUnpackInfo* dui, GLint xOffset,
                                GLint yOffset, GLint zOffset, GLenum* const out_glError)
{
    *out_glError = 0;

    WebGLContext* webgl = tex->mContext;

    // MakeCurrent is a big mess in here, because mapping (and presumably unmapping) on
    // OSX can lose our MakeCurrent. Therefore it's easiest to MakeCurrent just before we
    // call into GL, instead of trying to keep MakeCurrent-ed.

    RefPtr<gfx::DataSourceSurface> dataSurf = mSurf->GetDataSurface();

    if (!dataSurf) {
        // Since GetDataSurface didn't return error code, assume system
        // is out of memory
        *out_glError = LOCAL_GL_OUT_OF_MEMORY;
        return;
    }

    GLenum error;
    if (UploadDataSurface(isSubImage, webgl, target, level, dui, xOffset, yOffset,
                          zOffset, mWidth, mHeight, dataSurf, mIsAlphaPremult, &error))
    {
        return;
    }
    if (error == LOCAL_GL_OUT_OF_MEMORY) {
        *out_glError = LOCAL_GL_OUT_OF_MEMORY;
        return;
    }

    // CPU conversion. (++numCopies)

    UniqueBuffer convertedBuffer;
    uint8_t convertedAlignment;
    bool outOfMemory;
    if (!ConvertSurface(webgl, dui, dataSurf, mIsAlphaPremult, &convertedBuffer,
                        &convertedAlignment, &outOfMemory))
    {
        if (outOfMemory) {
            *out_glError = LOCAL_GL_OUT_OF_MEMORY;
        } else {
            NS_ERROR("Failed to convert surface.");
            *out_glError = LOCAL_GL_OUT_OF_MEMORY;
        }
        return;
    }

    MOZ_ALWAYS_TRUE( webgl->gl->MakeCurrent() );
    ScopedUnpackReset scopedReset(webgl);
    webgl->gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, convertedAlignment);

    error = DoTexOrSubImage(isSubImage, webgl->gl, target.get(), level, dui, xOffset,
                            yOffset, zOffset, mWidth, mHeight, mDepth,
                            convertedBuffer.get());
    *out_glError = error;
}
Exemple #2
0
static void ConvertModel( FILE *f, bspModel_t *model, int modelNum, vec3_t origin )
{
	int					i, s;
	bspDrawSurface_t	*ds;
	
	
	/* go through each drawsurf in the model */
	for( i = 0; i < model->numBSPSurfaces; i++ )
	{
		s = i + model->firstBSPSurface;
		ds = &bspDrawSurfaces[ s ];
		ConvertSurface( f, model, modelNum, ds, s, origin );
	}
}
Exemple #3
0
int WriteASEFile(char *filename)
{
	int             i, j, s, modelNum;
	FILE           *f;
	dshader_t      *shader;
	dmodel_t       *dm;
	drawSurface_t  *ds;
	entity_t       *e;
	vec3_t          origin;
	const char     *key;
	char            name[1024], base[1024];

	Sys_Printf("writing %s\n", filename);
	f = fopen(filename, "wb");
	if(!f)
		Error("Can't write %s\b", filename);

	// print header
	fprintf(f, "*3DSMAX_ASCIIEXPORT\t200\r\n");
	fprintf(f, "*COMMENT\t\"Generated by XMap (XreaL) -bsp2ase\"\r\n");
	fprintf(f, "*SCENE\t{\r\n");
	fprintf(f, "\t*SCENE_FILENAME\t\"%s\"\r\n", base);
	fprintf(f, "\t*SCENE_FIRSTFRAME\t0\r\n");
	fprintf(f, "\t*SCENE_LASTFRAME\t100\r\n");
	fprintf(f, "\t*SCENE_FRAMESPEED\t30\r\n");
	fprintf(f, "\t*SCENE_TICKSPERFRAME\t160\r\n");
	fprintf(f, "\t*SCENE_BACKGROUND_STATIC\t0.0000\t0.0000\t0.0000\r\n");
	fprintf(f, "\t*SCENE_AMBIENT_STATIC\t0.0000\t0.0000\t0.0000\r\n");
	fprintf(f, "}\r\n");

	// print materials
	fprintf(f, "*MATERIAL_LIST\t{\r\n");
	fprintf(f, "\t*MATERIAL_COUNT\t%d\r\n", numShaders);
	for(i = 0; i < numShaders; i++)
	{
		shader = &dshaders[i];
		ConvertShader(f, shader, i);
	}
	fprintf(f, "}\r\n");

	// walk entity list
	for(i = 0; i < numEntities; i++)
	{
		// get entity and model
		e = &entities[i];
		if(i == 0)
		{
			modelNum = 0;
		}
		else
		{
			key = ValueForKey(e, "model");
			if(key[0] != '*')
			{
				continue;
			}
			modelNum = atoi(key + 1);
		}
		dm = &dmodels[modelNum];

		// get entity origin
		key = ValueForKey(e, "origin");
		if(key[0] == '\0')
			VectorClear(origin);
		else
			GetVectorForKey(e, "origin", origin);

		// convert model
		for(j = 0; j < dm->numSurfaces; j++)
		{
			s = j + dm->firstSurface;
			ds = &drawSurfaces[s];

			ConvertSurface(f, dm, modelNum, ds, s, origin);
		}
	}

	// close the file
	fclose(f);

	// return to sender
	return 0;
}
Exemple #4
0
void Initialize(bool* Continue, bool* Error)
{
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
	{
		*Continue = false;  *Error = true;
		printf("SDL initialisation failed: %s\n", SDL_GetError());
		SDL_ClearError();
		return;
	}
	else
		printf("SDL initialisation succeeded\n");

	Screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE |
#ifdef SDL_TRIPLEBUF
		SDL_TRIPLEBUF
#else
		SDL_DOUBLEBUF
#endif
		);

	if (Screen == NULL)
	{
		*Continue = false;  *Error = true;
		printf("SDL_SetVideoMode failed: %s\n", SDL_GetError());
		SDL_ClearError();
		return;
	}
	else
		printf("SDL_SetVideoMode succeeded\n");

	SDL_ShowCursor(0);

	uint32_t i;
	for (i = 0; i < BG_LAYER_COUNT; i++)
	{
		BackgroundImages[i] = IMG_Load(BackgroundImageNames[i]);
		if (!CheckImage(Continue, Error, BackgroundImages[i], BackgroundImageNames[i]))
			return;
		if ((BackgroundImages[i] = ConvertSurface(Continue, Error, BackgroundImages[i], BackgroundImageNames[i])) == NULL)
			return;
	}
	CharacterFrames = IMG_Load("Bee.png");
	if (!CheckImage(Continue, Error, CharacterFrames, "Bee.png"))
		return;
	if ((CharacterFrames = ConvertSurface(Continue, Error, CharacterFrames, "Bee.png")) == NULL)
		return;
	CollisionImage = IMG_Load("Crash.png");
	if (!CheckImage(Continue, Error, CollisionImage, "Crash.png"))
		return;
	if ((CollisionImage = ConvertSurface(Continue, Error, CollisionImage, "Crash.png")) == NULL)
		return;
	ColumnImage = IMG_Load("Bamboo.png");
	if (!CheckImage(Continue, Error, ColumnImage, "Bamboo.png"))
		return;
	if ((ColumnImage = ConvertSurface(Continue, Error, ColumnImage, "Bamboo.png")) == NULL)
		return;

	InitializePlatform();

	// Title screen. (-> title.c)
	ToTitleScreen();
}
Exemple #5
0
int OpticMake( SYSTEM *system, int nsurf )
    {
    int s, n ;
    OPTIC *optic ;
    FUNC *func ;

    aperture_set = 0 ;
    origin_set = 0 ;
    failed = 0 ;

    if( system->optic )
	OpticFree( system->optic, system->nsurf ) ;
    system->optic = OpticAllocate( nsurf ) ;
    system->nsurf = nsurf ;

    SystemSetNumber( "MatTemperature", MatTemperature ) ;	// kludge warning
    MatPush( String( "Gas/AIR" ), Label( "MatTemperature" ), 0 ) ;
							/* just in case */

    func = OpticForward( system->input ) ;
    for( Surface = 0 ; func ; Surface++ )
	{
	optic = &( system->optic[Surface] ) ;
	if( Surface >= nsurf )
	    {
	    IOerror( OpticBomb, "OpticMake",
		"surface count exceeded, Surface = %d  nsurf = %d",
		Surface, nsurf ) ;
	    failed = 1 ;
	    }
	func = ConvertTransform( func, optic->terms + TERM_XFORM ) ;
	func = ConvertSurface( func, optic ) ;
	}
    if( Surface != nsurf )
	{
	IOerror( OpticBomb, "OpticMake",
	    "surface count not met, Surface = %d  nsurf = %d",
	    Surface, nsurf ) ;
	failed = 1 ;
	}

    MatClear() ;
/*  OpticPositions( system ) ;		# now done when needed */

    for( s = 0 ; s < nsurf ; s++ )
	{
	optic = &( system->optic[s] ) ;
	optic->fixed = 1 ;
	for( n = 0 ; n < NTERMS ; n++ )
	    {
	    ExprSimplify( &optic->terms[n].E, 1 ) ;

	    if( (n < TERM_COORD) && optic->terms[n].E
	    && !ExprIsNumber( optic->terms[n].E )
	    && !ExprIsString( optic->terms[n].E ) )
		optic->fixed = 0 ;
	    }
	optic->axial_xform = XformIsAxial( optic->terms + TERM_XFORM ) ;
	if( optic->surface & SURFACE_TRIAXIAL )
	    optic->axial_surface = 0 ;
	else
	    optic->axial_surface = 1 ;

	if( !optic->reverse )
	    {
	    int t ;
	    IOerror( IO_ERR, "OpticMake", "surface has no shape given" ) ;
	    failed = 1 ;
	    IOerrorPrint( "    label: " ) ;
	    ExprIOerror( optic->terms[ TERM_LABEL ].E ) ;
	    IOerrorPrint( "\nSurface #%d\n", Surface ) ;

	    for( t = s - 1 ; t >= 0 ; t-- )
		{
		if( system->optic[t].terms[ TERM_LABEL ].E )
		    break ;
		}
	    IOerrorPrint( "Previous surface with label is: " ) ;
	    if( t >= 0 )
		ExprIOerror( system->optic[t].terms[ TERM_LABEL ].E ) ;
	    else
		IOerrorPrint( "(none)" ) ;
	    IOerrorPrint( "\n" ) ;

	    for( t = s + 1 ; t < nsurf ; t++ )
		{
		if( system->optic[t].terms[ TERM_LABEL ].E )
		    break ;
		}
	    IOerrorPrint( "Following surface with label is: " ) ;
	    if( t < nsurf )
		ExprIOerror( system->optic[t].terms[ TERM_LABEL ].E ) ;
	    else
		IOerrorPrint( "(none)" ) ;
	    IOerrorPrint( "\n" ) ;
	    }

		/* KLUDGE for mirrors, since they don't reverse! */

	if( (optic->reverse == -1) && (optic->function & FUNCTION_MIRROR) )
	    optic->reverse = 1 ;
	}

    return failed ;
    }