Removed Nintendo DS support since nobody has volunteered to maintain it for over a year.
This commit is contained in:
parent
72befa7332
commit
3afbe992d5
53 changed files with 2 additions and 4350 deletions
|
@ -61,9 +61,6 @@ static const SDL_RenderDriver *render_drivers[] = {
|
|||
#if SDL_VIDEO_RENDER_DIRECTFB
|
||||
&DirectFB_RenderDriver,
|
||||
#endif
|
||||
#if SDL_VIDEO_RENDER_NDS
|
||||
&NDS_RenderDriver,
|
||||
#endif
|
||||
#if SDL_VIDEO_RENDER_PSP
|
||||
&PSP_RenderDriver,
|
||||
#endif
|
||||
|
|
|
@ -173,9 +173,6 @@ extern SDL_RenderDriver GLES_RenderDriver;
|
|||
#if SDL_VIDEO_RENDER_DIRECTFB
|
||||
extern SDL_RenderDriver DirectFB_RenderDriver;
|
||||
#endif
|
||||
#if SDL_VIDEO_RENDER_NDS
|
||||
extern SDL_RenderDriver NDS_RenderDriver;
|
||||
#endif
|
||||
#if SDL_VIDEO_RENDER_PSP
|
||||
extern SDL_RenderDriver PSP_RenderDriver;
|
||||
#endif
|
||||
|
|
|
@ -1,315 +0,0 @@
|
|||
/*
|
||||
* Note: The Nintendo DS port to SDL uses excerpts from the libGL2D,
|
||||
* with permission of the original author. The following is mostly his
|
||||
* code/comments.
|
||||
*
|
||||
*
|
||||
* Easy GL2D
|
||||
*
|
||||
* Relminator 2010
|
||||
* Richard Eric M. Lope BSN RN
|
||||
*
|
||||
* http://rel.betterwebber.com
|
||||
*
|
||||
* A very small and simple DS rendering lib using the 3d core to render 2D stuff
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_NDS
|
||||
|
||||
#include "SDL_libgl2D.h"
|
||||
|
||||
/*
|
||||
* Our static global variable used for Depth values since we cannot
|
||||
* disable depth testing in the DS hardware This value is incremented
|
||||
* for every draw call. */
|
||||
v16 g_depth;
|
||||
int gCurrentTexture;
|
||||
|
||||
/*
|
||||
* !!! PRIVATE !!! Set orthographic projection at 1:1 correspondence
|
||||
* to screen coords glOrtho expects f32 values but if we use the
|
||||
* standard f32 values, we need to rescale either every vert or the
|
||||
* modelview matrix by the same amount to make it work. That's gonna
|
||||
* give us lots of overflows and headaches. So we "scale down" and
|
||||
* use an all integer value.
|
||||
*/
|
||||
void SetOrtho(void)
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION); // set matrixmode to projection
|
||||
glLoadIdentity(); // reset
|
||||
glOrthof32(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1 << 12, 1 << 12); // downscale projection matrix
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes GL in 2D mode Also initializes GL in 3d mode so that we
|
||||
* could combine 2D and 3D later Almost a direct copy from the DS
|
||||
* example files
|
||||
*/
|
||||
void glScreen2D(void)
|
||||
{
|
||||
// initialize gl
|
||||
glInit();
|
||||
|
||||
// enable textures
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// enable antialiasing
|
||||
glEnable(GL_ANTIALIAS);
|
||||
|
||||
// setup the rear plane
|
||||
glClearColor(0, 0, 0, 31); // BG must be opaque for AA to work
|
||||
glClearPolyID(63); // BG must have a unique polygon ID for AA to work
|
||||
|
||||
glClearDepth(GL_MAX_DEPTH);
|
||||
|
||||
// this should work the same as the normal gl call
|
||||
glViewport(0,0,255,191);
|
||||
|
||||
// any floating point gl call is being converted to fixed prior to being implemented
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(70, 256.0 / 192.0, 1, 200);
|
||||
|
||||
gluLookAt( 0.0, 0.0, 1.0, //camera possition
|
||||
0.0, 0.0, 0.0, //look at
|
||||
0.0, 1.0, 0.0); //up
|
||||
|
||||
glMaterialf(GL_AMBIENT, RGB15(31,31,31));
|
||||
glMaterialf(GL_DIFFUSE, RGB15(31,31,31));
|
||||
glMaterialf(GL_SPECULAR, BIT(15) | RGB15(31,31,31));
|
||||
glMaterialf(GL_EMISSION, RGB15(31,31,31));
|
||||
|
||||
// ds uses a table for shinyness..this generates a half-ass one
|
||||
glMaterialShinyness();
|
||||
|
||||
// not a real gl function and will likely change
|
||||
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets up OpenGL for 2d rendering Call this before drawing any of
|
||||
* GL2D's drawing or sprite functions.
|
||||
*/
|
||||
void glBegin2D(void)
|
||||
{
|
||||
// save 3d perpective projection matrix
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
|
||||
// save 3d modelview matrix for safety
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
|
||||
|
||||
// what?!! No glDisable(GL_DEPTH_TEST)?!!!!!!
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glDisable(GL_ANTIALIAS); // disable AA
|
||||
glDisable(GL_OUTLINE); // disable edge-marking
|
||||
|
||||
glColor(0x7FFF); // max color
|
||||
|
||||
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); // no culling
|
||||
|
||||
SetOrtho();
|
||||
|
||||
glMatrixMode(GL_TEXTURE); // reset texture matrix just in case we did some funky stuff with it
|
||||
glLoadIdentity();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW); // reset modelview matrix. No need to scale up by << 12
|
||||
glLoadIdentity();
|
||||
|
||||
gCurrentTexture = 0; // set current texture to 0
|
||||
g_depth = 0; // set depth to 0. We need this var since we cannot disable depth testing
|
||||
}
|
||||
|
||||
/*
|
||||
* Issue this after drawing 2d so that we don't mess the matrix stack.
|
||||
* The complement of glBegin2D.
|
||||
*/
|
||||
void glEnd2D(void)
|
||||
{
|
||||
// restore 3d matrices and set current matrix to modelview
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix(1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Draws a pixel
|
||||
* Parameters:
|
||||
* x,y -> First coordinate of the line
|
||||
* color -> RGB15/ARGB16 color
|
||||
*/
|
||||
void glPutPixel(int x, int y, int color)
|
||||
{
|
||||
glBindTexture(0, 0);
|
||||
glColor(color);
|
||||
glBegin(GL_TRIANGLES);
|
||||
gxVertex3i(x, y, g_depth);
|
||||
gxVertex2i(x, y);
|
||||
gxVertex2i(x, y);
|
||||
glEnd();
|
||||
glColor(0x7FFF);
|
||||
g_depth++;
|
||||
gCurrentTexture = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Draws a line
|
||||
* Parameters:
|
||||
* x1,y1 -> First coordinate of the line
|
||||
* x2,y2 -> Second coordinate of the line
|
||||
* color -> RGB15/ARGB16 color
|
||||
*/
|
||||
void glLine(int x1, int y1, int x2, int y2, int color)
|
||||
{
|
||||
x2++;
|
||||
y2++;
|
||||
|
||||
glBindTexture(0, 0);
|
||||
glColor(color);
|
||||
glBegin(GL_TRIANGLES);
|
||||
gxVertex3i(x1, y1, g_depth);
|
||||
gxVertex2i(x2, y2);
|
||||
gxVertex2i(x2, y2);
|
||||
glEnd();
|
||||
glColor(0x7FFF);
|
||||
g_depth++;
|
||||
gCurrentTexture = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Draws a Filled Box
|
||||
* Parameters:
|
||||
* x1,y1 -> Top-left corner of the box
|
||||
* x2,y2 -> Bottom-Right corner of the box
|
||||
* color -> RGB15/ARGB16 color
|
||||
*/
|
||||
void glBoxFilled(int x1, int y1, int x2, int y2, int color)
|
||||
{
|
||||
x2++;
|
||||
y2++;
|
||||
|
||||
glBindTexture(0, 0);
|
||||
glColor(color);
|
||||
glBegin(GL_QUADS);
|
||||
gxVertex3i(x1, y1, g_depth); // use 3i for first vertex so that we increment HW depth
|
||||
gxVertex2i(x1, y2); // no need for 3 vertices as 2i would share last depth call
|
||||
gxVertex2i(x2, y2);
|
||||
gxVertex2i(x2, y1);
|
||||
glEnd();
|
||||
glColor(0x7FFF);
|
||||
g_depth++;
|
||||
gCurrentTexture = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Create a tile.
|
||||
* Very rigid and prone to human error.
|
||||
*
|
||||
* Parameters:
|
||||
* *sprite -> pointer to a glImage
|
||||
* texture_width -> width/height of the texture;
|
||||
* texture_height -> valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2d)
|
||||
* sprite_width
|
||||
* sprite_height -> width/height of the picture in the texture.
|
||||
* type -> The format of the texture (see glTexImage2d)
|
||||
* param -> parameters for the texture (see glTexImage2d)
|
||||
*/
|
||||
int glLoadTile(glImage *sprite,
|
||||
int texture_width,
|
||||
int texture_height,
|
||||
int sprite_width,
|
||||
int sprite_height,
|
||||
GL_TEXTURE_TYPE_ENUM type,
|
||||
int param,
|
||||
int pallette_width,
|
||||
const u16 *palette,
|
||||
const uint8 *texture)
|
||||
{
|
||||
int textureID;
|
||||
|
||||
glGenTextures(1, &textureID);
|
||||
glBindTexture(0, textureID);
|
||||
glTexImage2D(0, 0, type, texture_width, texture_height, 0, param, texture);
|
||||
glColorTableEXT(0, 0, pallette_width, 0, 0, palette);
|
||||
|
||||
sprite->width = sprite_width;
|
||||
sprite->height = sprite_height;
|
||||
sprite->textureID = textureID;
|
||||
|
||||
return textureID;
|
||||
}
|
||||
|
||||
/*
|
||||
* I made this since the scale wrappers are either the vectorized mode
|
||||
* or does not permit you to scale only the axis you want to
|
||||
* scale. Needed for sprite scaling.
|
||||
*/
|
||||
static inline void gxScalef32(s32 x, s32 y, s32 z)
|
||||
{
|
||||
MATRIX_SCALE = x;
|
||||
MATRIX_SCALE = y;
|
||||
MATRIX_SCALE = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* I this made for future naming conflicts.
|
||||
*/
|
||||
static inline void gxTranslate3f32(int32 x, int32 y, int32 z)
|
||||
{
|
||||
MATRIX_TRANSLATE = x;
|
||||
MATRIX_TRANSLATE = y;
|
||||
MATRIX_TRANSLATE = z;
|
||||
}
|
||||
|
||||
/*
|
||||
* Draws an axis exclusive scaled sprite
|
||||
* Parameters:
|
||||
* x -> x position of the sprite
|
||||
* y -> y position of the sprite
|
||||
* scaleX -> 20.12 FP X axis scale value (1 << 12 is normal)
|
||||
* scaleY -> 20.12 FP Y axis scale value (1 << 12 is normal)
|
||||
* flipmode -> mode for flipping (see GL_FLIP_MODE enum)
|
||||
* *spr -> pointer to a glImage
|
||||
*/
|
||||
void glSpriteScaleXY(int x, int y, s32 scaleX, s32 scaleY, int flipmode, const glImage *spr)
|
||||
{
|
||||
const int x1 = 0;
|
||||
const int y1 = 0;
|
||||
const int x2 = spr->width;
|
||||
const int y2 = spr->height;
|
||||
const int u1 = ((flipmode & GL_FLIP_H) ? spr->width-1 : 0);
|
||||
const int u2 = ((flipmode & GL_FLIP_H) ? 0 : spr->width-1);
|
||||
const int v1 = ((flipmode & GL_FLIP_V) ? spr->height-1 : 0);
|
||||
const int v2 = ((flipmode & GL_FLIP_V) ? 0 : spr->height-1);
|
||||
|
||||
if (spr->textureID != gCurrentTexture)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, spr->textureID);
|
||||
gCurrentTexture = spr->textureID;
|
||||
}
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
gxTranslate3f32(x, y, 0);
|
||||
gxScalef32(scaleX, scaleY, 1 << 12);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
gxTexcoord2i(u1, v1); gxVertex3i(x1, y1, g_depth);
|
||||
gxTexcoord2i(u1, v2); gxVertex2i(x1, y2);
|
||||
gxTexcoord2i(u2, v2); gxVertex2i(x2, y2);
|
||||
gxTexcoord2i(u2, v1); gxVertex2i(x2, y1);
|
||||
|
||||
glEnd();
|
||||
|
||||
glPopMatrix(1);
|
||||
g_depth++;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_NDS */
|
|
@ -1,154 +0,0 @@
|
|||
/*
|
||||
* Note: The Nintendo DS port to SDL uses excerpts from the libGL2D,
|
||||
* with permission of the original author. The following is mostly his
|
||||
* code/comments.
|
||||
*
|
||||
*
|
||||
* Easy GL2D
|
||||
*
|
||||
* Relminator 2010
|
||||
* Richard Eric M. Lope BSN RN
|
||||
*
|
||||
* http://rel.betterwebber.com
|
||||
*
|
||||
* A very small and simple DS rendering lib using the 3d core to render 2D stuff
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_NDS
|
||||
|
||||
#include <nds/arm9/videoGL.h>
|
||||
|
||||
/* LibGL extension(s) */
|
||||
static inline void gxTexcoord2i(t16 u, t16 v)
|
||||
{
|
||||
GFX_TEX_COORD = (v << 20) | ((u << 4) & 0xFFFF);
|
||||
}
|
||||
|
||||
static inline void gxVertex3i(v16 x, v16 y, v16 z)
|
||||
{
|
||||
GFX_VERTEX16 = (y << 16) | (x & 0xFFFF);
|
||||
GFX_VERTEX16 = ((uint32)(uint16)z);
|
||||
}
|
||||
|
||||
static inline void gxVertex2i(v16 x, v16 y)
|
||||
{
|
||||
GFX_VERTEX_XY = (y << 16) | (x & 0xFFFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Enums selecting flipping mode.
|
||||
*
|
||||
* These enums are bits for flipping the sprites.
|
||||
* You can "|" (or) GL_FLIP_V and GL_FLIP_H to flip
|
||||
* both ways.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GL_FLIP_NONE = (1 << 0), /* No flipping */
|
||||
GL_FLIP_V = (1 << 1), /* Sprite is rendered vertically flipped */
|
||||
GL_FLIP_H = (1 << 2), /* Sprite is rendered horizontally flipped */
|
||||
} GL_FLIP_MODE;
|
||||
|
||||
/* Struct for out GL-Based Images. */
|
||||
typedef struct
|
||||
{
|
||||
int width; /* Width of the Sprite */
|
||||
int height; /* Height of the Sprite */
|
||||
int textureID; /* Texture handle (used in glDeleteTextures())
|
||||
The texture handle in VRAM (returned by glGenTextures())
|
||||
ie. This references the actual texture stored in VRAM. */
|
||||
} glImage;
|
||||
|
||||
extern v16 g_depth;
|
||||
extern int gCurrentTexture;
|
||||
|
||||
/*
|
||||
* Draws an Axis Exclusive Scaled Sprite
|
||||
* Parameters:
|
||||
* x X position of the sprite.
|
||||
* y Y position of the sprite.
|
||||
* scaleX 20.12 fixed-point X-Axis scale value (1 << 12 is normal).
|
||||
* scaleY 20.12 fixed-point Y-Axis scale value (1 << 12 is normal).
|
||||
* flipmode mode for flipping (see GL_FLIP_MODE enum).
|
||||
* *spr pointer to a glImage.
|
||||
*/
|
||||
void glSpriteScaleXY(int x, int y, s32 scaleX, s32 scaleY, int flipmode, const glImage *spr);
|
||||
|
||||
/* Initializes our Tileset (like glInitSpriteset()) but without the use of Texture Packer auto-generated files.
|
||||
* Can only be used when tiles in a tilset are of the same dimensions.
|
||||
* Parameters:
|
||||
* *sprite Pointer to an array of glImage.
|
||||
* tile_wid Width of each tile in the texture.
|
||||
* tile_hei Height of each tile in the texture.
|
||||
* bmp_wid Width of of the texture or tileset.
|
||||
* bmp_hei height of of the texture or tileset.
|
||||
* type The format of the texture (see glTexImage2d()).
|
||||
* sizeX The horizontal size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2d()).
|
||||
* sizeY The vertical size of the texture; valid sizes are enumerated in GL_TEXTURE_TYPE_ENUM (see glTexImage2d()).
|
||||
* param parameters for the texture (see glTexImage2d()).
|
||||
* pallette_width Length of the palette. Valid values are <b>4, 16, 32, 256</b> (if <b>0</b>, then palette is removed from currently bound texture).
|
||||
* *palette Pointer to the palette data to load (if NULL, then palette is removed from currently bound texture).
|
||||
* *texture Pointer to the texture data to load.
|
||||
*/
|
||||
int glLoadTile(glImage *sprite,
|
||||
int texture_width,
|
||||
int texture_height,
|
||||
int sprite_width,
|
||||
int sprite_height,
|
||||
GL_TEXTURE_TYPE_ENUM type,
|
||||
int param,
|
||||
int pallette_width,
|
||||
const u16 *palette,
|
||||
const uint8 *texture);
|
||||
|
||||
/* Initializes GL in 2D mode */
|
||||
void glScreen2D(void);
|
||||
|
||||
/*
|
||||
* Sets up OpenGL for 2d rendering.
|
||||
*
|
||||
* Call this before drawing any of GL2D's drawing or sprite functions.
|
||||
*/
|
||||
void glBegin2D(void);
|
||||
|
||||
/*
|
||||
* Issue this after drawing 2d so that we don't mess the matrix stack.
|
||||
*
|
||||
* The complement of glBegin2D().
|
||||
*/
|
||||
void glEnd2D(void);
|
||||
|
||||
/*
|
||||
* Draws a Pixel
|
||||
* x X position of the pixel.
|
||||
* y Y position of the pixel.
|
||||
* color RGB15/ARGB16 color.
|
||||
*/
|
||||
void glPutPixel(int x, int y, int color);
|
||||
|
||||
/*
|
||||
* Draws a Line
|
||||
* x1,y1 Top-Left coordinate of the line.
|
||||
* x2,y2 Bottom-Right coordinate of the line.
|
||||
* color RGB15/ARGB16 color.
|
||||
*/
|
||||
void glLine(int x1, int y1, int x2, int y2, int color);
|
||||
|
||||
/*
|
||||
* Draws a Box
|
||||
* x1,y1 Top-Left coordinate of the box.
|
||||
* x2,y2 Bottom-Right coordinate of the box.
|
||||
* color RGB15/ARGB16 color.
|
||||
*/
|
||||
void glBox(int x1, int y1, int x2, int y2, int color);
|
||||
|
||||
/*
|
||||
* Draws a Filled Box
|
||||
* x1,y1 Top-Left coordinate of the box.
|
||||
* x2,y2 Bottom-Right coordinate of the box.
|
||||
* color RGB15/ARGB16 color.
|
||||
*/
|
||||
void glBoxFilled(int x1, int y1, int x2, int y2, int color);
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_NDS */
|
|
@ -1,418 +0,0 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_NDS
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <nds.h>
|
||||
|
||||
#include "SDL_libgl2D.h"
|
||||
|
||||
#include "SDL_video.h"
|
||||
#include "../../video/SDL_sysvideo.h"
|
||||
#include "SDL_render.h"
|
||||
#include "../SDL_sysrender.h"
|
||||
#include "SDL_log.h"
|
||||
|
||||
/* Draws a partial sprite. Based on glSprite. */
|
||||
static void glSpritePartial(const SDL_Rect * srcrect, int x, int y, int flipmode, const glImage *spr)
|
||||
{
|
||||
int x1 = x;
|
||||
int y1 = y;
|
||||
int x2 = x + srcrect->w;
|
||||
int y2 = y + srcrect->h;
|
||||
|
||||
int u1 = srcrect->x + ((flipmode & GL_FLIP_H) ? spr->width-1 : 0);
|
||||
int u2 = srcrect->x + ((flipmode & GL_FLIP_H) ? 0 : srcrect->h);
|
||||
int v1 = srcrect->y + ((flipmode & GL_FLIP_V) ? spr->height-1 : 0);
|
||||
int v2 = srcrect->y + ((flipmode & GL_FLIP_V) ? 0 : srcrect->h);
|
||||
|
||||
if (spr->textureID != gCurrentTexture) {
|
||||
glBindTexture(GL_TEXTURE_2D, spr->textureID);
|
||||
gCurrentTexture = spr->textureID;
|
||||
}
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
gxTexcoord2i(u1, v1); gxVertex3i(x1, y1, g_depth);
|
||||
gxTexcoord2i(u1, v2); gxVertex2i(x1, y2);
|
||||
gxTexcoord2i(u2, v2); gxVertex2i(x2, y2);
|
||||
gxTexcoord2i(u2, v1); gxVertex2i(x2, y1);
|
||||
|
||||
glEnd();
|
||||
|
||||
g_depth++;
|
||||
}
|
||||
|
||||
/* SDL NDS renderer implementation */
|
||||
|
||||
extern SDL_RenderDriver NDS_RenderDriver;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* Whether current 3D engine is on the main or sub screen. */
|
||||
int is_sub;
|
||||
} NDS_RenderData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
glImage image[1];
|
||||
} NDS_TextureData;
|
||||
|
||||
static int NDS_UpdateViewport(SDL_Renderer *renderer)
|
||||
{
|
||||
/* Nothing to do. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
|
||||
{
|
||||
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
|
||||
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
|
||||
int dest_y;
|
||||
|
||||
if (data->is_sub) {
|
||||
dest_y = dstrect->y;
|
||||
} else {
|
||||
dest_y = dstrect->y-SCREEN_HEIGHT;
|
||||
}
|
||||
|
||||
if (srcrect->w == dstrect->w && srcrect->h == dstrect->h) {
|
||||
/* No scaling */
|
||||
glSpritePartial(srcrect, dstrect->x, dest_y, GL_FLIP_NONE, txdat->image);
|
||||
} else {
|
||||
/* Convert the scaling proportion into a 20.12 value. */
|
||||
s32 scale_w = divf32(dstrect->w << 12, texture->w << 12);
|
||||
s32 scale_h = divf32(dstrect->h << 12, texture->h << 12);
|
||||
|
||||
glSpriteScaleXY(dstrect->x, dest_y, scale_w, scale_h, GL_FLIP_NONE, txdat->image);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int NDS_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
{
|
||||
NDS_TextureData *txdat = NULL;
|
||||
int i;
|
||||
|
||||
SDL_Log("NDS_CreateTexture: NDS_CreateTexture.\n");
|
||||
|
||||
/* Sanity checks. */
|
||||
for (i=0; i<NDS_RenderDriver.info.num_texture_formats; i++) {
|
||||
if (texture->format == NDS_RenderDriver.info.texture_formats[i])
|
||||
break;
|
||||
}
|
||||
if (i == NDS_RenderDriver.info.num_texture_formats) {
|
||||
SDL_SetError("Unsupported texture format (%x)", texture->format);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (texture->w > NDS_RenderDriver.info.max_texture_width) {
|
||||
SDL_SetError("Texture too large (%d)", texture->w);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (texture->h > NDS_RenderDriver.info.max_texture_height) {
|
||||
SDL_SetError("Texture too tall (%d)", texture->h);
|
||||
return -1;
|
||||
}
|
||||
|
||||
texture->driverdata = SDL_calloc(1, sizeof(NDS_TextureData));
|
||||
txdat = (NDS_TextureData *) texture->driverdata;
|
||||
if (!txdat) {
|
||||
SDL_OutOfMemory();
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
NDS_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{
|
||||
NDS_TextureData *txdat = texture->driverdata;
|
||||
|
||||
/* free anything else allocated for texture */
|
||||
SDL_free(txdat);
|
||||
}
|
||||
|
||||
/* size is no more than 512. */
|
||||
static int get_gltexture_size(unsigned int size)
|
||||
{
|
||||
if (size > 256)
|
||||
return TEXTURE_SIZE_512;
|
||||
else if (size > 128)
|
||||
return TEXTURE_SIZE_256;
|
||||
else if (size > 64)
|
||||
return TEXTURE_SIZE_128;
|
||||
else if (size > 32)
|
||||
return TEXTURE_SIZE_64;
|
||||
else if (size > 16)
|
||||
return TEXTURE_SIZE_32;
|
||||
else if (size > 8)
|
||||
return TEXTURE_SIZE_16;
|
||||
else
|
||||
return TEXTURE_SIZE_8;
|
||||
}
|
||||
|
||||
static int NDS_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect, const void *pixels, int pitch)
|
||||
{
|
||||
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
|
||||
char *new_pixels = NULL;
|
||||
const int gl_w = get_gltexture_size(rect->w);
|
||||
const int gl_h = get_gltexture_size(rect->h);
|
||||
const int w = 1 << (3+gl_w); /* Texture sizes must be a power of 2. */
|
||||
const int h = 1 << (3+gl_h); /* Texture sizes must be a power of 2. */
|
||||
|
||||
if (w != rect->w || h != rect->h) {
|
||||
/* Allocate a temporary surface and copy pixels into it while
|
||||
* enlarging the pitch. */
|
||||
const char *src;
|
||||
char *dst;
|
||||
int new_pitch = 2 * w;
|
||||
int i;
|
||||
|
||||
new_pixels = malloc(2 * w * h);
|
||||
if (!new_pixels)
|
||||
return SDL_ENOMEM;
|
||||
|
||||
src = pixels;
|
||||
dst = new_pixels;
|
||||
for (i=0; i<rect->h; i++) {
|
||||
memcpy(dst, src, pitch);
|
||||
src += pitch;
|
||||
dst += new_pitch;
|
||||
}
|
||||
}
|
||||
|
||||
glLoadTile(txdat->image,
|
||||
gl_w, gl_h,
|
||||
rect->w, rect->h,
|
||||
texture->format == SDL_PIXELFORMAT_ABGR1555 ? GL_RGBA : GL_RGB,
|
||||
TEXGEN_OFF, 0, NULL,
|
||||
new_pixels? new_pixels : pixels);
|
||||
|
||||
if (new_pixels)
|
||||
free(new_pixels);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int NDS_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
const SDL_Rect *rect, void **pixels, int *pitch)
|
||||
{
|
||||
SDL_Log("enter %s (todo)\n", __func__);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void NDS_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
{
|
||||
SDL_Log("enter %s\n", __func__);
|
||||
/* stub! */
|
||||
}
|
||||
|
||||
static int NDS_RenderClear(SDL_Renderer *renderer)
|
||||
{
|
||||
glClearColor(renderer->r >> 3,
|
||||
renderer->g >> 3,
|
||||
renderer->b >> 3,
|
||||
renderer->a >> 3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void NDS_RenderPresent(SDL_Renderer * renderer)
|
||||
{
|
||||
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
|
||||
|
||||
glEnd2D();
|
||||
|
||||
glFlush(0);
|
||||
|
||||
swiWaitForVBlank();
|
||||
|
||||
/* wait for capture unit to be ready */
|
||||
while(REG_DISPCAPCNT & DCAP_ENABLE);
|
||||
|
||||
/* 3D engine can only work on one screen at a time. */
|
||||
data->is_sub = !data->is_sub;
|
||||
if (data->is_sub) {
|
||||
lcdMainOnBottom();
|
||||
vramSetBankC(VRAM_C_LCD);
|
||||
vramSetBankD(VRAM_D_SUB_SPRITE);
|
||||
REG_DISPCAPCNT = DCAP_BANK(2) | DCAP_ENABLE | DCAP_SIZE(3);
|
||||
} else {
|
||||
lcdMainOnTop();
|
||||
vramSetBankD(VRAM_D_LCD);
|
||||
vramSetBankC(VRAM_C_SUB_BG);
|
||||
REG_DISPCAPCNT = DCAP_BANK(3) | DCAP_ENABLE | DCAP_SIZE(3);
|
||||
}
|
||||
|
||||
glBegin2D();
|
||||
}
|
||||
|
||||
static int NDS_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points,
|
||||
int count)
|
||||
{
|
||||
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
|
||||
int i;
|
||||
int color = RGB15(renderer->r >> 3,
|
||||
renderer->g >> 3,
|
||||
renderer->b >> 3);
|
||||
|
||||
for (i=0; i < count; i++) {
|
||||
if (data->is_sub) {
|
||||
glPutPixel(points[i].x, points[i].y, color);
|
||||
} else {
|
||||
glPutPixel(points[i].x, points[i].y - SCREEN_HEIGHT, color);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int NDS_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points,
|
||||
int count)
|
||||
{
|
||||
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
|
||||
int i;
|
||||
int color = RGB15(renderer->r >> 3,
|
||||
renderer->g >> 3,
|
||||
renderer->b >> 3);
|
||||
|
||||
for (i=0; i < count-1; i++) {
|
||||
if (data->is_sub) {
|
||||
glLine(points[i].x, points[i].y, points[i+1].x, points[i+1].y, color);
|
||||
} else {
|
||||
glLine(points[i].x, points[i].y - SCREEN_HEIGHT,
|
||||
points[i+1].x, points[i+1].y - SCREEN_HEIGHT, color);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int NDS_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects,
|
||||
int count)
|
||||
{
|
||||
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
|
||||
int i;
|
||||
int color = RGB15(renderer->r >> 3,
|
||||
renderer->g >> 3,
|
||||
renderer->b >> 3);
|
||||
|
||||
for (i=0; i<count; i++) {
|
||||
if (data->is_sub) {
|
||||
glBoxFilled(rects[i].x, rects[i].y,
|
||||
rects[i].x + rects[i].w,
|
||||
rects[i].y + rects[i].h, color);
|
||||
} else {
|
||||
glBoxFilled(rects[i].x, rects[i].y - SCREEN_HEIGHT,
|
||||
rects[i].x + rects[i].w,
|
||||
rects[i].y + rects[i].h - SCREEN_HEIGHT,
|
||||
color);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SDL_Renderer *
|
||||
NDS_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
{
|
||||
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
||||
SDL_DisplayMode *displayMode = &display->current_mode;
|
||||
SDL_Renderer *renderer;
|
||||
NDS_RenderData *data;
|
||||
int bpp;
|
||||
Uint32 Rmask, Gmask, Bmask, Amask;
|
||||
|
||||
if (displayMode->format != SDL_PIXELFORMAT_ABGR1555) {
|
||||
SDL_SetError("Unsupported pixel format (%x)", displayMode->format);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!SDL_PixelFormatEnumToMasks(displayMode->format, &bpp,
|
||||
&Rmask, &Gmask, &Bmask, &Amask)) {
|
||||
SDL_SetError("Unknown display format");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
|
||||
if (!renderer) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = (NDS_RenderData *) SDL_calloc(1, sizeof(*data));
|
||||
if (!data) {
|
||||
SDL_free(renderer);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
renderer->info = NDS_RenderDriver.info;
|
||||
renderer->info.flags = SDL_RENDERER_ACCELERATED;
|
||||
|
||||
renderer->CreateTexture = NDS_CreateTexture;
|
||||
renderer->UpdateTexture = NDS_UpdateTexture;
|
||||
renderer->LockTexture = NDS_LockTexture;
|
||||
renderer->UnlockTexture = NDS_UnlockTexture;
|
||||
renderer->UpdateViewport = NDS_UpdateViewport;
|
||||
renderer->RenderClear = NDS_RenderClear;
|
||||
renderer->RenderDrawPoints = NDS_RenderDrawPoints;
|
||||
renderer->RenderDrawLines = NDS_RenderDrawLines;
|
||||
renderer->RenderFillRects = NDS_RenderFillRects;
|
||||
renderer->RenderCopy = NDS_RenderCopy;
|
||||
/* renderer->RenderReadPixels = NDS_RenderReadPixels; - todo ? */
|
||||
renderer->RenderPresent = NDS_RenderPresent;
|
||||
renderer->DestroyTexture = NDS_DestroyTexture;
|
||||
/* renderer->DestroyRenderer = NDS_DestroyRenderer; - todo ? */
|
||||
|
||||
renderer->driverdata = data;
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
SDL_RenderDriver NDS_RenderDriver = {
|
||||
.CreateRenderer = NDS_CreateRenderer,
|
||||
.info = {
|
||||
.name = "nds",
|
||||
.flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC,
|
||||
.num_texture_formats = 2,
|
||||
.texture_formats = { [0] = SDL_PIXELFORMAT_ABGR1555,
|
||||
[1] = SDL_PIXELFORMAT_BGR555,
|
||||
},
|
||||
.max_texture_width = 512,
|
||||
.max_texture_height = 512,
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_NDS */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
Loading…
Add table
Add a link
Reference in a new issue