static void texcache_setuptexture(int32_t *doalloc, GLuint *glpic) { if (*doalloc&1) { bglGenTextures(1,glpic); //# of textures (make OpenGL allocate structure) *doalloc |= 2; // prevents bglGenTextures being called again if we fail in here } bglBindTexture(GL_TEXTURE_2D,*glpic); }
//pitch must equal xsiz*4 uint32_t gloadtex(int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, int32_t dapal) { const char *const cptr = &britable[gammabrightness ? 0 : curbrightness][0]; // Correct for GL's RGB order; also apply gamma here: const coltype *const pic = (const coltype *)picbuf; coltype *pic2 = (coltype *)Xmalloc(xsiz*ysiz*sizeof(coltype)); if (!is8bit) { for (int32_t i=xsiz*ysiz-1; i>=0; i--) { pic2[i].b = cptr[pic[i].r]; pic2[i].g = cptr[pic[i].g]; pic2[i].r = cptr[pic[i].b]; pic2[i].a = 255; } } else { if (palookup[dapal] == NULL) dapal = 0; for (int32_t i=xsiz*ysiz-1; i>=0; i--) { const int32_t ii = palookup[dapal][pic[i].a]; pic2[i].b = cptr[curpalette[ii].b]; pic2[i].g = cptr[curpalette[ii].g]; pic2[i].r = cptr[curpalette[ii].r]; pic2[i].a = 255; } } uint32_t rtexid; bglGenTextures(1, (GLuint *) &rtexid); bglBindTexture(GL_TEXTURE_2D, rtexid); bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); bglTexImage2D(GL_TEXTURE_2D, 0, 4, xsiz, ysiz, 0, GL_RGBA, GL_UNSIGNED_BYTE, (char *) pic2); Bfree(pic2); return rtexid; }