Exemple #1
0
int pie_AddTexPage(iV_Image *s, const char *filename, bool gameTexture, int page)
{
	ASSERT(s && filename, "Bad input parameter");

	if (page < 0)
	{
		iTexPage tex;
		page = _TEX_PAGE.size();
		glGenTextures(1, &tex.id);
		sstrcpy(tex.name, filename);
		_TEX_PAGE.append(tex);
	}
	else // replace
	{
		sstrcpy(_TEX_PAGE[page].name, filename);

	}
	debug(LOG_TEXTURE, "%s page=%d", filename, page);

	pie_SetTexturePage(page);
	if (GLEW_VERSION_4_3 || GLEW_KHR_debug)
	{
		glObjectLabel(GL_TEXTURE, pie_Texture(page), -1, filename);
	}

	if (gameTexture) // this is a game texture, use texture compression
	{
		gluBuild2DMipmaps(GL_TEXTURE_2D, wz_texture_compression, s->width, s->height, iV_getPixelFormat(s), GL_UNSIGNED_BYTE, s->bmp);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	}
	else	// this is an interface texture, do not use compression
	{
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s->width, s->height, 0, iV_getPixelFormat(s), GL_UNSIGNED_BYTE, s->bmp);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	}
	// it is uploaded, we do not need it anymore
	free(s->bmp);
	s->bmp = NULL;

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	// Use anisotropic filtering, if available, but only max 4.0 to reduce processor burden
	if (GLEW_EXT_texture_filter_anisotropic)
	{
		GLfloat max;
		glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, MIN(4.0f, max));
	}
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	/* Send back the texpage number so we can store it in the IMD */
	return page;
}
Exemple #2
0
void GFX::loadTexture(const char *filename, GLenum filter)
{
	const char *extension = strrchr(filename, '.'); // determine the filetype
	iV_Image image;
	if (!extension || strcmp(extension, ".png") != 0)
	{
		debug(LOG_ERROR, "Bad image filename: %s", filename);
		return;
	}
	if (iV_loadImage_PNG(filename, &image))
	{
		makeTexture(image.width, image.height, filter, iV_getPixelFormat(&image), image.bmp);
		iV_unloadImage(&image);
	}
}
Exemple #3
0
void screen_SetBackDropFromFile(const char* filename)
{
	// HACK : We should use a resource handler here!
	const char *extension = strrchr(filename, '.');// determine the filetype
	iV_Image image;

	if(!extension)
	{
		debug(LOG_ERROR, "Image without extension: \"%s\"!", filename);
		return; // filename without extension... don't bother
	}

	// Make sure the current texture page is reloaded after we are finished
	// Otherwise WZ will think it is still loaded and not load it again
	pie_SetTexturePage(TEXPAGE_EXTERN);

	if( strcmp(extension,".png") == 0 )
	{
		if (iV_loadImage_PNG( filename, &image ) )
		{
			if (~backDropTexture == 0)
				glGenTextures(1, &backDropTexture);

			glBindTexture(GL_TEXTURE_2D, backDropTexture);
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
					image.width, image.height,
					0, iV_getPixelFormat(&image), GL_UNSIGNED_BYTE, image.bmp);
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

			iV_unloadImage(&image);
		}
		return;
	}
	else
		debug(LOG_ERROR, "Unknown extension \"%s\" for image \"%s\"!", extension, filename);
}
Exemple #4
0
/**************************************************************************
	Add an image buffer given in s as a new texture page in the texture
	table.  We check first if the given image has already been loaded,
	as a sanity check (should never happen).  The texture numbers are
	stored in a special texture table, not in the resource system, for
	some unknown reason. Start looking for an available slot in the
	texture table at the given slot number.

	Returns the texture number of the image.
**************************************************************************/
int pie_AddTexPage(iV_Image *s, const char* filename, int slot, int maxTextureSize, bool useMipmaping)
{
    unsigned int i = 0;
    int width, height;
    void *bmp;
    bool scaleDown = false;
    GLint minfilter;

    /* Have we already loaded this one? Should not happen here. */
    while (i < _TEX_INDEX)
    {
        if (strncmp(filename, _TEX_PAGE[i].name, iV_TEXNAME_MAX) == 0)
        {
            pie_PrintLoadedTextures();
        }
        ASSERT(strncmp(filename, _TEX_PAGE[i].name, iV_TEXNAME_MAX) != 0,
               "pie_AddTexPage: %s loaded again! Already loaded as %s|%u", filename,
               _TEX_PAGE[i].name, i);
        i++;
    }

    /* Use first unused slot */
    for (i = slot; i < iV_TEX_MAX && _TEX_PAGE[i].name[0] != '\0'; i++) {}

    if (i == _TEX_INDEX)
    {
        _TEX_INDEX++; // increase table
    }
    ASSERT(i != iV_TEX_MAX, "pie_AddTexPage: too many texture pages");

    debug(LOG_TEXTURE, "pie_AddTexPage: %s page=%d", filename, _TEX_INDEX);
    assert(s != NULL);

    /* Stick the name into the tex page structures */
    sstrcpy(_TEX_PAGE[i].name, filename);

    glGenTextures(1, &_TEX_PAGE[i].id);
    // FIXME: This function is used instead of glBindTexture, but we're juggling with difficult to trace global state here. Look into pie_SetTexturePage's definition for details.
    pie_SetTexturePage(i);

    width = s->width;
    height = s->height;
    bmp = s->bmp;
    if ((width & (width-1)) == 0 && (height & (height-1)) == 0)
    {
        if (maxTextureSize > 0 && width > maxTextureSize)
        {
            width = maxTextureSize;
            scaleDown = true;
        }
        if (maxTextureSize > 0 && height > maxTextureSize)
        {
            height = maxTextureSize;
            scaleDown = true;
        }
        if (scaleDown)
        {
            debug(LOG_TEXTURE, "scaling down texture %s from %ix%i to %ix%i", filename, s->width, s->height, width, height);
            bmp = malloc(4 * width * height); // FIXME: don't know for sure it is 4 bytes per pixel
            gluScaleImage(iV_getPixelFormat(s), s->width, s->height, GL_UNSIGNED_BYTE, s->bmp,
                          width,    height,    GL_UNSIGNED_BYTE, bmp);
            free(s->bmp);
        }

        if (maxTextureSize)
        {
            // this is a 3D texture, use texture compression
            gluBuild2DMipmaps(GL_TEXTURE_2D, wz_texture_compression, width, height, iV_getPixelFormat(s), GL_UNSIGNED_BYTE, bmp);
        }
        else
        {
            // this is an interface texture, do not use compression
            gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, width, height, iV_getPixelFormat(s), GL_UNSIGNED_BYTE, bmp);
        }
    }
    else
    {
        debug(LOG_ERROR, "pie_AddTexPage: non POT texture %s", filename);
    }

    // it is uploaded, we do not need it anymore
    free(bmp);
    s->bmp = NULL;

    if (useMipmaping)
    {
        minfilter = GL_LINEAR_MIPMAP_LINEAR;
    }
    else
    {
        minfilter = GL_LINEAR;
    }

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minfilter);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    // Use anisotropic filtering, if available, but only max 4.0 to reduce processor burden
    if (GLEW_EXT_texture_filter_anisotropic)
    {
        GLfloat max;

        glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, MIN(4.0f, max));
    }

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

    /* Send back the texpage number so we can store it in the IMD */

    _TEX_INDEX++;

    return i;
}