| Index: ddraw/TextureManager.cpp |
| — | — | @@ -1,491 +0,0 @@ |
| 2 | | -// DXGL
|
| 3 | | -// Copyright (C) 2012-2014 William Feely
|
| 4 | | -
|
| 5 | | -// This library is free software; you can redistribute it and/or
|
| 6 | | -// modify it under the terms of the GNU Lesser General Public
|
| 7 | | -// License as published by the Free Software Foundation; either
|
| 8 | | -// version 2.1 of the License, or (at your option) any later version.
|
| 9 | | -
|
| 10 | | -// This library is distributed in the hope that it will be useful,
|
| 11 | | -// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 | | -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 | | -// Lesser General Public License for more details.
|
| 14 | | -
|
| 15 | | -// You should have received a copy of the GNU Lesser General Public
|
| 16 | | -// License along with this library; if not, write to the Free Software
|
| 17 | | -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | | -
|
| 19 | | -#include "common.h"
|
| 20 | | -#include "TextureManager.h"
|
| 21 | | -#include "glUtil.h"
|
| 22 | | -#include "timer.h"
|
| 23 | | -#include "glRenderer.h"
|
| 24 | | -
|
| 25 | | -// Use EXACTLY one line per entry. Don't change layout of the list.
|
| 26 | | -const int START_TEXFORMATS = __LINE__;
|
| 27 | | -const DDPIXELFORMAT texformats[] =
|
| 28 | | -{ // Size Flags FOURCC bits R/Ymask G/U/Zmask B/V/STmask A/Zmask
|
| 29 | | - {sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8, 0, 8, 0, 0, 0, 0},
|
| 30 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 8, 0xE0, 0x1C, 0x3, 0},
|
| 31 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x7C00, 0x3E0, 0x1F, 0},
|
| 32 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0xF800, 0x7E0, 0x1F, 0},
|
| 33 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0xFF0000, 0xFF00, 0xFF, 0},
|
| 34 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF0000, 0xFF00, 0xFF, 0},
|
| 35 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF, 0xFF00, 0xFF0000, 0},
|
| 36 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xE0, 0x1C, 0x3, 0xFF00},
|
| 37 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xF00, 0xF0, 0xF, 0xF000},
|
| 38 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0x7c00, 0x3E0, 0x1F, 0x8000},
|
| 39 | | - {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000},
|
| 40 | | - {sizeof(DDPIXELFORMAT), DDPF_LUMINANCE, 0, 8, 0xFF, 0, 0, 0},
|
| 41 | | - {sizeof(DDPIXELFORMAT), DDPF_ALPHA, 0, 8, 0, 0, 0, 0},
|
| 42 | | - {sizeof(DDPIXELFORMAT), DDPF_LUMINANCE|DDPF_ALPHAPIXELS,0, 16, 0xFF, 0, 0, 0xFF00},
|
| 43 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 16, 0, 0xFFFF, 0, 0},
|
| 44 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 24, 0, 0xFFFFFF00, 0, 0},
|
| 45 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFF00, 0, 0},
|
| 46 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFFFF, 0, 0},
|
| 47 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFFFFFF00, 0xFF, 0},
|
| 48 | | - {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFF, 0xFFFFFF00, 0}
|
| 49 | | -};
|
| 50 | | -const int END_TEXFORMATS = __LINE__ - 4;
|
| 51 | | -const int numtexformats = END_TEXFORMATS - START_TEXFORMATS;
|
| 52 | | -
|
| 53 | | -TextureManager::TextureManager(glExtensions *glext)
|
| 54 | | -{
|
| 55 | | - ext = glext;
|
| 56 | | - texlevel = 0;
|
| 57 | | - ZeroMemory(textures, 16 * sizeof(GLuint));
|
| 58 | | -}
|
| 59 | | -
|
| 60 | | -void TextureManager::_CreateTexture(TEXTURE *texture, int width, int height)
|
| 61 | | -{
|
| 62 | | - CreateTextureClassic(texture, width, height);
|
| 63 | | -}
|
| 64 | | -void TextureManager::_DeleteTexture(TEXTURE *texture)
|
| 65 | | -{
|
| 66 | | - DeleteTexture(texture);
|
| 67 | | -}
|
| 68 | | -void TextureManager::_UploadTexture(TEXTURE *texture, int level, const void *data, int width, int height)
|
| 69 | | -{
|
| 70 | | - UploadTextureClassic(texture, level, data, width, height);
|
| 71 | | -}
|
| 72 | | -void TextureManager::_DownloadTexture(TEXTURE *texture, int level, void *data)
|
| 73 | | -{
|
| 74 | | - DownloadTextureClassic(texture, level, data);
|
| 75 | | -}
|
| 76 | | -
|
| 77 | | -void TextureManager::InitSamplers()
|
| 78 | | -{
|
| 79 | | - if(ext->GLEXT_ARB_sampler_objects)
|
| 80 | | - {
|
| 81 | | - memset(samplers,0,8*sizeof(SAMPLER));
|
| 82 | | - for(int i = 0; i < 8; i++)
|
| 83 | | - {
|
| 84 | | - ext->glGenSamplers(1,&samplers[i].id);
|
| 85 | | - ext->glBindSampler(i,samplers[i].id);
|
| 86 | | - ext->glSamplerParameteri(samplers[i].id,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
|
| 87 | | - ext->glSamplerParameteri(samplers[i].id,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
|
| 88 | | - ext->glSamplerParameteri(samplers[i].id,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
| 89 | | - ext->glSamplerParameteri(samplers[i].id,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
| 90 | | - }
|
| 91 | | - }
|
| 92 | | -}
|
| 93 | | -void TextureManager::DeleteSamplers()
|
| 94 | | -{
|
| 95 | | - if(ext->GLEXT_ARB_sampler_objects)
|
| 96 | | - {
|
| 97 | | - for(int i = 0; i < 8; i++)
|
| 98 | | - {
|
| 99 | | - ext->glBindSampler(i,0);
|
| 100 | | - ext->glDeleteSamplers(1,&samplers[i].id);
|
| 101 | | - samplers[i].id = 0;
|
| 102 | | - }
|
| 103 | | - }
|
| 104 | | -}
|
| 105 | | -
|
| 106 | | -void TextureManager::CreateTextureClassic(TEXTURE *texture, int width, int height)
|
| 107 | | -{
|
| 108 | | - int texformat = -1;
|
| 109 | | - texture->pixelformat.dwSize = sizeof(DDPIXELFORMAT);
|
| 110 | | - for(int i = 0; i < numtexformats; i++)
|
| 111 | | - {
|
| 112 | | - if(!memcmp(&texformats[i],&texture->pixelformat,sizeof(DDPIXELFORMAT)))
|
| 113 | | - {
|
| 114 | | - texformat = i;
|
| 115 | | - break;
|
| 116 | | - }
|
| 117 | | - }
|
| 118 | | - switch(texformat)
|
| 119 | | - {
|
| 120 | | - case -1:
|
| 121 | | - case 0: // 8-bit palette
|
| 122 | | - if(ext->glver_major >= 3)
|
| 123 | | - {
|
| 124 | | - texture->internalformat = GL_R8;
|
| 125 | | - texture->format = GL_RED;
|
| 126 | | - }
|
| 127 | | - else
|
| 128 | | - {
|
| 129 | | - texture->internalformat = GL_RGBA8;
|
| 130 | | - texture->format = GL_LUMINANCE;
|
| 131 | | - }
|
| 132 | | - texture->type = GL_UNSIGNED_BYTE;
|
| 133 | | - break;
|
| 134 | | - case 1: // 8-bit RGB332
|
| 135 | | - texture->internalformat = GL_R3_G3_B2;
|
| 136 | | - texture->format = GL_RGB;
|
| 137 | | - texture->type = GL_UNSIGNED_BYTE_3_3_2;
|
| 138 | | - break;
|
| 139 | | - case 2: // 16-bit RGB555
|
| 140 | | - texture->internalformat = GL_RGB5_A1;
|
| 141 | | - texture->format = GL_BGRA;
|
| 142 | | - texture->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
| 143 | | - break;
|
| 144 | | - case 3: // 16-bit RGB565
|
| 145 | | - /*if(GLEXT_ARB_ES2_compatibility) texture->internalformat = GL_RGB565;
|
| 146 | | - else */texture->internalformat = GL_RGBA8;
|
| 147 | | - texture->format = GL_RGB;
|
| 148 | | - texture->type = GL_UNSIGNED_SHORT_5_6_5;
|
| 149 | | - break;
|
| 150 | | - case 4: // 24-bit RGB888
|
| 151 | | - texture->internalformat = GL_RGB8;
|
| 152 | | - texture->format = GL_BGR;
|
| 153 | | - texture->type = GL_UNSIGNED_BYTE;
|
| 154 | | - break;
|
| 155 | | - case 5: // 32-bit RGB888
|
| 156 | | - texture->internalformat = GL_RGBA8;
|
| 157 | | - texture->format = GL_BGRA;
|
| 158 | | - texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| 159 | | - break;
|
| 160 | | - case 6: // 32-bit BGR888
|
| 161 | | - texture->internalformat = GL_RGBA8;
|
| 162 | | - texture->format = GL_RGBA;
|
| 163 | | - texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| 164 | | - break;
|
| 165 | | - case 7: // 16-bit RGBA8332
|
| 166 | | - FIXME("Unusual texture format RGBA8332 not supported");
|
| 167 | | - break;
|
| 168 | | - case 8: // 16-bit RGBA4444
|
| 169 | | - texture->internalformat = GL_RGBA4;
|
| 170 | | - texture->format = GL_BGRA;
|
| 171 | | - texture->type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
|
| 172 | | - break;
|
| 173 | | - case 9: // 16-bit RGBA1555
|
| 174 | | - texture->internalformat = GL_RGB5_A1;
|
| 175 | | - texture->format = GL_BGRA;
|
| 176 | | - texture->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
| 177 | | - break;
|
| 178 | | - case 10: // 32-bit RGBA8888
|
| 179 | | - texture->internalformat = GL_RGBA8;
|
| 180 | | - texture->format = GL_BGRA;
|
| 181 | | - texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| 182 | | - break;
|
| 183 | | - case 11: // 8-bit Luminance
|
| 184 | | - texture->internalformat = GL_LUMINANCE8;
|
| 185 | | - texture->format = GL_LUMINANCE;
|
| 186 | | - texture->type = GL_UNSIGNED_BYTE;
|
| 187 | | - break;
|
| 188 | | - case 12: // 8-bit Alpha
|
| 189 | | - texture->internalformat = GL_ALPHA8;
|
| 190 | | - texture->format = GL_ALPHA;
|
| 191 | | - texture->type = GL_UNSIGNED_BYTE;
|
| 192 | | - break;
|
| 193 | | - case 13: // 16-bit Luminance Alpha
|
| 194 | | - texture->internalformat = GL_LUMINANCE8_ALPHA8;
|
| 195 | | - texture->format = GL_LUMINANCE_ALPHA;
|
| 196 | | - texture->type = GL_UNSIGNED_BYTE;
|
| 197 | | - break;
|
| 198 | | - case 14: // 16-bit Z buffer
|
| 199 | | - texture->internalformat = GL_DEPTH_COMPONENT16;
|
| 200 | | - texture->format = GL_DEPTH_COMPONENT;
|
| 201 | | - texture->type = GL_UNSIGNED_SHORT;
|
| 202 | | - break;
|
| 203 | | - case 15: // 24-bit Z buffer
|
| 204 | | - texture->internalformat = GL_DEPTH_COMPONENT24;
|
| 205 | | - texture->format = GL_DEPTH_COMPONENT;
|
| 206 | | - texture->type = GL_UNSIGNED_INT;
|
| 207 | | - break;
|
| 208 | | - case 16: // 32/24 bit Z buffer
|
| 209 | | - texture->internalformat = GL_DEPTH_COMPONENT24;
|
| 210 | | - texture->format = GL_DEPTH_COMPONENT;
|
| 211 | | - texture->type = GL_UNSIGNED_INT;
|
| 212 | | - break;
|
| 213 | | - case 17: // 32-bit Z buffer
|
| 214 | | - texture->internalformat = GL_DEPTH_COMPONENT32;
|
| 215 | | - texture->format = GL_DEPTH_COMPONENT;
|
| 216 | | - texture->type = GL_UNSIGNED_INT;
|
| 217 | | - break;
|
| 218 | | - case 18: // 32-bit Z/Stencil buffer, depth LSB
|
| 219 | | - texture->internalformat = GL_DEPTH24_STENCIL8;
|
| 220 | | - texture->format = GL_DEPTH_STENCIL;
|
| 221 | | - texture->type = GL_UNSIGNED_INT_24_8;
|
| 222 | | - break;
|
| 223 | | - case 19: // 32-bit Z/Stencil buffer, depth MSB
|
| 224 | | - texture->internalformat = GL_DEPTH24_STENCIL8;
|
| 225 | | - texture->format = GL_DEPTH_STENCIL;
|
| 226 | | - texture->type = GL_UNSIGNED_INT_24_8;
|
| 227 | | - break;
|
| 228 | | - }
|
| 229 | | - texture->width = width;
|
| 230 | | - texture->height = height;
|
| 231 | | - glGenTextures(1,&texture->id);
|
| 232 | | - SetTexture(0,texture);
|
| 233 | | - glTexImage2D(GL_TEXTURE_2D,0,texture->internalformat,texture->width,texture->height,0,texture->format,texture->type,NULL);
|
| 234 | | - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,texture->minfilter);
|
| 235 | | - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,texture->magfilter);
|
| 236 | | - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,texture->wraps);
|
| 237 | | - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,texture->wrapt);
|
| 238 | | -}
|
| 239 | | -
|
| 240 | | -void TextureManager::DeleteTexture(TEXTURE *texture)
|
| 241 | | -{
|
| 242 | | - glDeleteTextures(1,&texture->id);
|
| 243 | | - texture->bordercolor = texture->format = texture->internalformat =
|
| 244 | | - texture->type = texture->width = texture->height = texture->magfilter =
|
| 245 | | - texture->minfilter = texture->miplevel = texture->wraps = texture->wrapt =
|
| 246 | | - texture->pbo = texture->id = 0;
|
| 247 | | -}
|
| 248 | | -
|
| 249 | | -void TextureManager::UploadTextureClassic(TEXTURE *texture, int level, const void *data, int width, int height)
|
| 250 | | -{
|
| 251 | | - texture->width = width;
|
| 252 | | - texture->height = height;
|
| 253 | | - if(ext->GLEXT_EXT_direct_state_access) ext->glTextureImage2DEXT(texture->id,GL_TEXTURE_2D,level,texture->internalformat,
|
| 254 | | - width,height,0,texture->format,texture->type,data);
|
| 255 | | - else
|
| 256 | | - {
|
| 257 | | - SetActiveTexture(0);
|
| 258 | | - SetTexture(0,texture);
|
| 259 | | - glTexImage2D(GL_TEXTURE_2D,level,texture->internalformat,width,height,0,texture->format,texture->type,data);
|
| 260 | | - }
|
| 261 | | -}
|
| 262 | | -
|
| 263 | | -void TextureManager::DownloadTextureClassic(TEXTURE *texture, int level, void *data)
|
| 264 | | -{
|
| 265 | | - if(ext->GLEXT_EXT_direct_state_access) ext->glGetTextureImageEXT(texture->id,GL_TEXTURE_2D,level,texture->format,texture->type,data);
|
| 266 | | - else
|
| 267 | | - {
|
| 268 | | - SetActiveTexture(0);
|
| 269 | | - SetTexture(0,texture);
|
| 270 | | - glGetTexImage(GL_TEXTURE_2D,level,texture->format,texture->type,data);
|
| 271 | | - }
|
| 272 | | -}
|
| 273 | | -
|
| 274 | | -void TextureManager::SetActiveTexture(int level)
|
| 275 | | -{
|
| 276 | | - if(level != texlevel)
|
| 277 | | - {
|
| 278 | | - texlevel = level;
|
| 279 | | - ext->glActiveTexture(GL_TEXTURE0+level);
|
| 280 | | - }
|
| 281 | | -}
|
| 282 | | -
|
| 283 | | -
|
| 284 | | -void TextureManager::SetTexture(unsigned int level, TEXTURE *texture)
|
| 285 | | -{
|
| 286 | | - if(level >= 16) return;
|
| 287 | | - GLuint texname;
|
| 288 | | - if(!texture) texname = 0;
|
| 289 | | - else texname=texture->id;
|
| 290 | | - if(texname != textures[level])
|
| 291 | | - {
|
| 292 | | - SetActiveTexture(level);
|
| 293 | | - glBindTexture(GL_TEXTURE_2D,texname);
|
| 294 | | - }
|
| 295 | | -}
|
| 296 | | -
|
| 297 | | -
|
| 298 | | -
|
| 299 | | -/* old code
|
| 300 | | - if(ddsd.ddpfPixelFormat.dwFlags & DDPF_RGB)
|
| 301 | | - {
|
| 302 | | - switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
|
| 303 | | - {
|
| 304 | | - case 8:
|
| 305 | | - if(ddsd.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8)
|
| 306 | | - {
|
| 307 | | - texformat = GL_LUMINANCE;
|
| 308 | | - texformat2 = GL_UNSIGNED_BYTE;
|
| 309 | | - if(dxglcfg.texformat) texformat3 = GL_LUMINANCE8;
|
| 310 | | - else texformat3 = GL_RGBA8;
|
| 311 | | - if(!palettein) palette = new glDirectDrawPalette(DDPCAPS_8BIT|DDPCAPS_ALLOW256|DDPCAPS_PRIMARYSURFACE,NULL,NULL);
|
| 312 | | - bitmapinfo->bmiHeader.biBitCount = 8;
|
| 313 | | - }
|
| 314 | | - else
|
| 315 | | - {
|
| 316 | | - texformat = GL_RGB;
|
| 317 | | - texformat2 = GL_UNSIGNED_BYTE_3_3_2;
|
| 318 | | - if(dxglcfg.texformat) texformat3 = GL_R3_G3_B2;
|
| 319 | | - else texformat3 = GL_RGBA8;
|
| 320 | | - }
|
| 321 | | - ddsd.ddpfPixelFormat.dwRBitMask = 0;
|
| 322 | | - ddsd.ddpfPixelFormat.dwGBitMask = 0;
|
| 323 | | - ddsd.ddpfPixelFormat.dwBBitMask = 0;
|
| 324 | | - ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth);
|
| 325 | | - break;
|
| 326 | | - case 16:
|
| 327 | | - if((ddsd.ddpfPixelFormat.dwRBitMask == 0x7C00) && (ddsd.ddpfPixelFormat.dwGBitMask == 0x3E0)
|
| 328 | | - && (ddsd.ddpfPixelFormat.dwBBitMask == 0x1F))
|
| 329 | | - {
|
| 330 | | - texformat = GL_BGRA;
|
| 331 | | - texformat2 = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
| 332 | | - if(dxglcfg.texformat) texformat3 = GL_RGB5_A1;
|
| 333 | | - else texformat3 = GL_RGBA8;
|
| 334 | | - }
|
| 335 | | - else // fixme: support more formats
|
| 336 | | - {
|
| 337 | | - texformat = GL_RGB;
|
| 338 | | - texformat2 = GL_UNSIGNED_SHORT_5_6_5;
|
| 339 | | - if(dxglcfg.texformat) texformat3 = GL_RGB;
|
| 340 | | - else texformat3 = GL_RGBA8;
|
| 341 | | - }
|
| 342 | | - ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*2);
|
| 343 | | - break;
|
| 344 | | - case 24:
|
| 345 | | - if((ddsd.ddpfPixelFormat.dwRBitMask == 0xFF0000) && (ddsd.ddpfPixelFormat.dwGBitMask == 0xFF00)
|
| 346 | | - && (ddsd.ddpfPixelFormat.dwBBitMask == 0xFF))
|
| 347 | | - {
|
| 348 | | - texformat = GL_BGR;
|
| 349 | | - texformat2 = GL_UNSIGNED_BYTE;
|
| 350 | | - if(dxglcfg.texformat) texformat3 = GL_RGB8;
|
| 351 | | - else texformat3 = GL_RGBA8;
|
| 352 | | - }
|
| 353 | | - else // fixme: support more formats
|
| 354 | | - {
|
| 355 | | - texformat = GL_RGB;
|
| 356 | | - texformat2 = GL_UNSIGNED_BYTE;
|
| 357 | | - if(dxglcfg.texformat) texformat3 = GL_RGB8;
|
| 358 | | - else texformat3 = GL_RGBA8;
|
| 359 | | - }
|
| 360 | | - ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*3);
|
| 361 | | - break;
|
| 362 | | - case 32:
|
| 363 | | - default:
|
| 364 | | - if((ddsd.ddpfPixelFormat.dwRBitMask == 0xFF0000) && (ddsd.ddpfPixelFormat.dwGBitMask == 0xFF00)
|
| 365 | | - && (ddsd.ddpfPixelFormat.dwBBitMask == 0xFF))
|
| 366 | | - {
|
| 367 | | - texformat = GL_BGRA;
|
| 368 | | - texformat2 = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| 369 | | - texformat3 = GL_RGBA8;
|
| 370 | | - }
|
| 371 | | - else // fixme: support more formats
|
| 372 | | - {
|
| 373 | | - texformat = GL_RGBA;
|
| 374 | | - texformat2 = GL_UNSIGNED_BYTE;
|
| 375 | | - texformat3 = GL_RGBA8;
|
| 376 | | - }
|
| 377 | | - ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*4);
|
| 378 | | - }
|
| 379 | | - }
|
| 380 | | - else if(ddsd.ddpfPixelFormat.dwFlags & DDPF_ZBUFFER)
|
| 381 | | - {
|
| 382 | | - switch(ddsd.ddpfPixelFormat.dwZBufferBitDepth)
|
| 383 | | - {
|
| 384 | | - case 16:
|
| 385 | | - default:
|
| 386 | | - texformat = GL_DEPTH_COMPONENT;
|
| 387 | | - texformat2 = GL_UNSIGNED_BYTE;
|
| 388 | | - texformat3 = GL_DEPTH_COMPONENT16;
|
| 389 | | - break;
|
| 390 | | - case 24:
|
| 391 | | - texformat = GL_DEPTH_COMPONENT;
|
| 392 | | - texformat2 = GL_UNSIGNED_BYTE;
|
| 393 | | - texformat3 = GL_DEPTH_COMPONENT24;
|
| 394 | | - break;
|
| 395 | | - case 32:
|
| 396 | | - if((ddsd.ddpfPixelFormat.dwRGBZBitMask == 0x00ffffff) &&
|
| 397 | | - !(ddsd.ddpfPixelFormat.dwFlags & DDPF_STENCILBUFFER))
|
| 398 | | - {
|
| 399 | | - texformat = GL_DEPTH_COMPONENT;
|
| 400 | | - texformat2 = GL_UNSIGNED_INT;
|
| 401 | | - texformat3 = GL_DEPTH_COMPONENT24;
|
| 402 | | - break;
|
| 403 | | - }
|
| 404 | | - else if(ddsd.ddpfPixelFormat.dwFlags & DDPF_STENCILBUFFER)
|
| 405 | | - {
|
| 406 | | - texformat = GL_DEPTH_STENCIL;
|
| 407 | | - texformat2 = GL_UNSIGNED_INT_24_8;
|
| 408 | | - texformat3 = GL_DEPTH24_STENCIL8;
|
| 409 | | - hasstencil = true;
|
| 410 | | - break;
|
| 411 | | - }
|
| 412 | | - else
|
| 413 | | - {
|
| 414 | | - texformat = GL_DEPTH_COMPONENT;
|
| 415 | | - texformat2 = GL_UNSIGNED_INT;
|
| 416 | | - texformat3 = GL_DEPTH_COMPONENT32;
|
| 417 | | - break;
|
| 418 | | - }
|
| 419 | | - }
|
| 420 | | - }
|
| 421 | | - }
|
| 422 | | -
|
| 423 | | -*/
|
| 424 | | -
|
| 425 | | -/*
|
| 426 | | - if(!(ddsd.dwFlags & DDSD_PIXELFORMAT))
|
| 427 | | - {
|
| 428 | | - ddsd.ddpfPixelFormat.dwRGBBitCount = ddInterface->GetBPP();
|
| 429 | | - switch(ddInterface->GetBPP())
|
| 430 | | - {
|
| 431 | | - case 8:
|
| 432 | | - texformat = GL_LUMINANCE;
|
| 433 | | - texformat2 = GL_UNSIGNED_BYTE;
|
| 434 | | - if(dxglcfg.texformat) texformat3 = GL_LUMINANCE8;
|
| 435 | | - else texformat3 = GL_RGBA8;
|
| 436 | | - ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
|
| 437 | | - ddsd.ddpfPixelFormat.dwRBitMask = 0;
|
| 438 | | - ddsd.ddpfPixelFormat.dwGBitMask = 0;
|
| 439 | | - ddsd.ddpfPixelFormat.dwBBitMask = 0;
|
| 440 | | - ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth);
|
| 441 | | - break;
|
| 442 | | - case 15:
|
| 443 | | - texformat = GL_BGRA;
|
| 444 | | - texformat2 = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
| 445 | | - if(dxglcfg.texformat) texformat3 = GL_RGB5_A1;
|
| 446 | | - else texformat3 = GL_RGBA8;
|
| 447 | | - ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
| 448 | | - ddsd.ddpfPixelFormat.dwRBitMask = 0x7C00;
|
| 449 | | - ddsd.ddpfPixelFormat.dwGBitMask = 0x3E0;
|
| 450 | | - ddsd.ddpfPixelFormat.dwBBitMask = 0x1F;
|
| 451 | | - ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*2);
|
| 452 | | - ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
|
| 453 | | - break;
|
| 454 | | - case 16:
|
| 455 | | - texformat = GL_RGB;
|
| 456 | | - texformat2 = GL_UNSIGNED_SHORT_5_6_5;
|
| 457 | | - if(dxglcfg.texformat) texformat3 = GL_RGB;
|
| 458 | | - else texformat3 = GL_RGBA8;
|
| 459 | | - ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
| 460 | | - ddsd.ddpfPixelFormat.dwRBitMask = 0xF800;
|
| 461 | | - ddsd.ddpfPixelFormat.dwGBitMask = 0x7E0;
|
| 462 | | - ddsd.ddpfPixelFormat.dwBBitMask = 0x1F;
|
| 463 | | - ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*2);
|
| 464 | | - break;
|
| 465 | | - case 24:
|
| 466 | | - texformat = GL_BGR;
|
| 467 | | - texformat2 = GL_UNSIGNED_BYTE;
|
| 468 | | - if(dxglcfg.texformat) texformat3 = GL_RGB8;
|
| 469 | | - else texformat3 = GL_RGBA8;
|
| 470 | | - ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
| 471 | | - ddsd.ddpfPixelFormat.dwRBitMask = 0xFF0000;
|
| 472 | | - ddsd.ddpfPixelFormat.dwGBitMask = 0xFF00;
|
| 473 | | - ddsd.ddpfPixelFormat.dwBBitMask = 0xFF;
|
| 474 | | - ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*3);
|
| 475 | | - break;
|
| 476 | | - case 32:
|
| 477 | | - texformat = GL_BGRA;
|
| 478 | | - texformat2 = GL_UNSIGNED_BYTE;
|
| 479 | | - texformat3 = GL_RGBA8;
|
| 480 | | - ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
| 481 | | - ddsd.ddpfPixelFormat.dwRBitMask = 0xFF0000;
|
| 482 | | - ddsd.ddpfPixelFormat.dwGBitMask = 0xFF00;
|
| 483 | | - ddsd.ddpfPixelFormat.dwBBitMask = 0xFF;
|
| 484 | | - ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*4);
|
| 485 | | - break;
|
| 486 | | - default:
|
| 487 | | - *error = DDERR_INVALIDPIXELFORMAT;
|
| 488 | | - return;
|
| 489 | | - }
|
| 490 | | - }
|
| 491 | | -
|
| 492 | | -*/ |
| \ No newline at end of file |
| Index: ddraw/TextureManager.c |
| — | — | @@ -0,0 +1,497 @@ |
| | 2 | +// DXGL
|
| | 3 | +// Copyright (C) 2012-2014 William Feely
|
| | 4 | +
|
| | 5 | +// This library is free software; you can redistribute it and/or
|
| | 6 | +// modify it under the terms of the GNU Lesser General Public
|
| | 7 | +// License as published by the Free Software Foundation; either
|
| | 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| | 9 | +
|
| | 10 | +// This library is distributed in the hope that it will be useful,
|
| | 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| | 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| | 13 | +// Lesser General Public License for more details.
|
| | 14 | +
|
| | 15 | +// You should have received a copy of the GNU Lesser General Public
|
| | 16 | +// License along with this library; if not, write to the Free Software
|
| | 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| | 18 | +
|
| | 19 | +#include "common.h"
|
| | 20 | +#include "TextureManager.h"
|
| | 21 | +
|
| | 22 | +// Use EXACTLY one line per entry. Don't change layout of the list.
|
| | 23 | +static const int START_TEXFORMATS = __LINE__;
|
| | 24 | +const DDPIXELFORMAT texformats[] =
|
| | 25 | +{ // Size Flags FOURCC bits R/Ymask G/U/Zmask B/V/STmask A/Zmask
|
| | 26 | + {sizeof(DDPIXELFORMAT), DDPF_PALETTEINDEXED8, 0, 8, 0, 0, 0, 0},
|
| | 27 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 8, 0xE0, 0x1C, 0x3, 0},
|
| | 28 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x7C00, 0x3E0, 0x1F, 0},
|
| | 29 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0xF800, 0x7E0, 0x1F, 0},
|
| | 30 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0xFF0000, 0xFF00, 0xFF, 0},
|
| | 31 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF0000, 0xFF00, 0xFF, 0},
|
| | 32 | + {sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0xFF, 0xFF00, 0xFF0000, 0},
|
| | 33 | + {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xE0, 0x1C, 0x3, 0xFF00},
|
| | 34 | + {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0xF00, 0xF0, 0xF, 0xF000},
|
| | 35 | + {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 16, 0x7c00, 0x3E0, 0x1F, 0x8000},
|
| | 36 | + {sizeof(DDPIXELFORMAT), DDPF_RGB|DDPF_ALPHAPIXELS, 0, 32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000},
|
| | 37 | + {sizeof(DDPIXELFORMAT), DDPF_LUMINANCE, 0, 8, 0xFF, 0, 0, 0},
|
| | 38 | + {sizeof(DDPIXELFORMAT), DDPF_ALPHA, 0, 8, 0, 0, 0, 0},
|
| | 39 | + {sizeof(DDPIXELFORMAT), DDPF_LUMINANCE|DDPF_ALPHAPIXELS,0, 16, 0xFF, 0, 0, 0xFF00},
|
| | 40 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 16, 0, 0xFFFF, 0, 0},
|
| | 41 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 24, 0, 0xFFFFFF00, 0, 0},
|
| | 42 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFF00, 0, 0},
|
| | 43 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 0, 0xFFFFFFFF, 0, 0},
|
| | 44 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFFFFFF00, 0xFF, 0},
|
| | 45 | + {sizeof(DDPIXELFORMAT), DDPF_ZBUFFER, 0, 32, 8, 0xFF, 0xFFFFFF00, 0}
|
| | 46 | +};
|
| | 47 | +static const int END_TEXFORMATS = __LINE__ - 4;
|
| | 48 | +int numtexformats;
|
| | 49 | +
|
| | 50 | +TextureManager *TextureManager_Create(glExtensions *glext)
|
| | 51 | +{
|
| | 52 | + TextureManager *newtex;
|
| | 53 | + numtexformats = END_TEXFORMATS - START_TEXFORMATS;
|
| | 54 | + newtex = (TextureManager*)malloc(sizeof(TextureManager));
|
| | 55 | + if (!newtex) return 0;
|
| | 56 | + ZeroMemory(newtex, sizeof(TextureManager));
|
| | 57 | + newtex->ext = glext;
|
| | 58 | + newtex->texlevel = 0;
|
| | 59 | + ZeroMemory(newtex->textures, 16 * sizeof(GLuint));
|
| | 60 | + return newtex;
|
| | 61 | +}
|
| | 62 | +
|
| | 63 | +void TextureManager__CreateTexture(TextureManager *This, TEXTURE *texture, int width, int height)
|
| | 64 | +{
|
| | 65 | + TextureManager_CreateTextureClassic(This, texture, width, height);
|
| | 66 | +}
|
| | 67 | +void TextureManager__DeleteTexture(TextureManager *This, TEXTURE *texture)
|
| | 68 | +{
|
| | 69 | + TextureManager_DeleteTexture(This, texture);
|
| | 70 | +}
|
| | 71 | +void TextureManager__UploadTexture(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height)
|
| | 72 | +{
|
| | 73 | + TextureManager_UploadTextureClassic(This, texture, level, data, width, height);
|
| | 74 | +}
|
| | 75 | +void TextureManager__DownloadTexture(TextureManager *This, TEXTURE *texture, int level, void *data)
|
| | 76 | +{
|
| | 77 | + TextureManager_DownloadTextureClassic(This, texture, level, data);
|
| | 78 | +}
|
| | 79 | +
|
| | 80 | +void TextureManager_InitSamplers(TextureManager *This)
|
| | 81 | +{
|
| | 82 | + int i;
|
| | 83 | + if(This->ext->GLEXT_ARB_sampler_objects)
|
| | 84 | + {
|
| | 85 | + memset(This->samplers,0,8*sizeof(SAMPLER));
|
| | 86 | + for(i = 0; i < 8; i++)
|
| | 87 | + {
|
| | 88 | + This->ext->glGenSamplers(1,&This->samplers[i].id);
|
| | 89 | + This->ext->glBindSampler(i,This->samplers[i].id);
|
| | 90 | + This->ext->glSamplerParameteri(This->samplers[i].id,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
|
| | 91 | + This->ext->glSamplerParameteri(This->samplers[i].id,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
|
| | 92 | + This->ext->glSamplerParameteri(This->samplers[i].id,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
|
| | 93 | + This->ext->glSamplerParameteri(This->samplers[i].id,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
|
| | 94 | + }
|
| | 95 | + }
|
| | 96 | +}
|
| | 97 | +void TextureManager_DeleteSamplers(TextureManager *This)
|
| | 98 | +{
|
| | 99 | + int i;
|
| | 100 | + if(This->ext->GLEXT_ARB_sampler_objects)
|
| | 101 | + {
|
| | 102 | + for(i = 0; i < 8; i++)
|
| | 103 | + {
|
| | 104 | + This->ext->glBindSampler(i,0);
|
| | 105 | + This->ext->glDeleteSamplers(1,&This->samplers[i].id);
|
| | 106 | + This->samplers[i].id = 0;
|
| | 107 | + }
|
| | 108 | + }
|
| | 109 | +}
|
| | 110 | +
|
| | 111 | +void TextureManager_CreateTextureClassic(TextureManager *This, TEXTURE *texture, int width, int height)
|
| | 112 | +{
|
| | 113 | + int texformat = -1;
|
| | 114 | + int i;
|
| | 115 | + texture->pixelformat.dwSize = sizeof(DDPIXELFORMAT);
|
| | 116 | + for(i = 0; i < numtexformats; i++)
|
| | 117 | + {
|
| | 118 | + if(!memcmp(&texformats[i],&texture->pixelformat,sizeof(DDPIXELFORMAT)))
|
| | 119 | + {
|
| | 120 | + texformat = i;
|
| | 121 | + break;
|
| | 122 | + }
|
| | 123 | + }
|
| | 124 | + switch(texformat)
|
| | 125 | + {
|
| | 126 | + case -1:
|
| | 127 | + case 0: // 8-bit palette
|
| | 128 | + if(This->ext->glver_major >= 3)
|
| | 129 | + {
|
| | 130 | + texture->internalformat = GL_R8;
|
| | 131 | + texture->format = GL_RED;
|
| | 132 | + }
|
| | 133 | + else
|
| | 134 | + {
|
| | 135 | + texture->internalformat = GL_RGBA8;
|
| | 136 | + texture->format = GL_LUMINANCE;
|
| | 137 | + }
|
| | 138 | + texture->type = GL_UNSIGNED_BYTE;
|
| | 139 | + break;
|
| | 140 | + case 1: // 8-bit RGB332
|
| | 141 | + texture->internalformat = GL_R3_G3_B2;
|
| | 142 | + texture->format = GL_RGB;
|
| | 143 | + texture->type = GL_UNSIGNED_BYTE_3_3_2;
|
| | 144 | + break;
|
| | 145 | + case 2: // 16-bit RGB555
|
| | 146 | + texture->internalformat = GL_RGB5_A1;
|
| | 147 | + texture->format = GL_BGRA;
|
| | 148 | + texture->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
| | 149 | + break;
|
| | 150 | + case 3: // 16-bit RGB565
|
| | 151 | + /*if(GLEXT_ARB_ES2_compatibility) texture->internalformat = GL_RGB565;
|
| | 152 | + else */texture->internalformat = GL_RGBA8;
|
| | 153 | + texture->format = GL_RGB;
|
| | 154 | + texture->type = GL_UNSIGNED_SHORT_5_6_5;
|
| | 155 | + break;
|
| | 156 | + case 4: // 24-bit RGB888
|
| | 157 | + texture->internalformat = GL_RGB8;
|
| | 158 | + texture->format = GL_BGR;
|
| | 159 | + texture->type = GL_UNSIGNED_BYTE;
|
| | 160 | + break;
|
| | 161 | + case 5: // 32-bit RGB888
|
| | 162 | + texture->internalformat = GL_RGBA8;
|
| | 163 | + texture->format = GL_BGRA;
|
| | 164 | + texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| | 165 | + break;
|
| | 166 | + case 6: // 32-bit BGR888
|
| | 167 | + texture->internalformat = GL_RGBA8;
|
| | 168 | + texture->format = GL_RGBA;
|
| | 169 | + texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| | 170 | + break;
|
| | 171 | + case 7: // 16-bit RGBA8332
|
| | 172 | + FIXME("Unusual texture format RGBA8332 not supported");
|
| | 173 | + break;
|
| | 174 | + case 8: // 16-bit RGBA4444
|
| | 175 | + texture->internalformat = GL_RGBA4;
|
| | 176 | + texture->format = GL_BGRA;
|
| | 177 | + texture->type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
|
| | 178 | + break;
|
| | 179 | + case 9: // 16-bit RGBA1555
|
| | 180 | + texture->internalformat = GL_RGB5_A1;
|
| | 181 | + texture->format = GL_BGRA;
|
| | 182 | + texture->type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
| | 183 | + break;
|
| | 184 | + case 10: // 32-bit RGBA8888
|
| | 185 | + texture->internalformat = GL_RGBA8;
|
| | 186 | + texture->format = GL_BGRA;
|
| | 187 | + texture->type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| | 188 | + break;
|
| | 189 | + case 11: // 8-bit Luminance
|
| | 190 | + texture->internalformat = GL_LUMINANCE8;
|
| | 191 | + texture->format = GL_LUMINANCE;
|
| | 192 | + texture->type = GL_UNSIGNED_BYTE;
|
| | 193 | + break;
|
| | 194 | + case 12: // 8-bit Alpha
|
| | 195 | + texture->internalformat = GL_ALPHA8;
|
| | 196 | + texture->format = GL_ALPHA;
|
| | 197 | + texture->type = GL_UNSIGNED_BYTE;
|
| | 198 | + break;
|
| | 199 | + case 13: // 16-bit Luminance Alpha
|
| | 200 | + texture->internalformat = GL_LUMINANCE8_ALPHA8;
|
| | 201 | + texture->format = GL_LUMINANCE_ALPHA;
|
| | 202 | + texture->type = GL_UNSIGNED_BYTE;
|
| | 203 | + break;
|
| | 204 | + case 14: // 16-bit Z buffer
|
| | 205 | + texture->internalformat = GL_DEPTH_COMPONENT16;
|
| | 206 | + texture->format = GL_DEPTH_COMPONENT;
|
| | 207 | + texture->type = GL_UNSIGNED_SHORT;
|
| | 208 | + break;
|
| | 209 | + case 15: // 24-bit Z buffer
|
| | 210 | + texture->internalformat = GL_DEPTH_COMPONENT24;
|
| | 211 | + texture->format = GL_DEPTH_COMPONENT;
|
| | 212 | + texture->type = GL_UNSIGNED_INT;
|
| | 213 | + break;
|
| | 214 | + case 16: // 32/24 bit Z buffer
|
| | 215 | + texture->internalformat = GL_DEPTH_COMPONENT24;
|
| | 216 | + texture->format = GL_DEPTH_COMPONENT;
|
| | 217 | + texture->type = GL_UNSIGNED_INT;
|
| | 218 | + break;
|
| | 219 | + case 17: // 32-bit Z buffer
|
| | 220 | + texture->internalformat = GL_DEPTH_COMPONENT32;
|
| | 221 | + texture->format = GL_DEPTH_COMPONENT;
|
| | 222 | + texture->type = GL_UNSIGNED_INT;
|
| | 223 | + break;
|
| | 224 | + case 18: // 32-bit Z/Stencil buffer, depth LSB
|
| | 225 | + texture->internalformat = GL_DEPTH24_STENCIL8;
|
| | 226 | + texture->format = GL_DEPTH_STENCIL;
|
| | 227 | + texture->type = GL_UNSIGNED_INT_24_8;
|
| | 228 | + break;
|
| | 229 | + case 19: // 32-bit Z/Stencil buffer, depth MSB
|
| | 230 | + texture->internalformat = GL_DEPTH24_STENCIL8;
|
| | 231 | + texture->format = GL_DEPTH_STENCIL;
|
| | 232 | + texture->type = GL_UNSIGNED_INT_24_8;
|
| | 233 | + break;
|
| | 234 | + }
|
| | 235 | + texture->width = width;
|
| | 236 | + texture->height = height;
|
| | 237 | + glGenTextures(1,&texture->id);
|
| | 238 | + TextureManager_SetTexture(This,0,texture);
|
| | 239 | + glTexImage2D(GL_TEXTURE_2D,0,texture->internalformat,texture->width,texture->height,0,texture->format,texture->type,NULL);
|
| | 240 | + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,texture->minfilter);
|
| | 241 | + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,texture->magfilter);
|
| | 242 | + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,texture->wraps);
|
| | 243 | + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,texture->wrapt);
|
| | 244 | +}
|
| | 245 | +
|
| | 246 | +void TextureManager_DeleteTexture(TextureManager *This, TEXTURE *texture)
|
| | 247 | +{
|
| | 248 | + glDeleteTextures(1,&texture->id);
|
| | 249 | + texture->bordercolor = texture->format = texture->internalformat =
|
| | 250 | + texture->type = texture->width = texture->height = texture->magfilter =
|
| | 251 | + texture->minfilter = texture->miplevel = texture->wraps = texture->wrapt =
|
| | 252 | + texture->pbo = texture->id = 0;
|
| | 253 | +}
|
| | 254 | +
|
| | 255 | +void TextureManager_UploadTextureClassic(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height)
|
| | 256 | +{
|
| | 257 | + texture->width = width;
|
| | 258 | + texture->height = height;
|
| | 259 | + if(This->ext->GLEXT_EXT_direct_state_access) This->ext->glTextureImage2DEXT(texture->id,GL_TEXTURE_2D,level,texture->internalformat,
|
| | 260 | + width,height,0,texture->format,texture->type,data);
|
| | 261 | + else
|
| | 262 | + {
|
| | 263 | + TextureManager_SetActiveTexture(This, 0);
|
| | 264 | + TextureManager_SetTexture(This, 0,texture);
|
| | 265 | + glTexImage2D(GL_TEXTURE_2D,level,texture->internalformat,width,height,0,texture->format,texture->type,data);
|
| | 266 | + }
|
| | 267 | +}
|
| | 268 | +
|
| | 269 | +void TextureManager_DownloadTextureClassic(TextureManager *This, TEXTURE *texture, int level, void *data)
|
| | 270 | +{
|
| | 271 | + if(This->ext->GLEXT_EXT_direct_state_access) This->ext->glGetTextureImageEXT(texture->id,GL_TEXTURE_2D,level,texture->format,texture->type,data);
|
| | 272 | + else
|
| | 273 | + {
|
| | 274 | + TextureManager_SetActiveTexture(This, 0);
|
| | 275 | + TextureManager_SetTexture(This, 0,texture);
|
| | 276 | + glGetTexImage(GL_TEXTURE_2D,level,texture->format,texture->type,data);
|
| | 277 | + }
|
| | 278 | +}
|
| | 279 | +
|
| | 280 | +void TextureManager_SetActiveTexture(TextureManager *This, int level)
|
| | 281 | +{
|
| | 282 | + if(level != This->texlevel)
|
| | 283 | + {
|
| | 284 | + This->texlevel = level;
|
| | 285 | + This->ext->glActiveTexture(GL_TEXTURE0+level);
|
| | 286 | + }
|
| | 287 | +}
|
| | 288 | +
|
| | 289 | +
|
| | 290 | +void TextureManager_SetTexture(TextureManager *This, unsigned int level, TEXTURE *texture)
|
| | 291 | +{
|
| | 292 | + GLuint texname;
|
| | 293 | + if (level >= 16) return;
|
| | 294 | + if(!texture) texname = 0;
|
| | 295 | + else texname=texture->id;
|
| | 296 | + if(texname != This->textures[level])
|
| | 297 | + {
|
| | 298 | + TextureManager_SetActiveTexture(This, level);
|
| | 299 | + glBindTexture(GL_TEXTURE_2D,texname);
|
| | 300 | + }
|
| | 301 | +}
|
| | 302 | +
|
| | 303 | +
|
| | 304 | +
|
| | 305 | +/* old code
|
| | 306 | + if(ddsd.ddpfPixelFormat.dwFlags & DDPF_RGB)
|
| | 307 | + {
|
| | 308 | + switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
|
| | 309 | + {
|
| | 310 | + case 8:
|
| | 311 | + if(ddsd.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8)
|
| | 312 | + {
|
| | 313 | + texformat = GL_LUMINANCE;
|
| | 314 | + texformat2 = GL_UNSIGNED_BYTE;
|
| | 315 | + if(dxglcfg.texformat) texformat3 = GL_LUMINANCE8;
|
| | 316 | + else texformat3 = GL_RGBA8;
|
| | 317 | + if(!palettein) palette = new glDirectDrawPalette(DDPCAPS_8BIT|DDPCAPS_ALLOW256|DDPCAPS_PRIMARYSURFACE,NULL,NULL);
|
| | 318 | + bitmapinfo->bmiHeader.biBitCount = 8;
|
| | 319 | + }
|
| | 320 | + else
|
| | 321 | + {
|
| | 322 | + texformat = GL_RGB;
|
| | 323 | + texformat2 = GL_UNSIGNED_BYTE_3_3_2;
|
| | 324 | + if(dxglcfg.texformat) texformat3 = GL_R3_G3_B2;
|
| | 325 | + else texformat3 = GL_RGBA8;
|
| | 326 | + }
|
| | 327 | + ddsd.ddpfPixelFormat.dwRBitMask = 0;
|
| | 328 | + ddsd.ddpfPixelFormat.dwGBitMask = 0;
|
| | 329 | + ddsd.ddpfPixelFormat.dwBBitMask = 0;
|
| | 330 | + ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth);
|
| | 331 | + break;
|
| | 332 | + case 16:
|
| | 333 | + if((ddsd.ddpfPixelFormat.dwRBitMask == 0x7C00) && (ddsd.ddpfPixelFormat.dwGBitMask == 0x3E0)
|
| | 334 | + && (ddsd.ddpfPixelFormat.dwBBitMask == 0x1F))
|
| | 335 | + {
|
| | 336 | + texformat = GL_BGRA;
|
| | 337 | + texformat2 = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
| | 338 | + if(dxglcfg.texformat) texformat3 = GL_RGB5_A1;
|
| | 339 | + else texformat3 = GL_RGBA8;
|
| | 340 | + }
|
| | 341 | + else // fixme: support more formats
|
| | 342 | + {
|
| | 343 | + texformat = GL_RGB;
|
| | 344 | + texformat2 = GL_UNSIGNED_SHORT_5_6_5;
|
| | 345 | + if(dxglcfg.texformat) texformat3 = GL_RGB;
|
| | 346 | + else texformat3 = GL_RGBA8;
|
| | 347 | + }
|
| | 348 | + ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*2);
|
| | 349 | + break;
|
| | 350 | + case 24:
|
| | 351 | + if((ddsd.ddpfPixelFormat.dwRBitMask == 0xFF0000) && (ddsd.ddpfPixelFormat.dwGBitMask == 0xFF00)
|
| | 352 | + && (ddsd.ddpfPixelFormat.dwBBitMask == 0xFF))
|
| | 353 | + {
|
| | 354 | + texformat = GL_BGR;
|
| | 355 | + texformat2 = GL_UNSIGNED_BYTE;
|
| | 356 | + if(dxglcfg.texformat) texformat3 = GL_RGB8;
|
| | 357 | + else texformat3 = GL_RGBA8;
|
| | 358 | + }
|
| | 359 | + else // fixme: support more formats
|
| | 360 | + {
|
| | 361 | + texformat = GL_RGB;
|
| | 362 | + texformat2 = GL_UNSIGNED_BYTE;
|
| | 363 | + if(dxglcfg.texformat) texformat3 = GL_RGB8;
|
| | 364 | + else texformat3 = GL_RGBA8;
|
| | 365 | + }
|
| | 366 | + ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*3);
|
| | 367 | + break;
|
| | 368 | + case 32:
|
| | 369 | + default:
|
| | 370 | + if((ddsd.ddpfPixelFormat.dwRBitMask == 0xFF0000) && (ddsd.ddpfPixelFormat.dwGBitMask == 0xFF00)
|
| | 371 | + && (ddsd.ddpfPixelFormat.dwBBitMask == 0xFF))
|
| | 372 | + {
|
| | 373 | + texformat = GL_BGRA;
|
| | 374 | + texformat2 = GL_UNSIGNED_INT_8_8_8_8_REV;
|
| | 375 | + texformat3 = GL_RGBA8;
|
| | 376 | + }
|
| | 377 | + else // fixme: support more formats
|
| | 378 | + {
|
| | 379 | + texformat = GL_RGBA;
|
| | 380 | + texformat2 = GL_UNSIGNED_BYTE;
|
| | 381 | + texformat3 = GL_RGBA8;
|
| | 382 | + }
|
| | 383 | + ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*4);
|
| | 384 | + }
|
| | 385 | + }
|
| | 386 | + else if(ddsd.ddpfPixelFormat.dwFlags & DDPF_ZBUFFER)
|
| | 387 | + {
|
| | 388 | + switch(ddsd.ddpfPixelFormat.dwZBufferBitDepth)
|
| | 389 | + {
|
| | 390 | + case 16:
|
| | 391 | + default:
|
| | 392 | + texformat = GL_DEPTH_COMPONENT;
|
| | 393 | + texformat2 = GL_UNSIGNED_BYTE;
|
| | 394 | + texformat3 = GL_DEPTH_COMPONENT16;
|
| | 395 | + break;
|
| | 396 | + case 24:
|
| | 397 | + texformat = GL_DEPTH_COMPONENT;
|
| | 398 | + texformat2 = GL_UNSIGNED_BYTE;
|
| | 399 | + texformat3 = GL_DEPTH_COMPONENT24;
|
| | 400 | + break;
|
| | 401 | + case 32:
|
| | 402 | + if((ddsd.ddpfPixelFormat.dwRGBZBitMask == 0x00ffffff) &&
|
| | 403 | + !(ddsd.ddpfPixelFormat.dwFlags & DDPF_STENCILBUFFER))
|
| | 404 | + {
|
| | 405 | + texformat = GL_DEPTH_COMPONENT;
|
| | 406 | + texformat2 = GL_UNSIGNED_INT;
|
| | 407 | + texformat3 = GL_DEPTH_COMPONENT24;
|
| | 408 | + break;
|
| | 409 | + }
|
| | 410 | + else if(ddsd.ddpfPixelFormat.dwFlags & DDPF_STENCILBUFFER)
|
| | 411 | + {
|
| | 412 | + texformat = GL_DEPTH_STENCIL;
|
| | 413 | + texformat2 = GL_UNSIGNED_INT_24_8;
|
| | 414 | + texformat3 = GL_DEPTH24_STENCIL8;
|
| | 415 | + hasstencil = true;
|
| | 416 | + break;
|
| | 417 | + }
|
| | 418 | + else
|
| | 419 | + {
|
| | 420 | + texformat = GL_DEPTH_COMPONENT;
|
| | 421 | + texformat2 = GL_UNSIGNED_INT;
|
| | 422 | + texformat3 = GL_DEPTH_COMPONENT32;
|
| | 423 | + break;
|
| | 424 | + }
|
| | 425 | + }
|
| | 426 | + }
|
| | 427 | + }
|
| | 428 | +
|
| | 429 | +*/
|
| | 430 | +
|
| | 431 | +/*
|
| | 432 | + if(!(ddsd.dwFlags & DDSD_PIXELFORMAT))
|
| | 433 | + {
|
| | 434 | + ddsd.ddpfPixelFormat.dwRGBBitCount = ddInterface->GetBPP();
|
| | 435 | + switch(ddInterface->GetBPP())
|
| | 436 | + {
|
| | 437 | + case 8:
|
| | 438 | + texformat = GL_LUMINANCE;
|
| | 439 | + texformat2 = GL_UNSIGNED_BYTE;
|
| | 440 | + if(dxglcfg.texformat) texformat3 = GL_LUMINANCE8;
|
| | 441 | + else texformat3 = GL_RGBA8;
|
| | 442 | + ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8;
|
| | 443 | + ddsd.ddpfPixelFormat.dwRBitMask = 0;
|
| | 444 | + ddsd.ddpfPixelFormat.dwGBitMask = 0;
|
| | 445 | + ddsd.ddpfPixelFormat.dwBBitMask = 0;
|
| | 446 | + ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth);
|
| | 447 | + break;
|
| | 448 | + case 15:
|
| | 449 | + texformat = GL_BGRA;
|
| | 450 | + texformat2 = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
| | 451 | + if(dxglcfg.texformat) texformat3 = GL_RGB5_A1;
|
| | 452 | + else texformat3 = GL_RGBA8;
|
| | 453 | + ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
| | 454 | + ddsd.ddpfPixelFormat.dwRBitMask = 0x7C00;
|
| | 455 | + ddsd.ddpfPixelFormat.dwGBitMask = 0x3E0;
|
| | 456 | + ddsd.ddpfPixelFormat.dwBBitMask = 0x1F;
|
| | 457 | + ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*2);
|
| | 458 | + ddsd.ddpfPixelFormat.dwRGBBitCount = 16;
|
| | 459 | + break;
|
| | 460 | + case 16:
|
| | 461 | + texformat = GL_RGB;
|
| | 462 | + texformat2 = GL_UNSIGNED_SHORT_5_6_5;
|
| | 463 | + if(dxglcfg.texformat) texformat3 = GL_RGB;
|
| | 464 | + else texformat3 = GL_RGBA8;
|
| | 465 | + ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
| | 466 | + ddsd.ddpfPixelFormat.dwRBitMask = 0xF800;
|
| | 467 | + ddsd.ddpfPixelFormat.dwGBitMask = 0x7E0;
|
| | 468 | + ddsd.ddpfPixelFormat.dwBBitMask = 0x1F;
|
| | 469 | + ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*2);
|
| | 470 | + break;
|
| | 471 | + case 24:
|
| | 472 | + texformat = GL_BGR;
|
| | 473 | + texformat2 = GL_UNSIGNED_BYTE;
|
| | 474 | + if(dxglcfg.texformat) texformat3 = GL_RGB8;
|
| | 475 | + else texformat3 = GL_RGBA8;
|
| | 476 | + ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
| | 477 | + ddsd.ddpfPixelFormat.dwRBitMask = 0xFF0000;
|
| | 478 | + ddsd.ddpfPixelFormat.dwGBitMask = 0xFF00;
|
| | 479 | + ddsd.ddpfPixelFormat.dwBBitMask = 0xFF;
|
| | 480 | + ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*3);
|
| | 481 | + break;
|
| | 482 | + case 32:
|
| | 483 | + texformat = GL_BGRA;
|
| | 484 | + texformat2 = GL_UNSIGNED_BYTE;
|
| | 485 | + texformat3 = GL_RGBA8;
|
| | 486 | + ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
|
| | 487 | + ddsd.ddpfPixelFormat.dwRBitMask = 0xFF0000;
|
| | 488 | + ddsd.ddpfPixelFormat.dwGBitMask = 0xFF00;
|
| | 489 | + ddsd.ddpfPixelFormat.dwBBitMask = 0xFF;
|
| | 490 | + ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*4);
|
| | 491 | + break;
|
| | 492 | + default:
|
| | 493 | + *error = DDERR_INVALIDPIXELFORMAT;
|
| | 494 | + return;
|
| | 495 | + }
|
| | 496 | + }
|
| | 497 | +
|
| | 498 | +*/ |
| \ No newline at end of file |
| Index: ddraw/TextureManager.h |
| — | — | @@ -19,6 +19,10 @@ |
| 20 | 20 | #ifndef _TEXTURE_H
|
| 21 | 21 | #define _TEXTURE_H
|
| 22 | 22 |
|
| | 23 | +#ifdef __cplusplus
|
| | 24 | +extern "C" {
|
| | 25 | +#endif
|
| | 26 | +
|
| 23 | 27 | typedef struct
|
| 24 | 28 | {
|
| 25 | 29 | GLuint id;
|
| — | — | @@ -47,32 +51,32 @@ |
| 48 | 52 | } SAMPLER;
|
| 49 | 53 |
|
| 50 | 54 | extern const DDPIXELFORMAT texformats[];
|
| 51 | | -extern const int numtexformats;
|
| | 55 | +extern int numtexformats;
|
| 52 | 56 |
|
| 53 | | -class TextureManager
|
| | 57 | +typedef struct TextureManager
|
| 54 | 58 | {
|
| 55 | | -public:
|
| 56 | | - TextureManager(glExtensions *glext);
|
| 57 | | - void InitSamplers();
|
| 58 | | - void DeleteSamplers();
|
| 59 | | - void SetActiveTexture(int level);
|
| 60 | | - void SetTexture(unsigned int level, TEXTURE *texture);
|
| 61 | | -
|
| 62 | | - void _CreateTexture(TEXTURE *texture, int width, int height);
|
| 63 | | - void _DeleteTexture(TEXTURE *texture);
|
| 64 | | - void _UploadTexture(TEXTURE *texture, int level, const void *data, int width, int height);
|
| 65 | | - void _DownloadTexture(TEXTURE *texture, int level, void *data);
|
| 66 | | -
|
| 67 | 59 | SAMPLER samplers[8];
|
| 68 | | -
|
| 69 | | -private:
|
| 70 | | - void CreateTextureClassic(TEXTURE *texture, int width, int height);
|
| 71 | | - void DeleteTexture(TEXTURE *texture);
|
| 72 | | - void UploadTextureClassic(TEXTURE *texture, int level, const void *data, int width, int height);
|
| 73 | | - void DownloadTextureClassic(TEXTURE *texture, int level, void *data);
|
| 74 | 60 | glExtensions *ext;
|
| 75 | 61 | GLint texlevel;
|
| 76 | 62 | GLuint textures[16];
|
| 77 | | -};
|
| | 63 | +} TextureManager;
|
| 78 | 64 |
|
| | 65 | +TextureManager *TextureManager_Create(glExtensions *glext);
|
| | 66 | +void TextureManager_InitSamplers(TextureManager *This);
|
| | 67 | +void TextureManager_DeleteSamplers(TextureManager *This);
|
| | 68 | +void TextureManager_SetActiveTexture(TextureManager *This, int level);
|
| | 69 | +void TextureManager_SetTexture(TextureManager *This, unsigned int level, TEXTURE *texture);
|
| | 70 | +void TextureManager__CreateTexture(TextureManager *This, TEXTURE *texture, int width, int height);
|
| | 71 | +void TextureManager__DeleteTexture(TextureManager *This, TEXTURE *texture);
|
| | 72 | +void TextureManager__UploadTexture(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height);
|
| | 73 | +void TextureManager__DownloadTexture(TextureManager *This, TEXTURE *texture, int level, void *data);
|
| | 74 | +void TextureManager_CreateTextureClassic(TextureManager *This, TEXTURE *texture, int width, int height);
|
| | 75 | +void TextureManager_DeleteTexture(TextureManager *This, TEXTURE *texture);
|
| | 76 | +void TextureManager_UploadTextureClassic(TextureManager *This, TEXTURE *texture, int level, const void *data, int width, int height);
|
| | 77 | +void TextureManager_DownloadTextureClassic(TextureManager *This, TEXTURE *texture, int level, void *data);
|
| | 78 | +
|
| | 79 | +#ifdef __cplusplus
|
| | 80 | +}
|
| | 81 | +#endif
|
| | 82 | +
|
| 79 | 83 | #endif //_TEXTURE_H |
| \ No newline at end of file |
| Index: ddraw/ddraw.vcxproj |
| — | — | @@ -376,7 +376,14 @@ |
| 377 | 377 | <ClCompile Include="ShaderGen3D.cpp" />
|
| 378 | 378 | <ClCompile Include="shadergen2d.cpp" />
|
| 379 | 379 | <ClCompile Include="ShaderManager.cpp" />
|
| 380 | | - <ClCompile Include="TextureManager.cpp" />
|
| | 380 | + <ClCompile Include="TextureManager.c">
|
| | 381 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
| | 382 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
|
| | 383 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
| | 384 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
| | 385 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">NotUsing</PrecompiledHeader>
|
| | 386 | + <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug No MSVCRT|Win32'">NotUsing</PrecompiledHeader>
|
| | 387 | + </ClCompile>
|
| 381 | 388 | <ClCompile Include="timer.cpp" />
|
| 382 | 389 | <ClCompile Include="trace.c">
|
| 383 | 390 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Trace|Win32'">NotUsing</PrecompiledHeader>
|
| Index: ddraw/ddraw.vcxproj.filters |
| — | — | @@ -208,9 +208,6 @@ |
| 209 | 209 | <ClCompile Include="shadergen2d.cpp">
|
| 210 | 210 | <Filter>Source Files</Filter>
|
| 211 | 211 | </ClCompile>
|
| 212 | | - <ClCompile Include="TextureManager.cpp">
|
| 213 | | - <Filter>Source Files</Filter>
|
| 214 | | - </ClCompile>
|
| 215 | 212 | <ClCompile Include="glUtil.cpp">
|
| 216 | 213 | <Filter>Source Files</Filter>
|
| 217 | 214 | </ClCompile>
|
| — | — | @@ -229,6 +226,9 @@ |
| 230 | 227 | <ClCompile Include="glDirectDrawPalette.c">
|
| 231 | 228 | <Filter>Source Files</Filter>
|
| 232 | 229 | </ClCompile>
|
| | 230 | + <ClCompile Include="TextureManager.c">
|
| | 231 | + <Filter>Source Files</Filter>
|
| | 232 | + </ClCompile>
|
| 233 | 233 | </ItemGroup>
|
| 234 | 234 | <ItemGroup>
|
| 235 | 235 | <ResourceCompile Include="ddraw.rc">
|
| Index: ddraw/glDirectDrawSurface.cpp |
| — | — | @@ -1436,7 +1436,7 @@ |
| 1437 | 1437 | }
|
| 1438 | 1438 | else
|
| 1439 | 1439 | {
|
| 1440 | | - texman->SetTexture(level,texture);
|
| | 1440 | + TextureManager_SetTexture(texman,level,texture);
|
| 1441 | 1441 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,mag);
|
| 1442 | 1442 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,min);
|
| 1443 | 1443 | }
|
| Index: ddraw/glRenderer.cpp |
| — | — | @@ -100,7 +100,7 @@ |
| 101 | 101 | if(bpp == 15) bpp = 16;
|
| 102 | 102 | if((x == bigx && y == bigy) || !bigbuffer)
|
| 103 | 103 | {
|
| 104 | | - texman->_UploadTexture(texture, 0, buffer, x, y);
|
| | 104 | + TextureManager__UploadTexture(texman, texture, 0, buffer, x, y);
|
| 105 | 105 | }
|
| 106 | 106 | else
|
| 107 | 107 | {
|
| — | — | @@ -120,7 +120,7 @@ |
| 121 | 121 | break;
|
| 122 | 122 | break;
|
| 123 | 123 | }
|
| 124 | | - texman->_UploadTexture(texture,0,bigbuffer,bigx,bigy);
|
| | 124 | + TextureManager__UploadTexture(texman,texture,0,bigbuffer,bigx,bigy);
|
| 125 | 125 | }
|
| 126 | 126 | }
|
| 127 | 127 |
|
| — | — | @@ -149,11 +149,11 @@ |
| 150 | 150 | {
|
| 151 | 151 | if((bigx == x && bigy == y) || !bigbuffer)
|
| 152 | 152 | {
|
| 153 | | - texman->_DownloadTexture(texture,0,buffer);
|
| | 153 | + TextureManager__DownloadTexture(texman,texture,0,buffer);
|
| 154 | 154 | }
|
| 155 | 155 | else
|
| 156 | 156 | {
|
| 157 | | - texman->_DownloadTexture(texture,0,bigbuffer);
|
| | 157 | + TextureManager__DownloadTexture(texman,texture,0,bigbuffer);
|
| 158 | 158 | switch(bpp)
|
| 159 | 159 | {
|
| 160 | 160 | case 8:
|
| — | — | @@ -638,7 +638,7 @@ |
| 639 | 639 | if(dib.hdc) DeleteDC(dib.hdc);
|
| 640 | 640 | ZeroMemory(&dib,sizeof(DIB));
|
| 641 | 641 | }
|
| 642 | | - texman->DeleteSamplers();
|
| | 642 | + TextureManager_DeleteSamplers(texman);
|
| 643 | 643 | util->DeleteFBO(&fbo);
|
| 644 | 644 | if(PBO)
|
| 645 | 645 | {
|
| — | — | @@ -648,7 +648,7 @@ |
| 649 | 649 | }
|
| 650 | 650 | if(backbuffer)
|
| 651 | 651 | {
|
| 652 | | - texman->_DeleteTexture(backbuffer);
|
| | 652 | + TextureManager__DeleteTexture(texman,backbuffer);
|
| 653 | 653 | delete backbuffer;
|
| 654 | 654 | backbuffer = NULL;
|
| 655 | 655 | backx = 0;
|
| — | — | @@ -655,7 +655,7 @@ |
| 656 | 656 | backy = 0;
|
| 657 | 657 | }
|
| 658 | 658 | delete shaders;
|
| 659 | | - delete texman;
|
| | 659 | + free(texman);
|
| 660 | 660 | free(ext);
|
| 661 | 661 | delete util;
|
| 662 | 662 | ext = NULL;
|
| — | — | @@ -835,8 +835,8 @@ |
| 836 | 836 | util->SetCull(D3DCULL_CCW);
|
| 837 | 837 | glEnable(GL_CULL_FACE);
|
| 838 | 838 | SwapBuffers(hDC);
|
| 839 | | - texman = new TextureManager(ext);
|
| 840 | | - texman->SetActiveTexture(0);
|
| | 839 | + texman = TextureManager_Create(ext);
|
| | 840 | + TextureManager_SetActiveTexture(texman,0);
|
| 841 | 841 | _SetFogColor(0);
|
| 842 | 842 | _SetFogStart(0);
|
| 843 | 843 | _SetFogEnd(1);
|
| — | — | @@ -864,7 +864,7 @@ |
| 865 | 865 | ext->glBindBuffer(GL_PIXEL_PACK_BUFFER,PBO);
|
| 866 | 866 | ext->glBufferData(GL_PIXEL_PACK_BUFFER,width*height*4,NULL,GL_STREAM_READ);
|
| 867 | 867 | ext->glBindBuffer(GL_PIXEL_PACK_BUFFER,0);
|
| 868 | | - texman->InitSamplers();
|
| | 868 | + TextureManager_InitSamplers(texman);
|
| 869 | 869 | TRACE_SYSINFO();
|
| 870 | 870 | return TRUE;
|
| 871 | 871 | }
|
| — | — | @@ -991,7 +991,7 @@ |
| 992 | 992 | }
|
| 993 | 993 | if(src)
|
| 994 | 994 | {
|
| 995 | | - texman->SetTexture(0,src->GetTexture());
|
| | 995 | + TextureManager_SetTexture(texman,0,src->GetTexture());
|
| 996 | 996 | if(ext->GLEXT_ARB_sampler_objects)
|
| 997 | 997 | {
|
| 998 | 998 | if((dxglcfg.scalingfilter == 0) || (ddInterface->GetBPP() == 8)) src->SetFilter(0,GL_NEAREST,GL_NEAREST,ext,texman);
|
| — | — | @@ -998,7 +998,7 @@ |
| 999 | 999 | else src->SetFilter(0,GL_LINEAR,GL_LINEAR,ext,texman);
|
| 1000 | 1000 | }
|
| 1001 | 1001 | }
|
| 1002 | | - else texman->SetTexture(0,NULL);
|
| | 1002 | + else TextureManager_SetTexture(texman,0,NULL);
|
| 1003 | 1003 | ext->glUniform4f(shaders->shaders[progtype].view,0,(GLfloat)dest->fakex,0,(GLfloat)dest->fakey);
|
| 1004 | 1004 | dest->dirty |= 2;
|
| 1005 | 1005 | util->EnableArray(shaders->shaders[progtype].pos,true);
|
| — | — | @@ -1027,13 +1027,13 @@ |
| 1028 | 1028 |
|
| 1029 | 1029 | void glRenderer::_MakeTexture(TEXTURE *texture, DWORD width, DWORD height)
|
| 1030 | 1030 | {
|
| 1031 | | - texman->_CreateTexture(texture,width,height);
|
| | 1031 | + TextureManager__CreateTexture(texman,texture,width,height);
|
| 1032 | 1032 | }
|
| 1033 | 1033 |
|
| 1034 | 1034 | void glRenderer::_DrawBackbuffer(TEXTURE **texture, int x, int y, int progtype)
|
| 1035 | 1035 | {
|
| 1036 | 1036 | GLfloat view[4];
|
| 1037 | | - texman->SetActiveTexture(0);
|
| | 1037 | + TextureManager_SetActiveTexture(texman,0);
|
| 1038 | 1038 | if(!backbuffer)
|
| 1039 | 1039 | {
|
| 1040 | 1040 | backbuffer = new TEXTURE;
|
| — | — | @@ -1045,13 +1045,13 @@ |
| 1046 | 1046 | backbuffer->pixelformat.dwGBitMask = 0xFF00;
|
| 1047 | 1047 | backbuffer->pixelformat.dwRBitMask = 0xFF0000;
|
| 1048 | 1048 | backbuffer->pixelformat.dwRGBBitCount = 32;
|
| 1049 | | - texman->_CreateTexture(backbuffer,x,y);
|
| | 1049 | + TextureManager__CreateTexture(texman,backbuffer,x,y);
|
| 1050 | 1050 | backx = x;
|
| 1051 | 1051 | backy = y;
|
| 1052 | 1052 | }
|
| 1053 | 1053 | if((backx != x) || (backy != y))
|
| 1054 | 1054 | {
|
| 1055 | | - texman->_UploadTexture(backbuffer,0,NULL,x,y);
|
| | 1055 | + TextureManager__UploadTexture(texman,backbuffer,0,NULL,x,y);
|
| 1056 | 1056 | backx = x;
|
| 1057 | 1057 | backy = y;
|
| 1058 | 1058 | }
|
| — | — | @@ -1061,7 +1061,7 @@ |
| 1062 | 1062 | view[3] = (GLfloat)y;
|
| 1063 | 1063 | util->SetViewport(0,0,x,y);
|
| 1064 | 1064 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
| 1065 | | - texman->SetTexture(0,*texture);
|
| | 1065 | + TextureManager_SetTexture(texman,0,*texture);
|
| 1066 | 1066 | *texture = backbuffer;
|
| 1067 | 1067 | if(ext->GLEXT_ARB_sampler_objects) ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR,ext,texman);
|
| 1068 | 1068 | ext->glUniform4f(shaders->shaders[progtype].view,view[0],view[1],view[2],view[3]);
|
| — | — | @@ -1145,17 +1145,17 @@ |
| 1146 | 1146 | {
|
| 1147 | 1147 | shaders->SetShader(PROG_PAL256,NULL,NULL,0);
|
| 1148 | 1148 | progtype = PROG_PAL256;
|
| 1149 | | - texman->_UploadTexture(paltex,0,glDirectDrawPalette_GetPalette(dest->palette,NULL),256,1);
|
| | 1149 | + TextureManager__UploadTexture(texman,paltex,0,glDirectDrawPalette_GetPalette(dest->palette,NULL),256,1);
|
| 1150 | 1150 | ext->glUniform1i(shaders->shaders[progtype].tex0,0);
|
| 1151 | 1151 | ext->glUniform1i(shaders->shaders[progtype].pal,1);
|
| 1152 | | - texman->SetTexture(0,texture);
|
| 1153 | | - texman->SetTexture(1,paltex);
|
| | 1152 | + TextureManager_SetTexture(texman,0,texture);
|
| | 1153 | + TextureManager_SetTexture(texman,1,paltex);
|
| 1154 | 1154 | if(dxglcfg.scalingfilter)
|
| 1155 | 1155 | {
|
| 1156 | 1156 | _DrawBackbuffer(&texture,dest->fakex,dest->fakey,progtype);
|
| 1157 | 1157 | shaders->SetShader(PROG_TEXTURE,NULL,NULL,0);
|
| 1158 | 1158 | progtype = PROG_TEXTURE;
|
| 1159 | | - texman->SetTexture(0,texture);
|
| | 1159 | + TextureManager_SetTexture(texman,0,texture);
|
| 1160 | 1160 | ext->glUniform1i(shaders->shaders[progtype].tex0,0);
|
| 1161 | 1161 | }
|
| 1162 | 1162 | if(ext->GLEXT_ARB_sampler_objects)
|
| — | — | @@ -1168,7 +1168,7 @@ |
| 1169 | 1169 | {
|
| 1170 | 1170 | shaders->SetShader(PROG_TEXTURE,NULL,NULL,0);
|
| 1171 | 1171 | progtype = PROG_TEXTURE;
|
| 1172 | | - texman->SetTexture(0,texture);
|
| | 1172 | + TextureManager_SetTexture(texman,0,texture);
|
| 1173 | 1173 | ext->glUniform1i(shaders->shaders[progtype].tex0,0);
|
| 1174 | 1174 | }
|
| 1175 | 1175 | if(dxglcfg.scalingfilter && ext->GLEXT_ARB_sampler_objects) ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR,ext,texman);
|
| — | — | @@ -1240,7 +1240,7 @@ |
| 1241 | 1241 |
|
| 1242 | 1242 | void glRenderer::_DeleteTexture(TEXTURE *texture)
|
| 1243 | 1243 | {
|
| 1244 | | - texman->_DeleteTexture(texture);
|
| | 1244 | + TextureManager__DeleteTexture(texman,texture);
|
| 1245 | 1245 | SetEvent(busy);
|
| 1246 | 1246 | }
|
| 1247 | 1247 |
|
| — | — | @@ -1616,11 +1616,11 @@ |
| 1617 | 1617 | }
|
| 1618 | 1618 | if(device->texstages[i].texture)
|
| 1619 | 1619 | device->texstages[i].texture->SetFilter(i,device->texstages[i].glmagfilter,device->texstages[i].glminfilter,ext,texman);
|
| 1620 | | - texman->SetTexture(i,device->texstages[i].texture->texture);
|
| | 1620 | + TextureManager_SetTexture(texman,i,device->texstages[i].texture->texture);
|
| 1621 | 1621 | util->SetWrap(i,0,device->texstages[i].addressu,texman);
|
| 1622 | 1622 | util->SetWrap(i,1,device->texstages[i].addressv,texman);
|
| 1623 | 1623 | }
|
| 1624 | | - else texman->SetTexture(i,0);
|
| | 1624 | + TextureManager_SetTexture(texman,i,0);
|
| 1625 | 1625 | ext->glUniform1i(prog.uniforms[128+i],i);
|
| 1626 | 1626 | if(device->renderstate[D3DRENDERSTATE_COLORKEYENABLE] && device->texstages[i].texture && (prog.uniforms[142+i] != -1))
|
| 1627 | 1627 | {
|
| Index: ddraw/glUtil.cpp |
| — | — | @@ -238,7 +238,7 @@ |
| 239 | 239 | }
|
| 240 | 240 | else
|
| 241 | 241 | {
|
| 242 | | - texman->SetActiveTexture(level);
|
| | 242 | + TextureManager_SetActiveTexture(texman,level);
|
| 243 | 243 | if(coord) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,wrapmode);
|
| 244 | 244 | else glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,wrapmode);
|
| 245 | 245 | }
|