src/render/nds/SDL_ndsrender.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 06 Mar 2011 21:19:02 -0800
changeset 5429 76329ba1fa5c
parent 5423 b69fa50e80d7
child 5515 0fcf231a6e74
permissions -rw-r--r--
Only compile the NDS renderer if specified in the config file.
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
*/
5429
76329ba1fa5c Only compile the NDS renderer if specified in the config file.
Sam Lantinga <slouken@libsdl.org>
parents: 5423
diff changeset
    22
#include "SDL_config.h"
76329ba1fa5c Only compile the NDS renderer if specified in the config file.
Sam Lantinga <slouken@libsdl.org>
parents: 5423
diff changeset
    23
76329ba1fa5c Only compile the NDS renderer if specified in the config file.
Sam Lantinga <slouken@libsdl.org>
parents: 5423
diff changeset
    24
#if SDL_VIDEO_RENDER_NDS
5423
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include <stdio.h>
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
#include <stdlib.h>
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include <nds.h>
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#include <gl2d.h>
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include "SDL_video.h"
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include "../../video/SDL_sysvideo.h"
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include "SDL_render.h"
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include "../SDL_sysrender.h"
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#include "SDL_log.h"
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
/* SDL NDS renderer implementation */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
extern SDL_RenderDriver NDS_RenderDriver;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
typedef struct
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    43
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
	/* Whether current 3D engine is on the main or sub screen. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
	int is_sub;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
} NDS_RenderData;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
typedef struct
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
	glImage image[1];
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
} NDS_TextureData;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
static int NDS_UpdateViewport(SDL_Renderer *renderer)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
	/* Nothing to do. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
	return 0;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
static int
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
               const SDL_Rect * srcrect, const SDL_Rect * dstrect)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
	int dest_y;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
	if (data->is_sub) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
		dest_y = dstrect->y;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
	} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
		dest_y = dstrect->y-SCREEN_HEIGHT;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
	if (texture->w == dstrect->w && texture->h == dstrect->h) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
		/* No scaling */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
		glSprite(dstrect->x, dest_y, GL_FLIP_NONE, txdat->image);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
	} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
		/* Convert the scaling proportion into a 20.12 value. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
		s32 scale_w = divf32(dstrect->w << 12, texture->w << 12);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
		s32 scale_h = divf32(dstrect->h << 12, texture->h << 12);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
		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
    83
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    return 0;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
static int NDS_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
    NDS_TextureData *txdat = NULL;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
    int i;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
	SDL_Log("NDS_CreateTexture: NDS_CreateTexture.\n");
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
	/* Sanity checks. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
	for (i=0; i<NDS_RenderDriver.info.num_texture_formats; i++) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
		if (texture->format == NDS_RenderDriver.info.texture_formats[i])
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
			break;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
	}
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
	if (i == NDS_RenderDriver.info.num_texture_formats) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
		SDL_SetError("Unsupported texture format (%x)", texture->format);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
		return -1;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
	if (texture->w > NDS_RenderDriver.info.max_texture_width) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
		SDL_SetError("Texture too large (%d)", texture->w);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
		return -1;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
	if (texture->h > NDS_RenderDriver.info.max_texture_height) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
		SDL_SetError("Texture too tall (%d)", texture->h);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
		return -1;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
	texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
	txdat = (NDS_TextureData *) texture->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
	if (!txdat) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
		SDL_OutOfMemory();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
		return -1;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
    return 0;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
static void
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
    NDS_TextureData *txdat = texture->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
    /* free anything else allocated for texture */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
    SDL_free(txdat);
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
/* size is no more than 1024. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
static int get_gltexture_size(unsigned int size)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
	if (size > 256)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
		return TEXTURE_SIZE_512;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
	else if (size > 128)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
		return TEXTURE_SIZE_256;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
	else if (size > 64)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
		return TEXTURE_SIZE_128;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
	else if (size > 32)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
		return TEXTURE_SIZE_64;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
	else if (size > 16)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
		return TEXTURE_SIZE_32;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
	else if (size > 8)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
		return TEXTURE_SIZE_16;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
	else
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
		return TEXTURE_SIZE_8;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
							 const SDL_Rect * rect, const void *pixels, int pitch)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
    NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
	SDL_Log("enter %s\n", __func__);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
	glLoadTileSet(txdat->image,
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
				  rect->w, rect->h,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
				  GL_RGBA,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
				  get_gltexture_size(rect->w),
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
				  get_gltexture_size(rect->h),
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
				  TEXGEN_OFF, 0, NULL,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
				  pixels);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
    return 0;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
static int NDS_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
						   const SDL_Rect *rect, void **pixels, int *pitch)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
	SDL_Log("enter %s (todo)\n", __func__);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
    return 0;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
static void NDS_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
	SDL_Log("enter %s\n", __func__);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
    /* stub! */
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
static int NDS_RenderClear(SDL_Renderer *renderer)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
	/* wait for capture unit to be ready */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
	while(REG_DISPCAPCNT & DCAP_ENABLE);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
	/* 3D engine can only work on one screen at a time. */
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
	data->is_sub = !data->is_sub;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
	if (data->is_sub) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
		lcdMainOnBottom();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
		vramSetBankC(VRAM_C_LCD);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
		vramSetBankD(VRAM_D_SUB_SPRITE);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
		REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
	} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
		lcdMainOnTop();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
		vramSetBankD(VRAM_D_LCD);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
		vramSetBankC(VRAM_C_SUB_BG);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
		REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3);
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
	glBegin2D();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
    glClearColor(renderer->r >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
                 renderer->g >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
                 renderer->b >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
                 renderer->a >> 3);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
	return 0;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
