Add helpers: RageDisplay::CreateSurfaceFromPixfmt, RageDisplay::FindPixelFormat.
UpdateTexture can now take any image format; it doesn't have to match the original format, or even be a standard pixel format. This is because we can often do the conversion much more efficiently within UpdateTexture than we can in the caller. With D3D, we can convert any source format as we copy, preventing an extra blit. OpenGL can do it on the fly if it happens to be a known texture format. We can figure out the pixel format from the image itself, so there's no need to pass pixfmt to UpdateTexture. Add BGR8, for movies with OpenGL.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "RageMath.h"
|
||||
#include "RageUtil.h"
|
||||
#include "GameConstantsAndTypes.h"
|
||||
#include "SDL_utils.h"
|
||||
|
||||
//
|
||||
// Statistics stuff
|
||||
@@ -566,3 +567,35 @@ RageMatrix RageDisplay::GetPerspectiveMatrix(float fovy, float aspect, float zNe
|
||||
|
||||
return GetFrustrumMatrix(xmin, xmax, ymin, ymax, zNear, zFar);
|
||||
}
|
||||
|
||||
SDL_Surface *RageDisplay::CreateSurfaceFromPixfmt( PixelFormat pixfmt,
|
||||
void *pixels, int width, int height, int pitch )
|
||||
{
|
||||
const PixelFormatDesc *tpf = GetPixelFormatDesc(pixfmt);
|
||||
|
||||
SDL_Surface *surf = SDL_CreateRGBSurfaceFrom(
|
||||
pixels, width, height, tpf->bpp, pitch,
|
||||
tpf->masks[0], tpf->masks[1], tpf->masks[2], tpf->masks[3]);
|
||||
|
||||
return surf;
|
||||
}
|
||||
|
||||
PixelFormat RageDisplay::FindPixelFormat(
|
||||
int bpp, int Rmask, int Gmask, int Bmask, int Amask )
|
||||
{
|
||||
PixelFormatDesc tmp = { bpp, Rmask, Gmask, Bmask, Amask };
|
||||
|
||||
int pixfmt;
|
||||
for(pixfmt = 0; pixfmt < NUM_PIX_FORMATS; ++pixfmt)
|
||||
{
|
||||
const PixelFormatDesc *pf = GetPixelFormatDesc(PixelFormat(pixfmt));
|
||||
if(!SupportsTextureFormat( PixelFormat(pixfmt) ))
|
||||
continue;
|
||||
|
||||
if(memcmp(pf, &tmp, sizeof(tmp)))
|
||||
continue;
|
||||
return PixelFormat(pixfmt);
|
||||
}
|
||||
|
||||
return NUM_PIX_FORMATS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user