Exemplo n.º 1
0
CachedTextureInfo TextureCache::GetOrLoadImageTexture(uint32 image)
{
    image &= 0x7FFFF;
    auto kvp = _imageTextureMap.find(image);
    if (kvp != _imageTextureMap.end())
    {
        return kvp->second;
    }

    auto cacheInfo = LoadImageTexture(image);
    _imageTextureMap[image] = cacheInfo;

    return cacheInfo;
}
Exemplo n.º 2
0
BasicTextureInfo TextureCache::GetOrLoadImageTexture(uint32 image)
{
    image &= 0x7FFFF;

    uint32 index = _indexMap[image];
    if (index != UNUSED_INDEX)
    {
        const auto& info = _textureCache[index];
        return
        {
            info.index,
            info.normalizedBounds,
        };
    }

    index = (uint32)_textureCache.size();

    AtlasTextureInfo info = LoadImageTexture(image);

    _textureCache.push_back(info);
    _indexMap[image] = index;

    return info;
}
Exemplo n.º 3
0
int Project::Initialize()
{
/* to be filled in by the app if it sets camera params */

	GzCamera	camera;  
	int		    xRes, yRes, dispClass;	/* display parameters */ 

	GzToken		nameListShader[9]; 	/* shader attribute names */
	GzPointer   valueListShader[9];		/* shader attribute pointers */
	GzToken     nameListLights[10];		/* light info */
	GzPointer   valueListLights[10];
	int			shaderType, interpStyle;
	float		specpower;
	int		    status; 
 
	status = 0; 

	/* 
	 * Allocate memory for user input
	 */
	m_pUserInput = new GzInput;

	/* 
	 * initialize the display and the renderer 
	 */ 

	m_nWidth = 512;		// frame buffer and display width
	m_nHeight = 512;    // frame buffer and display height

	status |= GzNewFrameBuffer(&m_pFrameBuffer, m_nWidth, m_nHeight);
	status |= GzNewFrameBuffer(&m_p3DImageInRGB, m_nWidth, m_nHeight);
	status |= GzNewFrameBuffer(&m_pDepthMap, m_nWidth, m_nHeight);
	status |= GzNewFrameBuffer(&m_pDepthMapBlurred, m_nWidth, m_nHeight);
	status |= GzNewFrameBuffer(&m_pEdgeMap, m_nWidth, m_nHeight);
	status |= GzNewFrameBuffer(&m_p3DImageBlurred, m_nWidth, m_nHeight);
	status |= GzNewFrameBuffer(&m_pTexture, m_nWidth, m_nHeight);
	status |= GzNewFrameBuffer(&m_pProceduralTexture, m_nWidth, m_nHeight);
	status |= GzNewFrameBuffer(&m_pImageTexture, m_nWidth, m_nHeight);
	status |= GzNewFrameBuffer(&m_pTextureImageMult, m_nWidth, m_nHeight);
	status |= GzNewFrameBuffer(&m_pFinalImage, m_nWidth, m_nHeight);
	status |= GzNewFrameBuffer(&m_pGradient, m_nWidth, m_nHeight);
	status |= GzNewFloatArray(&m_pFF1_x, m_nWidth, m_nHeight);
	status |= GzNewFloatArray(&m_pFF1_y, m_nWidth, m_nHeight);
	status |= GzNewFloatArray(&m_pFF_x, m_nWidth, m_nHeight);
	status |= GzNewFloatArray(&m_pFF_y, m_nWidth, m_nHeight);

	status |= GzNewDisplay(&m_pDisplay, GZ_RGBAZ_DISPLAY, m_nWidth, m_nHeight);

	status |= GzGetDisplayParams(m_pDisplay, &xRes, &yRes, &dispClass); 
	 
	status |= GzInitDisplay(m_pDisplay); 
 
	status |= GzNewRender(&m_pRender, GZ_Z_BUFFER_RENDER, m_pDisplay); 

/* Translation matrix */
GzMatrix	scale = 
{ 
	3.25,	0.0,	0.0,	0.0, 
	0.0,	3.25,	0.0,	-3.25, 
	0.0,	0.0,	3.25,	3.5, 
	0.0,	0.0,	0.0,	1.0 
}; 
 
GzMatrix	rotateX = 
{ 
	1.0,	0.0,	0.0,	0.0, 
	0.0,	.7071,	.7071,	0.0, 
	0.0,	-.7071,	.7071,	0.0, 
	0.0,	0.0,	0.0,	1.0 
}; 
 
GzMatrix	rotateY = 
{ 
	.866,	0.0,	-0.5,	0.0, 
	0.0,	1.0,	0.0,	0.0, 
	0.5,	0.0,	.866,	0.0, 
	0.0,	0.0,	0.0,	1.0 
}; 

#if 0 	/* set up app-defined camera if desired, else use camera defaults */
	camera.position[X] = 13.2;      
  	camera.position[Y] = -8.7;
  	camera.position[Z] = -14.8;

  	camera.lookat[X] = 0.8;
  	camera.lookat[Y] = 0.7;
  	camera.lookat[Z] = 4.5;

  	camera.worldup[X] = -0.2;
  	camera.worldup[Y] = 1.0;
  	camera.worldup[Z] = 0.0;

	camera.FOV = 53.7;              /* degrees */

	status |= GzPutCamera(m_pRender, &camera); 
#endif 

	/* Start Renderer */
	status |= GzBeginRender(m_pRender);

	/* Light */

	/* Material property */
	GzColor specularCoefficient = { 0.3, 0.3, 0.3 };
	GzColor ambientCoefficient = { 0.1, 0.1, 0.1 };
	GzColor diffuseCoefficient = {0.7, 0.7, 0.7};

/* 
  renderer is ready for frame --- define lights and shader at start of frame 
*/

	/*
	* Tokens associated with light parameters
	*/
	nameListLights[0] = GZ_DIRECTIONAL_LIGHT;
	valueListLights[0] = (GzPointer)&light1;
	nameListLights[1] = GZ_DIRECTIONAL_LIGHT;
	valueListLights[1] = (GzPointer)&light2;
	status |= GzPutAttribute(m_pRender, 2, nameListLights, valueListLights);
	
	nameListLights[0] = GZ_AMBIENT_LIGHT;
	valueListLights[0] = (GzPointer)&ambientLight;
	status |= GzPutAttribute(m_pRender, 1, nameListLights, valueListLights);
	
	/*
	* Tokens associated with shading 
	*/
	nameListShader[0]  = GZ_DIFFUSE_COEFFICIENT;
	valueListShader[0] = (GzPointer)diffuseCoefficient;

	/* 
	* Select either GZ_COLOR or GZ_NORMALS as interpolation mode  
	*/
	nameListShader[1]  = GZ_INTERPOLATE;
	interpStyle = GZ_NORMAL;       /* Phong shading */

	valueListShader[1] = (GzPointer)&interpStyle;
	nameListShader[2]  = GZ_AMBIENT_COEFFICIENT;
	valueListShader[2] = (GzPointer)ambientCoefficient;
	nameListShader[3]  = GZ_SPECULAR_COEFFICIENT;
	valueListShader[3] = (GzPointer)specularCoefficient;
	nameListShader[4]  = GZ_DISTRIBUTION_COEFFICIENT;
	specpower = 32;
	valueListShader[4] = (GzPointer)&specpower;

	status |= GzPutAttribute(m_pRender, 5, nameListShader, valueListShader);

	//status |= GzPushMatrix(m_pRender, scale);  
	//status |= GzPushMatrix(m_pRender, rotateY); 
	//status |= GzPushMatrix(m_pRender, rotateX); 

	
	LoadProceduralTexture(m_pProceduralTexture);
	LoadImageTexture(m_pImageTexture);

	if (status) exit(GZ_FAILURE); 

	if (status) 
		return(GZ_FAILURE); 
	else 
		return(GZ_SUCCESS); 
}