static void NDS_RenderPresent(SDL_Renderer * renderer)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
//	SDL_Log("enter %s\n", __func__);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
	glEnd2D();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
		
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
	glFlush( 0 );
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
static int NDS_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
								int count)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
	int i;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
	int color = RGB15(renderer->r >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
					  renderer->g >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
					  renderer->b >> 3);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
	for (i=0; i < count; i++) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
		if (data->is_sub) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
			glPutPixel(points[i].x, points[i].y, color);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
		} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
			glPutPixel(points[i].x, points[i].y - SCREEN_HEIGHT, color);
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
	return 0;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
static int NDS_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
							   int count)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
	int i;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
	int color = RGB15(renderer->r >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
					  renderer->g >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
					  renderer->b >> 3);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
	for (i=0; i < count-1; i++) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
		if (data->is_sub) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
			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
   258
		} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
			glLine(points[i].x, points[i].y - SCREEN_HEIGHT, 
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
				   points[i+1].x, points[i+1].y - SCREEN_HEIGHT, color);
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
	return 0;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
static int NDS_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
							   int count)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
    NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
	int i;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   272
	int color = RGB15(renderer->r >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   273
					  renderer->g >> 3,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   274
					  renderer->b >> 3);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   275
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   276
	for (i=0; i<count; i++) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   277
		if (data->is_sub) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   278
			glBoxFilled(rects[i].x, rects[i].y, 
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   279
						rects[i].x + rects[i].w,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   280
						rects[i].y + rects[i].h, color);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   281
	} else {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   282
			glBoxFilled(rects[i].x, rects[i].y - SCREEN_HEIGHT,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   283
						rects[i].x + rects[i].w,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   284
						rects[i].y + rects[i].h - SCREEN_HEIGHT,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   285
						color);
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   289
	return 0;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   292
static SDL_Renderer *
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   293
NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   294
{
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   295
    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   296
    SDL_DisplayMode *displayMode = &display->current_mode;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   297
    SDL_Renderer *renderer;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   298
    NDS_RenderData *data;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   299
    int bpp;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   300
    Uint32 Rmask, Gmask, Bmask, Amask;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   301
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   302
	if (displayMode->format != SDL_PIXELFORMAT_ABGR1555) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   303
		SDL_SetError("Unsupported pixel format (%x)", displayMode->format);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   304
		return NULL;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   307
    if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   308
                                    &Rmask, &Gmask, &Bmask, &Amask)) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   309
        SDL_SetError("Unknown display format");
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   310
        return NULL;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   313
    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   314
    if (!renderer) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   315
        SDL_OutOfMemory();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   316
        return NULL;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   319
    data = (NDS_RenderData *) SDL_calloc(1, sizeof(*data));
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   320
    if (!data) {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   321
        SDL_free(renderer);
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   322
        SDL_OutOfMemory();
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   323
        return NULL;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   326
    renderer->info.name = NDS_RenderDriver.info.name;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
    renderer->info.flags = 0;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
    renderer->info.num_texture_formats = NDS_RenderDriver.info.num_texture_formats;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
    SDL_memcpy(renderer->info.texture_formats,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
			   NDS_RenderDriver.info.texture_formats,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   331
               sizeof(renderer->info.texture_formats));
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
    renderer->info.max_texture_width = NDS_RenderDriver.info.max_texture_width;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
    renderer->info.max_texture_height = NDS_RenderDriver.info.max_texture_height;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   334
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
	renderer->UpdateViewport = NDS_UpdateViewport;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
    renderer->CreateTexture = NDS_CreateTexture;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
	renderer->DestroyTexture = NDS_DestroyTexture;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   338
	renderer->RenderCopy = NDS_RenderCopy;	
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
	renderer->UpdateTexture = NDS_UpdateTexture;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
	renderer->LockTexture = NDS_LockTexture;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
	renderer->UnlockTexture = NDS_UnlockTexture;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
	renderer->RenderClear = NDS_RenderClear;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   343
	renderer->RenderPresent = NDS_RenderPresent;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
	renderer->RenderDrawPoints = NDS_RenderDrawPoints;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
	renderer->RenderDrawLines = NDS_RenderDrawLines;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
	renderer->RenderFillRects = NDS_RenderFillRects;
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   348
    return renderer;
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
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
SDL_RenderDriver NDS_RenderDriver = {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   352
	.CreateRenderer = NDS_CreateRenderer,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
    .info = {
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
		.name = "nds",
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   355
		.flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   356
		.num_texture_formats = 1,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   357
		.texture_formats = { [0] = SDL_PIXELFORMAT_ABGR1555,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
							 [1] = SDL_PIXELFORMAT_BGR555,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   359
		},
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
		.max_texture_width = 512,
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
		.max_texture_height = 512,
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
5429
76329ba1fa5c Only compile the NDS renderer if specified in the config file.
Sam Lantinga <slouken@libsdl.org>
parents: 5423
diff changeset
   365
#endif /* SDL_VIDEO_RENDER_NDS */
76329ba1fa5c Only compile the NDS renderer if specified in the config file.
Sam Lantinga <slouken@libsdl.org>
parents: 5423
diff changeset
   366
5423
b69fa50e80d7 a Nintendo ds update
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   367
/* vi: set ts=4 sw=4 expandtab: */