src/render/nds/SDL_ndsrender.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 06 Mar 2011 21:12:19 -0800
changeset 5423 b69fa50e80d7
child 5429 76329ba1fa5c
permissions -rw-r--r--
a Nintendo ds update Frank Zago to SDL For those interested, here's a snapshot of the current port. I did away with most of the previous attempt which was based of the sprite engine, because the support is limited to 128 64x64 sprites. Instead I'm using the gl engine. The drawback is that either the frame buffer or the gl engine can be used because there's not that much video memory on a DS. With minimal changes to their code, it can now run the following tests: , testspriteminimal, testscale and testsprite2. The last 2 only run under the emulator for some reason. The tests are not included in this patch for size reason. In 16 bits mode, the 16th bit indicated transparency/opacity. If 0, the color is not displayed. So I had to patch a few core file to set that bit to 1. See patch for src/video/SDL_RLEaccel.c and src/video/SDL_blit.h. Is that ok, or is there a better way ? The nds also doesn't support windowed mode, so I force the fullscreen in src/video/SDL_video.c. Is that ok, or is there a better way ? To get a smaller library, I also tried to not compile the software renderer when the hardware renderer is compiled in, and define SDL_NO_COMPAT; however the compilation eventually fails in SDL_surface.c because SDL_SRCCOLORKEY is defined in SDL_compat.h. Is SDL_NO_COMPAT only for application and not SDL itself ?
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5423
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
    Copyright (C) 1997-2011 Sam Lantinga
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
    Lesser General Public License for more details.
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free Software
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
    Sam Lantinga
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
    slouken@libsdl.org
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
*/
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
#include <stdio.h>
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
#include <stdlib.h>
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include <nds.h>
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include <gl2d.h>
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include "SDL_config.h"
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
#include "SDL_video.h"
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include "../../video/SDL_sysvideo.h"
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include "SDL_render.h"
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include "../SDL_sysrender.h"
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include "SDL_log.h"
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
/* SDL NDS renderer implementation */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
extern SDL_RenderDriver NDS_RenderDriver;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
typedef struct
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
	/* Whether current 3D engine is on the main or sub screen. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
	int is_sub;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
} NDS_RenderData;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
typedef struct
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
	glImage image[1];
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
} NDS_TextureData;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
static int NDS_UpdateViewport(SDL_Renderer *renderer)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
	/* Nothing to do. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
	return 0;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
static int
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
               const SDL_Rect * srcrect, const SDL_Rect * dstrect)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
	int dest_y;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
	if (data->is_sub) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
		dest_y = dstrect->y;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
	} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
		dest_y = dstrect->y-SCREEN_HEIGHT;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
	if (texture->w == dstrect->w && texture->h == dstrect->h) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
		/* No scaling */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
		glSprite(dstrect->x, dest_y, GL_FLIP_NONE, txdat->image);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
	} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
		/* Convert the scaling proportion into a 20.12 value. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
		s32 scale_w = divf32(dstrect->w << 12, texture->w << 12);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
		s32 scale_h = divf32(dstrect->h << 12, texture->h << 12);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
		glSpriteScaleXY(dstrect->x, dest_y, scale_w, scale_h, GL_FLIP_NONE, txdat->image);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
    return 0;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
static int NDS_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    NDS_TextureData *txdat = NULL;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
    int i;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
	SDL_Log("NDS_CreateTexture: NDS_CreateTexture.\n");
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
	/* Sanity checks. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
	for (i=0; i<NDS_RenderDriver.info.num_texture_formats; i++) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
		if (texture->format == NDS_RenderDriver.info.texture_formats[i])
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
			break;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
	if (i == NDS_RenderDriver.info.num_texture_formats) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
		SDL_SetError("Unsupported texture format (%x)", texture->format);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
		return -1;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
	if (texture->w > NDS_RenderDriver.info.max_texture_width) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
		SDL_SetError("Texture too large (%d)", texture->w);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
		return -1;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
	if (texture->h > NDS_RenderDriver.info.max_texture_height) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
		SDL_SetError("Texture too tall (%d)", texture->h);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
		return -1;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
	texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
	txdat = (NDS_TextureData *) texture->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
	if (!txdat) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
		SDL_OutOfMemory();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
		return -1;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
    return 0;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
static void
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
    NDS_TextureData *txdat = texture->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
    /* free anything else allocated for texture */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
    SDL_free(txdat);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
/* size is no more than 1024. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
static int get_gltexture_size(unsigned int size)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
	if (size > 256)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
		return TEXTURE_SIZE_512;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
	else if (size > 128)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
		return TEXTURE_SIZE_256;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
	else if (size > 64)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
		return TEXTURE_SIZE_128;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
	else if (size > 32)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
		return TEXTURE_SIZE_64;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
	else if (size > 16)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
		return TEXTURE_SIZE_32;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
	else if (size > 8)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
		return TEXTURE_SIZE_16;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
	else
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
		return TEXTURE_SIZE_8;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
							 const SDL_Rect * rect, const void *pixels, int pitch)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
	SDL_Log("enter %s\n", __func__);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
	glLoadTileSet(txdat->image,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
				  rect->w, rect->h,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
				  rect->w, rect->h,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
				  GL_RGBA,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
				  get_gltexture_size(rect->w),
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
				  get_gltexture_size(rect->h),
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
				  TEXGEN_OFF, 0, NULL,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
				  pixels);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
    return 0;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
static int NDS_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
						   const SDL_Rect *rect, void **pixels, int *pitch)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
	SDL_Log("enter %s (todo)\n", __func__);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
    return 0;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
static void NDS_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
	SDL_Log("enter %s\n", __func__);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
    /* stub! */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
