cli: user proper SDL2 OpenGL-accelerated rendering primitives
additionally: - don't allocate memory for surfaces and textures over and over - use one texture for each NDS screen - this allows to easily add support for horizontal screen layout.
This commit is contained in:
parent
7e0336d57d
commit
699f63d688
|
@ -82,6 +82,7 @@ static float nds_screen_size_ratio = 1.0f;
|
||||||
|
|
||||||
static SDL_Window * window;
|
static SDL_Window * window;
|
||||||
static SDL_Renderer * renderer;
|
static SDL_Renderer * renderer;
|
||||||
|
static SDL_Texture *screen[2];
|
||||||
|
|
||||||
/* Flags to pass to SDL_SetVideoMode */
|
/* Flags to pass to SDL_SetVideoMode */
|
||||||
static int sdl_videoFlags;
|
static int sdl_videoFlags;
|
||||||
|
@ -267,15 +268,23 @@ Draw( void) {
|
||||||
const size_t pixCount = GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT;
|
const size_t pixCount = GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT;
|
||||||
ColorspaceApplyIntensityToBuffer16<false, false>(displayInfo.nativeBuffer16[NDSDisplayID_Main], pixCount, displayInfo.backlightIntensity[NDSDisplayID_Main]);
|
ColorspaceApplyIntensityToBuffer16<false, false>(displayInfo.nativeBuffer16[NDSDisplayID_Main], pixCount, displayInfo.backlightIntensity[NDSDisplayID_Main]);
|
||||||
ColorspaceApplyIntensityToBuffer16<false, false>(displayInfo.nativeBuffer16[NDSDisplayID_Touch], pixCount, displayInfo.backlightIntensity[NDSDisplayID_Touch]);
|
ColorspaceApplyIntensityToBuffer16<false, false>(displayInfo.nativeBuffer16[NDSDisplayID_Touch], pixCount, displayInfo.backlightIntensity[NDSDisplayID_Touch]);
|
||||||
|
static const SDL_Rect destrect[2] = {
|
||||||
SDL_Surface *rawImage = SDL_CreateRGBSurfaceFrom(displayInfo.masterNativeBuffer16, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT * 2, 16, GPU_FRAMEBUFFER_NATIVE_WIDTH * sizeof(u16), 0x001F, 0x03E0, 0x7C00, 0);
|
{ 0,0,
|
||||||
if(rawImage == NULL) return;
|
GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT},
|
||||||
|
{ 0, GPU_FRAMEBUFFER_NATIVE_HEIGHT,
|
||||||
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, rawImage);
|
GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT},
|
||||||
SDL_FreeSurface(rawImage);
|
};
|
||||||
SDL_RenderCopy(renderer, texture, NULL, NULL);
|
unsigned i, off = 0, n = pixCount*2;
|
||||||
|
for(i = 0; i < 2; ++i) {
|
||||||
|
void *p = 0;
|
||||||
|
int pitch;
|
||||||
|
SDL_LockTexture(screen[i], NULL, &p, &pitch);
|
||||||
|
memcpy(p, ((char*)displayInfo.masterNativeBuffer16)+off, n);
|
||||||
|
SDL_UnlockTexture(screen[i]);
|
||||||
|
SDL_RenderCopy(renderer, screen[i], NULL, &destrect[i]);
|
||||||
|
off += n;
|
||||||
|
}
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,6 +342,7 @@ int main(int argc, char ** argv) {
|
||||||
int limiter_frame_counter = 0;
|
int limiter_frame_counter = 0;
|
||||||
int limiter_tick0 = 0;
|
int limiter_tick0 = 0;
|
||||||
int error;
|
int error;
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
GKeyFile *keyfile;
|
GKeyFile *keyfile;
|
||||||
|
|
||||||
|
@ -471,8 +481,9 @@ int main(int argc, char ** argv) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sdl_videoFlags |= SDL_SWSURFACE;
|
sdl_videoFlags |= SDL_WINDOW_OPENGL;
|
||||||
window = SDL_CreateWindow( "Desmume SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 256, 384, sdl_videoFlags );
|
window = SDL_CreateWindow( "Desmume SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||||
|
256, 384, sdl_videoFlags );
|
||||||
|
|
||||||
if ( !window ) {
|
if ( !window ) {
|
||||||
fprintf( stderr, "Window creation failed: %s\n", SDL_GetError( ) );
|
fprintf( stderr, "Window creation failed: %s\n", SDL_GetError( ) );
|
||||||
|
@ -481,6 +492,13 @@ int main(int argc, char ** argv) {
|
||||||
|
|
||||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
|
||||||
|
uint32_t desmume_pixelformat = SDL_MasksToPixelFormatEnum(16, 0x001F, 0x03E0, 0x7C00, 0);
|
||||||
|
|
||||||
|
for(i = 0; i < 2; ++i)
|
||||||
|
screen[i] = SDL_CreateTexture(renderer, desmume_pixelformat, SDL_TEXTUREACCESS_STREAMING,
|
||||||
|
GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT);
|
||||||
|
|
||||||
|
|
||||||
/* Initialize joysticks */
|
/* Initialize joysticks */
|
||||||
if(!init_joy()) return 1;
|
if(!init_joy()) return 1;
|
||||||
/* Load keyboard and joystick configuration */
|
/* Load keyboard and joystick configuration */
|
||||||
|
|
Loading…
Reference in New Issue