this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added GPU_FormatEnum and changed GPU_CreateImage() to use it instead of channels. Don't expect any of the new formats to work yet...

grimfang4 a49f9df0 c6a6a351

+139 -56
+88 -27
SDL_gpu/GL_common/SDL_gpu_GL_common.inl
··· 1425 1425 } 1426 1426 1427 1427 1428 - static GPU_Image* CreateUninitializedImage(GPU_Renderer* renderer, Uint16 w, Uint16 h, Uint8 channels) 1428 + static GPU_Image* CreateUninitializedImage(GPU_Renderer* renderer, Uint16 w, Uint16 h, GPU_FormatEnum format) 1429 1429 { 1430 - if(channels < 3 || channels > 4) 1430 + GLuint handle, channels; 1431 + GLenum gl_format; 1432 + switch(format) 1433 + { 1434 + case GPU_FORMAT_LUMINANCE: 1435 + gl_format = GL_LUMINANCE; 1436 + channels = 1; 1437 + break; 1438 + case GPU_FORMAT_LUMINANCE_ALPHA: 1439 + gl_format = GL_LUMINANCE_ALPHA; 1440 + channels = 2; 1441 + break; 1442 + case GPU_FORMAT_RGB: 1443 + gl_format = GL_RGB; 1444 + channels = 3; 1445 + break; 1446 + case GPU_FORMAT_RGBA: 1447 + gl_format = GL_RGBA; 1448 + channels = 4; 1449 + break; 1450 + case GPU_FORMAT_ALPHA: 1451 + gl_format = GL_ALPHA; 1452 + channels = 1; 1453 + break; 1454 + case GPU_FORMAT_RG: 1455 + gl_format = GL_RG; 1456 + channels = 2; 1457 + break; 1458 + case GPU_FORMAT_YCbCr420P: 1459 + gl_format = GL_RGB; 1460 + channels = 3; 1461 + break; 1462 + case GPU_FORMAT_YCbCr422: 1463 + gl_format = GL_RGB; 1464 + channels = 3; 1465 + break; 1466 + } 1467 + 1468 + if(channels < 1 || channels > 4) 1431 1469 { 1432 1470 GPU_PushErrorCode("GPU_CreateUninitializedImage", GPU_ERROR_DATA_ERROR, "Unsupported number of color channels"); 1433 1471 return NULL; 1434 1472 } 1435 1473 1436 - GLuint handle; 1437 - GLenum format; 1438 - if(channels == 3) 1439 - format = GL_RGB; 1440 - else 1441 - format = GL_RGBA; 1442 - 1443 1474 glGenTextures( 1, &handle ); 1444 1475 if(handle == 0) 1445 1476 { ··· 1466 1497 data->refcount = 1; 1467 1498 result->target = NULL; 1468 1499 result->renderer = renderer; 1500 + result->format = format; 1469 1501 result->channels = channels; 1470 1502 result->has_mipmaps = 0; 1471 1503 1472 1504 SDL_Color white = {255, 255, 255, 255}; 1473 1505 result->color = white; 1474 - result->use_blending = (channels > 3? 1 : 0); 1506 + result->use_blending = ((format == GPU_FORMAT_LUMINANCE_ALPHA || format == GPU_FORMAT_RGBA)? 1 : 0); 1475 1507 result->blend_mode = GPU_BLEND_NORMAL; 1476 1508 result->filter_mode = GPU_LINEAR; 1477 1509 result->wrap_mode_x = GPU_CLAMP_TO_EDGE; ··· 1480 1512 result->data = data; 1481 1513 result->is_alias = 0; 1482 1514 data->handle = handle; 1483 - data->format = format; 1515 + data->format = gl_format; 1484 1516 1485 1517 result->w = w; 1486 1518 result->h = h; ··· 1492 1524 } 1493 1525 1494 1526 1495 - static GPU_Image* CreateImage(GPU_Renderer* renderer, Uint16 w, Uint16 h, Uint8 channels) 1527 + static GPU_Image* CreateImage(GPU_Renderer* renderer, Uint16 w, Uint16 h, GPU_FormatEnum format) 1496 1528 { 1497 - if(channels < 3 || channels > 4) 1529 + if(format < 1 || format > GPU_FORMAT_RGBA) 1498 1530 { 1499 - GPU_PushErrorCode("GPU_CreateImage", GPU_ERROR_DATA_ERROR, "Unsupported number of color channels"); 1531 + GPU_PushErrorCode("GPU_CreateImage", GPU_ERROR_DATA_ERROR, "Unsupported image format"); 1500 1532 return NULL; 1501 1533 } 1502 1534 1503 - GPU_Image* result = CreateUninitializedImage(renderer, w, h, channels); 1535 + GPU_Image* result = CreateUninitializedImage(renderer, w, h, format); 1504 1536 1505 1537 if(result == NULL) 1506 1538 { ··· 1639 1671 memcpy(top, bottom, pitch); 1640 1672 memcpy(bottom, copy, pitch); 1641 1673 } 1674 + free(copy); 1642 1675 1643 1676 return data; 1644 1677 } ··· 2212 2245 if(image == NULL) 2213 2246 return NULL; 2214 2247 2215 - GPU_Image* result = CreateUninitializedImage(renderer, image->w, image->h, image->channels); 2248 + GPU_Image* result = CreateUninitializedImage(renderer, image->w, image->h, image->format); 2216 2249 if(result == NULL) 2217 2250 return NULL; 2218 2251 ··· 2325 2358 static GPU_Image* CopyImageFromSurface(GPU_Renderer* renderer, SDL_Surface* surface) 2326 2359 { 2327 2360 const SDL_PixelFormat *fmt; 2328 - Uint8 needAlpha; 2361 + Uint8 needAlpha, hasAlpha; 2329 2362 GPU_Image* image; 2330 2363 int channels; 2364 + GPU_FormatEnum format = GPU_FORMAT_RGBA; 2331 2365 2332 2366 if(!surface) 2333 2367 { ··· 2337 2371 2338 2372 /* See what the best texture format is */ 2339 2373 fmt = surface->format; 2340 - if (fmt->Amask || hasColorkey(surface)) { 2374 + hasAlpha = (fmt->Amask != 0); 2375 + if(!hasAlpha) 2376 + { 2377 + if(hasColorkey(surface)) 2378 + needAlpha = 1; 2379 + else 2380 + needAlpha = 0; 2381 + } 2382 + else 2341 2383 needAlpha = 1; 2342 - } else { 2343 - needAlpha = 0; 2344 - } 2345 2384 2346 2385 // Get appropriate storage format 2347 - // TODO: More options would be nice... 2348 - if(needAlpha) 2386 + channels = fmt->BytesPerPixel; 2387 + if(channels < 1 || channels > 4) 2349 2388 { 2350 - channels = 4; 2389 + GPU_PushErrorCode("GPU_CopyImageFromSurface", GPU_ERROR_DATA_ERROR, "Unsupported number of channels in surface"); 2390 + return NULL; 2351 2391 } 2352 - else 2392 + 2393 + switch(channels) 2353 2394 { 2354 - channels = 3; 2395 + case 1: 2396 + if(hasAlpha) 2397 + format = GPU_FORMAT_ALPHA; 2398 + else 2399 + format = GPU_FORMAT_LUMINANCE; 2400 + break; 2401 + case 2: 2402 + if(hasAlpha) 2403 + format = GPU_FORMAT_LUMINANCE_ALPHA; 2404 + else 2405 + format = GPU_FORMAT_RG; 2406 + break; 2407 + case 3: 2408 + if(needAlpha) 2409 + format = GPU_FORMAT_RGBA; 2410 + else 2411 + format = GPU_FORMAT_RGB; 2412 + break; 2413 + case 4: 2414 + format = GPU_FORMAT_RGBA; 2415 + break; 2355 2416 } 2356 2417 2357 2418 //GPU_LogError("Format... Channels: %d, BPP: %d, Masks: %X %X %X %X\n", channels, fmt->BytesPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask); 2358 2419 2359 2420 //Uint32 pix = getPixel(surface, surface->w/2, surface->h/2); 2360 2421 //GPU_LogError("Middle pixel: %X\n", pix); 2361 - image = CreateUninitializedImage(renderer, surface->w, surface->h, channels); 2422 + image = CreateUninitializedImage(renderer, surface->w, surface->h, format); 2362 2423 if(image == NULL) 2363 2424 return NULL; 2364 2425
+30 -23
SDL_gpu/SDL_gpu.c
··· 423 423 return current_renderer->SetCamera(current_renderer, target, cam); 424 424 } 425 425 426 - GPU_Image* GPU_CreateImage(Uint16 w, Uint16 h, Uint8 channels) 426 + GPU_Image* GPU_CreateImage(Uint16 w, Uint16 h, GPU_FormatEnum format) 427 427 { 428 428 if(current_renderer == NULL || current_renderer->current_context_target == NULL || current_renderer->CreateImage == NULL) 429 429 return NULL; 430 430 431 - return current_renderer->CreateImage(current_renderer, w, h, channels); 431 + return current_renderer->CreateImage(current_renderer, w, h, format); 432 432 } 433 433 434 434 GPU_Image* GPU_LoadImage(const char* filename) ··· 512 512 GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, stbi_failure_reason()); 513 513 return NULL; 514 514 } 515 - if(channels < 3 || channels > 4) 515 + if(channels < 1 || channels > 4) 516 516 { 517 517 GPU_PushErrorCode(__func__, GPU_ERROR_DATA_ERROR, "Unsupported pixel format"); 518 518 stbi_image_free(data); 519 519 return NULL; 520 520 } 521 - 522 - if(channels == 3) 523 - { 524 - // These are reversed from what SDL_image uses... That is bad. :( Needs testing. 525 - #if SDL_BYTEORDER == SDL_BIG_ENDIAN 526 - Rmask = 0xff0000; 527 - Gmask = 0x00ff00; 528 - Bmask = 0x0000ff; 529 - #else 530 - Rmask = 0x0000ff; 531 - Gmask = 0x00ff00; 532 - Bmask = 0xff0000; 533 - #endif 534 - } 535 - else 536 - { 537 - Rmask = 0x000000ff; 538 - Gmask = 0x0000ff00; 539 - Bmask = 0x00ff0000; 540 - Amask = 0xff000000; 521 + 522 + switch(channels) 523 + { 524 + case 1: 525 + Rmask = Gmask = Bmask = 0; // Use default RGB masks for 8-bit 526 + break; 527 + case 2: 528 + Rmask = Gmask = Bmask = 0; // Use default RGB masks for 16-bit 529 + break; 530 + case 3: 531 + // These are reversed from what SDL_image uses... That is bad. :( Needs testing. 532 + #if SDL_BYTEORDER == SDL_BIG_ENDIAN 533 + Rmask = 0xff0000; 534 + Gmask = 0x00ff00; 535 + Bmask = 0x0000ff; 536 + #else 537 + Rmask = 0x0000ff; 538 + Gmask = 0x00ff00; 539 + Bmask = 0xff0000; 540 + #endif 541 + break; 542 + case 4: 543 + Rmask = 0x000000ff; 544 + Gmask = 0x0000ff00; 545 + Bmask = 0x00ff0000; 546 + Amask = 0xff000000; 547 + break; 541 548 } 542 549 543 550 SDL_Surface* result = SDL_CreateRGBSurfaceFrom(data, width, height, channels*8, width*channels, Rmask, Gmask, Bmask, Amask);
+21 -6
SDL_gpu/SDL_gpu.h
··· 98 98 GPU_BLEND_PUNCHOUT = 10, 99 99 GPU_BLEND_CUTOUT = 11, 100 100 GPU_BLEND_OVERRIDE = 100 // Lets you specify direct GL calls before blitting. Note: You should call GPU_FlushBlitBuffer() before you change blend modes via OpenGL so the new blend mode doesn't affect SDL_gpu's previously buffered blits. 101 - } GPU_BlendEnum; 101 + } GPU_BlendEnum; 102 + 103 + /*! Image format enum 104 + * \see GPU_CreateImage() 105 + */ 106 + typedef enum { 107 + GPU_FORMAT_LUMINANCE = 1, 108 + GPU_FORMAT_LUMINANCE_ALPHA = 2, 109 + GPU_FORMAT_RGB = 3, 110 + GPU_FORMAT_RGBA = 4, 111 + GPU_FORMAT_ALPHA = 5, 112 + GPU_FORMAT_RG = 6, 113 + GPU_FORMAT_YCbCr422 = 7, 114 + GPU_FORMAT_YCbCr420P = 8 115 + } GPU_FormatEnum; 102 116 103 117 /*! Image object for containing pixel/texture data. 104 118 * A GPU_Image can be created with GPU_CreateImage(), GPU_LoadImage(), GPU_CopyImage(), or GPU_CopyImageFromSurface(). ··· 113 127 { 114 128 struct GPU_Renderer* renderer; 115 129 GPU_Target* target; 116 - Uint16 w, h; 130 + Uint16 w, h; 131 + GPU_FormatEnum format; 117 132 int channels; 118 133 Uint32 texture_w, texture_h; // Underlying texture dimensions 119 134 Uint8 has_mipmaps; ··· 466 481 GPU_Camera (*SetCamera)(GPU_Renderer* renderer, GPU_Target* target, GPU_Camera* cam); 467 482 468 483 /*! \see GPU_CreateImage() */ 469 - GPU_Image* (*CreateImage)(GPU_Renderer* renderer, Uint16 w, Uint16 h, Uint8 channels); 484 + GPU_Image* (*CreateImage)(GPU_Renderer* renderer, Uint16 w, Uint16 h, GPU_FormatEnum format); 470 485 471 486 /*! \see GPU_LoadImage() */ 472 487 GPU_Image* (*LoadImage)(GPU_Renderer* renderer, const char* filename); ··· 1009 1024 1010 1025 // Image controls 1011 1026 1012 - /*! Create a new, blank image with a format determined by the number of channels requested. Don't forget to GPU_FreeImage() it. 1027 + /*! Create a new, blank image with the given format. Don't forget to GPU_FreeImage() it. 1013 1028 * \param w Image width in pixels 1014 1029 * \param h Image height in pixels 1015 - * \param channels Number of color channels. Usually in the range of [1,4] with 3 being RGB and 4 being RGBA. 1030 + * \param format Format of color channels. 1016 1031 */ 1017 - GPU_Image* GPU_CreateImage(Uint16 w, Uint16 h, Uint8 channels); 1032 + GPU_Image* GPU_CreateImage(Uint16 w, Uint16 h, GPU_FormatEnum format); 1018 1033 1019 1034 /*! Load image from an image file that is supported by this renderer. Don't forget to GPU_FreeImage() it. */ 1020 1035 GPU_Image* GPU_LoadImage(const char* filename);