static int NDS_RenderClear(SDL_Renderer *renderer)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
	/* wait for capture unit to be ready */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
	while(REG_DISPCAPCNT & DCAP_ENABLE);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
	/* 3D engine can only work on one screen at a time. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
	data->is_sub = !data->is_sub;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
	if (data->is_sub) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
		lcdMainOnBottom();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
		vramSetBankC(VRAM_C_LCD);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
		vramSetBankD(VRAM_D_SUB_SPRITE);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
		REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
	} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
		lcdMainOnTop();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
		vramSetBankD(VRAM_D_LCD);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
		vramSetBankC(VRAM_C_SUB_BG);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
		REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
	glBegin2D();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
    glClearColor(renderer->r >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
                 renderer->g >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
                 renderer->b >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
                 renderer->a >> 3);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
	return 0;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
static void NDS_RenderPresent(SDL_Renderer * renderer)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
//	SDL_Log("enter %s\n", __func__);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
	glEnd2D();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
		
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
	glFlush( 0 );
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
static int NDS_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
								int count)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
	int i;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
	int color = RGB15(renderer->r >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
					  renderer->g >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
					  renderer->b >> 3);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
	for (i=0; i < count; i++) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
		if (data->is_sub) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
			glPutPixel(points[i].x, points[i].y, color);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
		} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
			glPutPixel(points[i].x, points[i].y - SCREEN_HEIGHT, color);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
		}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
	return 0;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
static int NDS_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
							   int count)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
	int i;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
	int color = RGB15(renderer->r >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
					  renderer->g >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
					  renderer->b >> 3);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
	for (i=0; i < count-1; i++) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
		if (data->is_sub) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
			glLine(points[i].x, points[i].y, points[i+1].x, points[i+1].y, color);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
		} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
			glLine(points[i].x, points[i].y - SCREEN_HEIGHT, 
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
				   points[i+1].x, points[i+1].y - SCREEN_HEIGHT, color);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
		}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
	return 0;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
static int NDS_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
							   int count)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
	int i;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
	int color = RGB15(renderer->r >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
					  renderer->g >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
					  renderer->b >> 3);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
	for (i=0; i<count; i++) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
		if (data->is_sub) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
			glBoxFilled(rects[i].x, rects[i].y, 
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
						rects[i].x + rects[i].w,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
						rects[i].y + rects[i].h, color);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
	} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
			glBoxFilled(rects[i].x, rects[i].y - SCREEN_HEIGHT,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
						rects[i].x + rects[i].w,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
						rects[i].y + rects[i].h - SCREEN_HEIGHT,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
						color);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
		}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   286
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   287
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   288
	return 0;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   290
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   291
static SDL_Renderer *
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
    SDL_DisplayMode *displayMode = &display->current_mode;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
    SDL_Renderer *renderer;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
    NDS_RenderData *data;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
    int bpp;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
    Uint32 Rmask, Gmask, Bmask, Amask;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
	if (displayMode->format != SDL_PIXELFORMAT_ABGR1555) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
		SDL_SetError("Unsupported pixel format (%x)", displayMode->format);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
		return NULL;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   305
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   306
    if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
                                    &Rmask, &Gmask, &Bmask, &Amask)) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
        SDL_SetError("Unknown display format");
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
        return NULL;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
    }
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   311
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
    if (!renderer) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
        SDL_OutOfMemory();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
        return NULL;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
    }
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   317
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   318
    data = (NDS_RenderData *) SDL_calloc(1, sizeof(*data));
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
    if (!data) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
        SDL_free(renderer);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
        SDL_OutOfMemory();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
        return NULL;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
    }
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   324
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   325
    renderer->info.name = NDS_RenderDriver.info.name;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
    renderer->info.flags = 0;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
    renderer->info.num_texture_formats = NDS_RenderDriver.info.num_texture_formats;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
    SDL_memcpy(renderer->info.texture_formats,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
			   NDS_RenderDriver.info.texture_formats,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
               sizeof(renderer->info.texture_formats));
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
    renderer->info.max_texture_width = NDS_RenderDriver.info.max_texture_width;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
    renderer->info.max_texture_height = NDS_RenderDriver.info.max_texture_height;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
	renderer->UpdateViewport = NDS_UpdateViewport;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
    renderer->CreateTexture = NDS_CreateTexture;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
	renderer->DestroyTexture = NDS_DestroyTexture;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
	renderer->RenderCopy = NDS_RenderCopy;	
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
	renderer->UpdateTexture = NDS_UpdateTexture;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
	renderer->LockTexture = NDS_LockTexture;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
	renderer->UnlockTexture = NDS_UnlockTexture;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
	renderer->RenderClear = NDS_RenderClear;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
	renderer->RenderPresent = NDS_RenderPresent;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   343
	renderer->RenderDrawPoints = NDS_RenderDrawPoints;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
	renderer->RenderDrawLines = NDS_RenderDrawLines;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
	renderer->RenderFillRects = NDS_RenderFillRects;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
    return renderer;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   349
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   350
SDL_RenderDriver NDS_RenderDriver = {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
	.CreateRenderer = NDS_CreateRenderer,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
    .info = {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
		.name = "nds",
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
		.flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
		.num_texture_formats = 1,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
		.texture_formats = { [0] = SDL_PIXELFORMAT_ABGR1555,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
							 [1] = SDL_PIXELFORMAT_BGR555,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
		},
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
		.max_texture_width = 512,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
		.max_texture_height = 512,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
     }
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   362
};
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   363
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   364
/* vi: set ts=4 sw=4 expandtab: */