Created
April 14, 2014 01:33
-
-
Save cleverca22/10609835 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <errno.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <assert.h> | |
#include <stdbool.h> | |
#include <v3d2.h> | |
#include "compiler.h" | |
#include "SDL_video.h" | |
#include "../SDL_sysvideo.h" | |
#include "glCore.h" | |
#define _THIS SDL_VideoDevice *this | |
SDL_Rect **SDL_modelist; | |
struct V3D2MemoryReference *makeShaderCode(); | |
DISPMANX_MODEINFO_T *info; | |
// http://www.glprogramming.com/red/about.html | |
// FIXME should be in an GL header | |
extern DISPMANX_MODEINFO_T *initOpenGl(); | |
static int v3d2_VideoInit(_THIS, SDL_PixelFormat *vformat) { | |
info = initOpenGl(); | |
return 0; | |
} | |
static void v3d2_VideoQuit(_THIS) { | |
puts(__func__); | |
stopOpenGl(); | |
} | |
static void v3d2_InitOSKeymap(_THIS) { | |
} | |
static SDL_Rect **v3d2_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) { | |
puts(__func__); | |
SDL_modelist = (SDL_Rect **)SDL_malloc(2*sizeof(SDL_Rect *)); | |
SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); | |
SDL_modelist[0]->x=0; | |
SDL_modelist[0]->y=0; | |
SDL_modelist[0]->w=info->width; | |
SDL_modelist[0]->h=info->height; | |
SDL_modelist[1] = 0; | |
return SDL_modelist; | |
} | |
SDL_Surface *v3d2_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { | |
printf("v3d2_SetVideoMode(%p,%p,%d,%d,%d,%x)\n",this,current,width,height,bpp,flags); | |
SDL_Lock_EventThread(); | |
setViewportSize(width,height); | |
current->flags = flags & SDL_OPENGL; | |
this->gl_config.driver_loaded = 1; | |
SDL_Unlock_EventThread(); | |
return current; | |
} | |
int v3d2_GL_LoadLibrary(_THIS,const char *path) { | |
puts(__func__); | |
this->gl_config.driver_loaded = 1; | |
return 0; | |
} | |
void glBlendFunc(GLenum sfactor, GLenum dfactor) { | |
} | |
void glEnable(GLenum cap) { | |
switch (cap) { | |
case GL_BLEND: | |
case GL_TEXTURE_2D: | |
// FIXME | |
break; | |
default: | |
assert(0); | |
} | |
} | |
void glDisable(GLenum cap) { | |
switch (cap) { | |
case GL_FOG: | |
case GL_DEPTH_TEST: | |
case GL_CULL_FACE: | |
case GL_LIGHTING: | |
case GL_TEXTURE_2D: | |
// FIXME | |
break; | |
default: | |
assert(0); | |
} | |
} | |
void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *data) { | |
puts(__func__); | |
switch (target) { | |
case GL_TEXTURE_2D: | |
assert(internalFormat == GL_RGBA8); // 32 bits per pixel | |
assert(format == GL_RGBA); | |
assert(type == GL_UNSIGNED_BYTE); | |
// FIXME, copy data from data to active2D | |
break; | |
default: | |
assert(0); | |
} | |
} | |
void glDeleteTextures(GLsizei n, const GLuint *textures) { | |
puts(__func__); | |
} | |
GLAPI void GLAPIENTRY glTexParameteri( GLenum target, GLenum pname, GLint param ){ | |
puts(__func__); | |
} | |
const GLubyte *glGetString(GLenum name) { | |
printf("glGetString(%d)\n",name); | |
switch (name) { | |
case GL_EXTENSIONS: | |
return "GL_ARB_vertex_buffer_object"; | |
default: | |
assert(0); | |
} | |
return 0; | |
} | |
void glLoadIdentity(void) { | |
// https://www.opengl.org/sdk/docs/man2/xhtml/glLoadIdentity.xml | |
} | |
void v3d2_FIXME(void) { | |
puts("FIXME"); | |
} | |
void glLightf(GLenum light, GLenum pname, GLfloat param) { | |
} | |
void glMaterialfv(GLenum face, GLenum pname, const GLfloat *params) { | |
} | |
void glMateriali(GLenum face, GLenum pname, const GLint param) { | |
} | |
void glEnableClientState(GLenum cap) { | |
} | |
void glClear(GLbitfield mask) { | |
} | |
void glCallList(GLuint list) { | |
} | |
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal) { | |
} | |
GLAPI void GLAPIENTRY glDepthFunc( GLenum func ){ | |
} | |
GLAPI void GLAPIENTRY glColor3fv( const GLfloat *v ){ | |
} | |
GLAPI void GLAPIENTRY glLightModelfv( GLenum pname, const GLfloat *params ){ | |
} | |
GLAPI void GLAPIENTRY glColorMaterial( GLenum face, GLenum mode ){ | |
} | |
GLAPI void GLAPIENTRY glFogf( GLenum pname, GLfloat param ){ | |
} | |
GLAPI void GLAPIENTRY glFogi( GLenum pname, GLint param ){ | |
} | |
GLAPI void GLAPIENTRY glFogfv( GLenum pname, const GLfloat *params ){ | |
} | |
GLAPI void GLAPIENTRY glFogiv( GLenum pname, const GLint *params ){ | |
} | |
GLAPI void GLAPIENTRY glClientActiveTextureARB(GLenum texture){ | |
} | |
GLAPI void GLAPIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *ptr ){ | |
} | |
GLAPI void GLAPIENTRY glLightModeli( GLenum pname, GLint param ){ | |
} | |
GLAPI void GLAPIENTRY glActiveTextureARB(GLenum texture){ | |
} | |
GLAPI void GLAPIENTRY glDeleteLists( GLuint list, GLsizei range ){ | |
} | |
GLAPI GLuint GLAPIENTRY glGenLists( GLsizei range ){ | |
puts(__func__); | |
return 0; | |
} | |
GLAPI void GLAPIENTRY glNewList( GLuint list, GLenum mode ){ | |
} | |
GLAPI void GLAPIENTRY glEndList( void ){ | |
} | |
GLAPI void GLAPIENTRY glVertex3fv( const GLfloat *v ){ | |
} | |
GLAPI void GLAPIENTRY glLightfv( GLenum light, GLenum pname, const GLfloat *params) { | |
} | |
GLAPI void GLAPIENTRY glAlphaFunc( GLenum func, GLclampf ref ){} | |
GLAPI void GLAPIENTRY glDepthMask( GLboolean flag ){} | |
GLAPI void GLAPIENTRY glPushMatrix( void ){} | |
GLAPI void GLAPIENTRY glPopMatrix( void ){} | |
GLAPI void GLAPIENTRY glRotatef( GLfloat angle,GLfloat x, GLfloat y, GLfloat z ){} | |
GLAPI void GLAPIENTRY glTranslatef( GLfloat x, GLfloat y, GLfloat z ){} | |
GLAPI void GLAPIENTRY glVertex3f( GLfloat x, GLfloat y, GLfloat z ){} | |
GLAPI void GLAPIENTRY glNormal3f( GLfloat nx, GLfloat ny, GLfloat nz ){} | |
GLAPI void GLAPIENTRY glNormal3fv( const GLfloat *v ){} | |
GLAPI void GLAPIENTRY glColor4ub( GLubyte red, GLubyte green,GLubyte blue, GLubyte alpha){} | |
GLAPI void GLAPIENTRY glColor4ubv( const GLubyte *v ){} | |
GLAPI void GLAPIENTRY glTexCoord2fv( const GLfloat *v ){} | |
GLAPI void GLAPIENTRY glClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ){} | |
GLAPI void GLAPIENTRY glScalef( GLfloat x, GLfloat y, GLfloat z ){} | |
GLAPI void GLAPIENTRY glMatrixMode( GLenum mode ){} | |
GLAPI void GLAPIENTRY glVertex2i( GLint x, GLint y ){} | |
GLAPI void GLAPIENTRY glDrawRangeElements( GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices){} | |
GLAPI void GLAPIENTRY glGetIntegerv( GLenum pname, GLint *params ){} | |
GLAPI GLenum GLAPIENTRY glGetError( void ){ | |
puts(__func__); | |
return 0; | |
} | |
GLAPI void GLAPIENTRY glViewport( GLint x, GLint y, GLsizei width, GLsizei height ){} | |
GLAPI void GLAPIENTRY glMultMatrixf( const GLfloat *m ){} | |
GLAPI void GLAPIENTRY glDisableClientState( GLenum cap ){} | |
GLAPI void GLAPIENTRY glTexCoord3f( GLfloat s, GLfloat t, GLfloat r ){} | |
GLAPI void GLAPIENTRY glTexCoord3fv( const GLfloat *v ){} | |
GLAPI void GLAPIENTRY glTexGeni( GLenum coord, GLenum pname, GLint param ){} | |
GLAPI void GLAPIENTRY glTexGeniv( GLenum coord, GLenum pname, const GLint *params ){} | |
GLAPI void GLAPIENTRY glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *ptr){} | |
GLAPI void GLAPIENTRY glNormalPointer( GLenum type, GLsizei stride,const GLvoid *ptr){} | |
GLAPI void GLAPIENTRY glDrawElements( GLenum mode, GLsizei count,GLenum type, const GLvoid *indices){} | |
GLAPI void GLAPIENTRY glTexEnvi( GLenum target, GLenum pname, GLint param ){} | |
GLAPI void GLAPIENTRY glMaterialf( GLenum face, GLenum pname, GLfloat param ){} | |
GLAPI void GLAPIENTRY gluLookAt (GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ){} | |
GLAPI void GLAPIENTRY gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar){} | |
static void *v3d2_GL_GetProcAddress(_THIS, const char* proc) { | |
//printf("v3d2_GL_GetProcAddress(%p,%s)\n",this,proc); | |
#define X(x) if (strcmp(proc,#x) == 0) return x | |
X(glFlush); | |
X(glGetString); | |
X(glOrtho); | |
X(glBlendFunc); | |
X(glLoadIdentity); | |
X(glBegin); | |
X(glEnd); | |
X(glEnable); | |
X(glDisable); | |
X(glColor4f); | |
X(glGenTextures); | |
X(glBindTexture); | |
X(glTexImage2D); | |
#undef X | |
#define X(x) if (strcmp(proc,#x) == 0) return v3d2_FIXME | |
X(glMatrixMode); | |
X(glPixelStorei); | |
X(glPopAttrib); | |
X(glPopClientAttrib); | |
X(glPopMatrix); | |
X(glPushAttrib); | |
X(glPushClientAttrib); | |
X(glPushMatrix); | |
X(glTexCoord2f); | |
X(glTexEnvf); | |
X(glTexParameteri); | |
X(glTexSubImage2D); | |
X(glVertex2i); | |
X(glViewport); | |
#undef X | |
printf("X(%s);\n",proc); | |
return 0; | |
} | |
static int v3d2_available(void) { | |
return v3d2Supported(); | |
/*int fd = open("/dev/v3d2",O_RDONLY); | |
if (fd == -1) { | |
printf("cant open /dev/v3d2, %s\n",strerror(errno)); | |
return 0; | |
} | |
// FIXME, add version checks | |
close(fd); | |
puts("v3d2 supported"); | |
return 1;*/ | |
} | |
static void v3d2_DeleteDevice(SDL_VideoDevice *device) { | |
if (device) { | |
SDL_free(device); | |
} | |
} | |
static void v3d2_PumpEvents(_THIS) { | |
} | |
static void v3d2_GL_SwapBuffers(_THIS) { | |
} | |
static SDL_VideoDevice *v3d2_create(int devindex) { | |
SDL_VideoDevice *device = NULL; | |
device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); | |
if ( device ) { | |
SDL_memset(device, 0, (sizeof *device)); | |
} | |
if ( (device == NULL) ) { | |
SDL_OutOfMemory(); | |
return(0); | |
} | |
puts("made v3d2 device"); | |
device->VideoInit = v3d2_VideoInit; | |
device->InitOSKeymap = v3d2_InitOSKeymap; | |
device->ListModes = v3d2_ListModes; | |
device->SetVideoMode = v3d2_SetVideoMode; | |
device->GL_LoadLibrary = v3d2_GL_LoadLibrary; | |
device->GL_GetProcAddress = v3d2_GL_GetProcAddress; | |
device->VideoQuit = v3d2_VideoQuit; | |
device->free = v3d2_DeleteDevice; | |
device->PumpEvents = v3d2_PumpEvents; | |
device->GL_SwapBuffers = v3d2_GL_SwapBuffers; | |
return device; | |
} | |
VideoBootStrap V3D2_bootstrap = { | |
"v3d2","rpi v3d core",v3d2_available,v3d2_create | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment