diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gwin/gwin_gl3d.c | 171 | ||||
-rw-r--r-- | src/gwin/gwin_gl3d.h | 70 | ||||
-rw-r--r-- | src/gwin/sys_defs.h | 5 | ||||
-rw-r--r-- | src/gwin/sys_make.mk | 4 | ||||
-rw-r--r-- | src/gwin/sys_options.h | 7 |
5 files changed, 254 insertions, 3 deletions
diff --git a/src/gwin/gwin_gl3d.c b/src/gwin/gwin_gl3d.c new file mode 100644 index 00000000..e04875c0 --- /dev/null +++ b/src/gwin/gwin_gl3d.c @@ -0,0 +1,171 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gwin/gwin_gl3d.c + * @brief GWIN sub-system button code + */ + +#include "gfx.h" + +#if GFX_USE_GWIN && GWIN_NEED_GL3D + +#if GDISP_PIXELFORMAT != GDISP_PIXELFORMAT_RGB565 + #error "GWIN: GL3D only support GDISP_PIXELFORMAT_RGB565 color format (TinyGL limitation)" +#endif + +#include "src/gwin/class_gwin.h" + +#include "3rdparty/tinygl-0.4-ugfx/src/zgl.h" + +// Forward definitions +static void gl3dDestroy(GWindowObject *gh); +static void gl3dRedraw(GWindowObject *gh); +static int gl3dResizeGLViewport(GLContext *c, int *xsize_ptr, int *ysize_ptr); + +static const gwinVMT gl3dVMT = { + "GL3D", // The classname + sizeof(GGL3DObject), // The object size + gl3dDestroy, // The destroy routine + gl3dRedraw, // The redraw routine + 0, // The after-clear routine +}; + +static bool_t haveGLwindow = FALSE; + +GHandle gwinGGL3DCreate(GDisplay *g, GGL3DObject *gl, const GWindowInit *pInit) { + ZBuffer * zb; + GLContext * glcxt; + + // Only one GL3D window allowed at a time (TinyGL limitation) + if (haveGLwindow) + return 0; + + if (!(gl = (GGL3DObject *)_gwindowCreate(g, &gl->g, pInit, &gl3dVMT, 0))) + return 0; + + // Must be a multiple of 4 bytes + gl->g.width &= ~3; + gl->g.height &= ~3; + + zb = ZB_open(gl->g.width, gl->g.height, ZB_MODE_5R6G5B, 0, NULL, NULL, NULL); + if (!zb) { + if ((gl->g.flags & GWIN_FLG_DYNAMIC)) + gfxFree(gl); + return 0; + } + + /* initialisation of the TinyGL interpreter */ + glInit(zb); + gl->glcxt = glcxt = gl_get_context(); + glcxt->opaque = gl; + glcxt->gl_resize_viewport = gl3dResizeGLViewport; + + /* set the viewport : we force a call to the viewport resize routine */ + glcxt->viewport.xsize=-1; + glcxt->viewport.ysize=-1; + + glViewport(0, 0, gl->g.width, gl->g.height); + + haveGLwindow = TRUE; + gwinSetVisible((GHandle)gl, pInit->show); + return (GHandle)gl; +} + +static void gl3dDestroy(GWindowObject *gh) { + (void) gh; + glClose(); + haveGLwindow = FALSE; +} + +static void gl3dRedraw(GWindowObject *gh) { + ZBuffer * zb; + + zb = ((GGL3DObject *)gh)->glcxt->zb; + gdispGBlitArea(gh->display, gh->x, gh->y, zb->xsize, zb->ysize, 0, 0, zb->linesize/sizeof(color_t), (const pixel_t *)zb->pbuf); +} + +static int gl3dResizeGLViewport(GLContext *c, int *xsize_ptr, int *ysize_ptr) { + int cx, cy; + + cx = *xsize_ptr; + cy = *ysize_ptr; + + // We ensure that cx and cy are multiples of 4 for the zbuffer. TODO: find a better solution + cx &= ~3; + cy &= ~3; + + if (cx <= 0 || cy <= 0) + return -1; + + *xsize_ptr = cx; + *ysize_ptr = cy; + + // Resize the GWIN??? + + // Resize the Z buffer + ZB_resize(c->zb, NULL, cx, cy); + return 0; +} + +/** + * TinyGL support routines + */ + +#include <string.h> + +#define NO_CLIBRARY + +void tgl_warning(const char *format, ...) { (void)format; } +void tgl_trace(const char *format, ...) { (void)format; } +void tgl_fixme(const char *format, ...) { (void)format; } +void gl_fatal_error(char *format, ...) { gfxHalt(format); } +void gl_assert(int test) { if (!test) gfxHalt("TinyGL Assert"); } + +void gl_free(void *p) { gfxFree(p); } +void *gl_malloc(int size) { return gfxAlloc(size); } + +void *gl_zalloc(int size) { + void *p; + + p = gfxAlloc(size); + if (p) + memset(p, 0, size); + return p; +} + + +/** + * Pre-load TinyGL headers + */ + +/** + * TinyGL wrapper code + */ + +#include "3rdparty/tinygl-0.4-ugfx/src/api.c" +#include "3rdparty/tinygl-0.4-ugfx/src/list.c" +#include "3rdparty/tinygl-0.4-ugfx/src/vertex.c" +#include "3rdparty/tinygl-0.4-ugfx/src/init.c" +#include "3rdparty/tinygl-0.4-ugfx/src/matrix.c" +#include "3rdparty/tinygl-0.4-ugfx/src/texture.c" +#include "3rdparty/tinygl-0.4-ugfx/src/misc.c" +#include "3rdparty/tinygl-0.4-ugfx/src/clear.c" +#include "3rdparty/tinygl-0.4-ugfx/src/light.c" +#include "3rdparty/tinygl-0.4-ugfx/src/clip.c" +#include "3rdparty/tinygl-0.4-ugfx/src/select.c" +#include "3rdparty/tinygl-0.4-ugfx/src/get.c" +#include "3rdparty/tinygl-0.4-ugfx/src/zbuffer.c" +#include "3rdparty/tinygl-0.4-ugfx/src/zline.c" +#include "3rdparty/tinygl-0.4-ugfx/src/zdither.c" +#include "3rdparty/tinygl-0.4-ugfx/src/ztriangle.c" +#include "3rdparty/tinygl-0.4-ugfx/src/zmath.c" +#include "3rdparty/tinygl-0.4-ugfx/src/image_util.c" +#include "3rdparty/tinygl-0.4-ugfx/src/arrays.c" +#include "3rdparty/tinygl-0.4-ugfx/src/specbuf.c" + +#endif /* GFX_USE_GWIN && GWIN_NEED_GL3D */ diff --git a/src/gwin/gwin_gl3d.h b/src/gwin/gwin_gl3d.h new file mode 100644 index 00000000..ca3edf6f --- /dev/null +++ b/src/gwin/gwin_gl3d.h @@ -0,0 +1,70 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gwin/gwin_gl3d.h + * @brief GWIN 3D module header file + * + * @defgroup 3D 3D + * @ingroup Windows + * + * @details 3D GWIN window based on OpenGL (or more exactly Tiny GL) + * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h + * @pre GWIN_NEED_GL3D must be set to TRUE in your gfxconf.h + * + * @{ + */ + +#ifndef _GWIN_GL3D_H +#define _GWIN_GL3D_H + +/* This file is included within "gwin/gwin.h" */ + + +// A gl3d window +typedef struct GGL3DObject { + GWindowObject g; + struct GLContext * glcxt; + } GGL3DObject; + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Create a gl3d window. + * @return NULL if there is no resultant drawing area, otherwise a window handle. + * + * @param[in] g The GDisplay to display this window on + * @param[in] gg The GGL3DObject structure to initialise. If this is NULL the structure is dynamically allocated. + * @param[in] pInit The initialization parameters to use + * + * @note The drawing color and the background color get set to the current defaults. If you haven't called + * @p gwinSetDefaultColor() or @p gwinSetDefaultBgColor() then these are White and Black respectively. + * @note The font gets set to the current default font. If you haven't called @p gwinSetDefaultFont() then there + * is no default font and text drawing operations will no nothing. + * @note The dimensions and position may be changed to fit on the real screen. + * + * @api + */ +GHandle gwinGGL3DCreate(GDisplay *g, GGL3DObject *gg, const GWindowInit *pInit); +#define gwinGL3DCreate(gg, pInit) gwinGGL3DCreate(GDISP, gg, pInit) + +/* Include the gl interface */ +#include "3rdparty/tinygl-0.4-ugfx/include/GL/gl.h" + +#ifdef __cplusplus +} +#endif + +#endif /* _GWIN_GL3D_H */ +/** @} */ + diff --git a/src/gwin/sys_defs.h b/src/gwin/sys_defs.h index 4b103d11..7823eafe 100644 --- a/src/gwin/sys_defs.h +++ b/src/gwin/sys_defs.h @@ -962,14 +962,15 @@ extern "C" { #if GWIN_NEED_CONSOLE || defined(__DOXYGEN__) #include "src/gwin/console.h" #endif - #if GWIN_NEED_GRAPH || defined(__DOXYGEN__) #include "src/gwin/graph.h" #endif - #if GWIN_NEED_IMAGE || defined(__DOXYGEN__) #include "src/gwin/gimage.h" #endif + #if GWIN_NEED_GL3D || defined(__DOXYGEN__) + #include "src/gwin/gwin_gl3d.h" + #endif #endif /* GFX_USE_GWIN */ diff --git a/src/gwin/sys_make.mk b/src/gwin/sys_make.mk index 95a2ba84..f905f8d3 100644 --- a/src/gwin/sys_make.mk +++ b/src/gwin/sys_make.mk @@ -13,4 +13,6 @@ GFXSRC += $(GFXLIB)/src/gwin/gwin.c \ $(GFXLIB)/src/gwin/progressbar.c \ $(GFXLIB)/src/gwin/gcontainer.c \ $(GFXLIB)/src/gwin/frame.c \ - + $(GFXLIB)/src/gwin/gwin_gl3d.c \ + +GFXINC += $(GFXLIB)/3rdparty/tinygl-0.4-ugfx/include diff --git a/src/gwin/sys_options.h b/src/gwin/sys_options.h index d5240556..199cad5b 100644 --- a/src/gwin/sys_options.h +++ b/src/gwin/sys_options.h @@ -73,6 +73,13 @@ #define GWIN_NEED_GRAPH FALSE #endif /** + * @brief Should gl3d functions be included. + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_GL3D + #define GWIN_NEED_GL3D FALSE + #endif + /** * @brief Should button functions be included. * @details Defaults to FALSE */ |