From 0e87f046c50298473d2eeb287a8e10aacbaf0218 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 8 May 2008 22:38:07 +0000 Subject: [PATCH] set_pixel_zoom --- panda/src/display/config_display.cxx | 4 + panda/src/display/config_display.h | 2 + panda/src/display/displayRegion.cxx | 30 +++++- panda/src/display/displayRegion.h | 2 + panda/src/display/drawableRegion.I | 93 ++++++++++++++++++- panda/src/display/drawableRegion.cxx | 28 ++++++ panda/src/display/drawableRegion.h | 12 +++ panda/src/display/graphicsOutput.I | 34 ++++++- panda/src/display/graphicsOutput.cxx | 17 +++- panda/src/display/graphicsOutput.h | 4 +- panda/src/display/graphicsWindow.cxx | 1 + .../tinydisplay/tinyGraphicsStateGuardian.cxx | 65 +++++++++++++ .../tinydisplay/tinyGraphicsStateGuardian.h | 4 + .../src/tinydisplay/tinyWinGraphicsWindow.cxx | 38 +++++++- panda/src/tinydisplay/tinyWinGraphicsWindow.h | 1 + panda/src/tinydisplay/vertex.cxx | 4 +- panda/src/tinydisplay/zbuffer.cxx | 45 +++++---- panda/src/tinydisplay/zbuffer.h | 22 ++--- panda/src/tinydisplay/zgl.h | 2 +- panda/src/tinydisplay/zline.cxx | 14 +-- panda/src/tinydisplay/zline.h | 2 +- panda/src/tinydisplay/ztriangle.cxx | 36 +++---- panda/src/tinydisplay/ztriangle.h | 4 +- panda/src/tinydisplay/ztriangle_two.h | 30 +++--- 24 files changed, 398 insertions(+), 96 deletions(-) diff --git a/panda/src/display/config_display.cxx b/panda/src/display/config_display.cxx index bb1aefece6..6958b12afa 100644 --- a/panda/src/display/config_display.cxx +++ b/panda/src/display/config_display.cxx @@ -295,6 +295,10 @@ ConfigVariableInt back_buffers ("back-buffers", 1, PRC_DESC("The default number of back buffers requested.")); +ConfigVariableDouble pixel_zoom +("pixel-zoom", 1.0, + PRC_DESC("The default pixel_zoom factor for new windows.")); + ConfigVariableDouble background_color ("background-color", "0.41 0.41 0.41", PRC_DESC("Specifies the rgb(a) value of the default background color for a " diff --git a/panda/src/display/config_display.h b/panda/src/display/config_display.h index 608bbf5cef..177930fa84 100644 --- a/panda/src/display/config_display.h +++ b/panda/src/display/config_display.h @@ -88,6 +88,8 @@ extern EXPCL_PANDA_DISPLAY ConfigVariableInt stencil_bits; extern EXPCL_PANDA_DISPLAY ConfigVariableInt multisamples; extern EXPCL_PANDA_DISPLAY ConfigVariableInt back_buffers; +extern EXPCL_PANDA_DISPLAY ConfigVariableDouble pixel_zoom; + extern EXPCL_PANDA_DISPLAY ConfigVariableDouble background_color; extern EXPCL_PANDA_DISPLAY ConfigVariableBool sync_video; extern EXPCL_PANDA_DISPLAY ConfigVariableBool basic_shaders_only; diff --git a/panda/src/display/displayRegion.cxx b/panda/src/display/displayRegion.cxx index 7ef8ac23fa..ca0b77597a 100644 --- a/panda/src/display/displayRegion.cxx +++ b/panda/src/display/displayRegion.cxx @@ -136,7 +136,7 @@ set_dimensions(float l, float r, float b, float t) { cdata->_t = t; if (_window != (GraphicsOutput *)NULL && _window->has_size()) { - do_compute_pixels(_window->get_x_size(), _window->get_y_size(), cdata); + do_compute_pixels(_window->get_fb_x_size(), _window->get_fb_y_size(), cdata); } } @@ -296,7 +296,7 @@ compute_pixels() { if (_window != (GraphicsOutput *)NULL) { CDWriter cdata(_cycler); - do_compute_pixels(_window->get_x_size(), _window->get_y_size(), + do_compute_pixels(_window->get_fb_x_size(), _window->get_fb_y_size(), cdata); } } @@ -316,7 +316,7 @@ compute_pixels_all_stages() { if (_window != (GraphicsOutput *)NULL) { OPEN_ITERATE_ALL_STAGES(_cycler) { CDStageWriter cdata(_cycler, pipeline_stage); - do_compute_pixels(_window->get_x_size(), _window->get_y_size(), + do_compute_pixels(_window->get_fb_x_size(), _window->get_fb_y_size(), cdata); } CLOSE_ITERATE_ALL_STAGES(_cycler); @@ -554,6 +554,30 @@ make_cull_result_graph() { return cull_result->make_result_graph(); } +//////////////////////////////////////////////////////////////////// +// Function: DisplayRegion::supports_pixel_zoom +// Access: Published, Virtual +// Description: Returns true if a call to set_pixel_zoom() will be +// respected, false if it will be ignored. If this +// returns false, then get_pixel_factor() will always +// return 1.0, regardless of what value you specify for +// set_pixel_zoom(). +// +// This may return false if the underlying renderer +// doesn't support pixel zooming, or if you have called +// this on a DisplayRegion that doesn't have both +// set_clear_color() and set_clear_depth() enabled. +//////////////////////////////////////////////////////////////////// +bool DisplayRegion:: +supports_pixel_zoom() const { + if (_window != (GraphicsOutput *)NULL) { + if (_window->supports_pixel_zoom()) { + return get_clear_color_active() && get_clear_depth_active(); + } + } + return false; +} + //////////////////////////////////////////////////////////////////// // Function: DisplayRegion::win_display_regions_changed // Access: Private diff --git a/panda/src/display/displayRegion.h b/panda/src/display/displayRegion.h index b8110ef88f..0113ed9b42 100644 --- a/panda/src/display/displayRegion.h +++ b/panda/src/display/displayRegion.h @@ -128,6 +128,8 @@ PUBLISHED: PT(PandaNode) make_cull_result_graph(); public: + virtual bool supports_pixel_zoom() const; + INLINE void set_cull_result(CullResult *cull_result, SceneSetup *scene_setup, Thread *current_thread); INLINE CullResult *get_cull_result(Thread *current_thread) const; diff --git a/panda/src/display/drawableRegion.I b/panda/src/display/drawableRegion.I index 7c28fcba42..9726247f25 100644 --- a/panda/src/display/drawableRegion.I +++ b/panda/src/display/drawableRegion.I @@ -32,6 +32,8 @@ DrawableRegion() : _clear_value[i] = Colorf(0.0f, 0.0f, 0.0f, 0.0f); } _clear_value[RTP_depth] = Colorf(1.0f,1.0f,1.0f,1.0f); + _pixel_zoom = 1.0f; + _pixel_factor = 1.0f; } //////////////////////////////////////////////////////////////////// @@ -42,7 +44,9 @@ DrawableRegion() : INLINE DrawableRegion:: DrawableRegion(const DrawableRegion ©) : _screenshot_buffer_type(copy._screenshot_buffer_type), - _draw_buffer_type(copy._draw_buffer_type) + _draw_buffer_type(copy._draw_buffer_type), + _pixel_zoom(copy._pixel_zoom), + _pixel_factor(copy._pixel_factor) { for (int i=0; i= 0)&&(n < RTP_COUNT)); _clear_active[n] = clear_active; + update_pixel_factor(); } //////////////////////////////////////////////////////////////////// @@ -296,6 +306,7 @@ disable_clears() { for (int i=0; icompute_pixels_all_stages(x, y); + (*dri)->compute_pixels_all_stages(fb_x_size, fb_y_size); } if (_texture_card != 0) { @@ -920,6 +923,18 @@ void GraphicsOutput:: end_frame(FrameMode mode, Thread *current_thread) { } +//////////////////////////////////////////////////////////////////// +// Function: GraphicsOutput::pixel_factor_changed +// Access: Published, Virtual +// Description: Called internally when the pixel factor changes. +//////////////////////////////////////////////////////////////////// +void GraphicsOutput:: +pixel_factor_changed() { + if (_has_size) { + set_size_and_recalc(_x_size, _y_size); + } +} + //////////////////////////////////////////////////////////////////// // Function: GraphicsOutput::prepare_for_deletion // Access: Protected diff --git a/panda/src/display/graphicsOutput.h b/panda/src/display/graphicsOutput.h index a8b1c31a2c..1e3657174d 100644 --- a/panda/src/display/graphicsOutput.h +++ b/panda/src/display/graphicsOutput.h @@ -108,6 +108,8 @@ PUBLISHED: INLINE int get_x_size() const; INLINE int get_y_size() const; + INLINE int get_fb_x_size() const; + INLINE int get_fb_y_size() const; INLINE bool has_size() const; INLINE bool is_valid() const; @@ -214,7 +216,7 @@ public: INLINE PStatCollector &get_draw_window_pcollector(); protected: - + virtual void pixel_factor_changed(); void prepare_for_deletion(); void copy_to_textures(); diff --git a/panda/src/display/graphicsWindow.cxx b/panda/src/display/graphicsWindow.cxx index b336ec8042..759fb50903 100644 --- a/panda/src/display/graphicsWindow.cxx +++ b/panda/src/display/graphicsWindow.cxx @@ -71,6 +71,7 @@ GraphicsWindow(GraphicsPipe *pipe, request_properties(win_prop); _window_event = "window-event"; + set_pixel_zoom(pixel_zoom); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx b/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx index 2b075eb92a..2d27bf706d 100644 --- a/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx +++ b/panda/src/tinydisplay/tinyGraphicsStateGuardian.cxx @@ -504,6 +504,8 @@ TinyGraphicsStateGuardian(GraphicsPipe *pipe, GraphicsStateGuardian(CS_yup_right, pipe), _textures_lru("textures_lru", td_texture_ram) { + _current_frame_buffer = NULL; + _aux_frame_buffer = NULL; _c = NULL; _vertices = NULL; _vertices_size = 0; @@ -565,6 +567,11 @@ reset() { //////////////////////////////////////////////////////////////////// void TinyGraphicsStateGuardian:: free_pointers() { + if (_aux_frame_buffer != (ZBuffer *)NULL) { + ZB_close(_aux_frame_buffer); + _aux_frame_buffer = NULL; + } + if (_vertices != (GLVertex *)NULL) { PANDA_FREE_ARRAY(_vertices); _vertices = NULL; @@ -679,6 +686,31 @@ prepare_display_region(DisplayRegionPipelineReader *dr, int xmin, ymin, xsize, ysize; dr->get_region_pixels_i(xmin, ymin, xsize, ysize); + float pixel_factor = _current_display_region->get_pixel_factor(); + if (pixel_factor != 1.0) { + // Render into an aux buffer, and zoom it up into the main + // frame buffer later. + xmin = 0; + ymin = 0; + xsize = int(xsize * pixel_factor); + ysize = int(ysize * pixel_factor); + if (_aux_frame_buffer == (ZBuffer *)NULL) { + // We add 3 to xsize, since ZB_open may resize the frame buffer + // down by up to 3 pixels to make it fit within the + // word-alignment rule. + _aux_frame_buffer = ZB_open(xsize + 3, ysize, ZB_MODE_RGBA, 0, 0, 0, 0); + } else if (_aux_frame_buffer->xsize < xsize || _aux_frame_buffer->ysize < ysize) { + ZB_resize(_aux_frame_buffer, NULL, + max(_aux_frame_buffer->xsize, xsize) + 3, + max(_aux_frame_buffer->ysize, ysize)); + } + _c->zb = _aux_frame_buffer; + + } else { + // Render directly into the main frame buffer. + _c->zb = _current_frame_buffer; + } + _c->viewport.xmin = xmin; _c->viewport.ymin = ymin; _c->viewport.xsize = xsize; @@ -807,6 +839,39 @@ begin_scene() { //////////////////////////////////////////////////////////////////// void TinyGraphicsStateGuardian:: end_scene() { + if (_c->zb == _aux_frame_buffer) { + // Copy the aux frame buffer into the main scene now, zooming it + // up to the appropriate size. + int xmin, ymin, xsize, ysize; + _current_display_region->get_region_pixels_i(xmin, ymin, xsize, ysize); + float pixel_factor = _current_display_region->get_pixel_factor(); + + int fb_xsize = int(xsize * pixel_factor); + int fb_ysize = int(ysize * pixel_factor); + + int tyinc = _current_frame_buffer->linesize / PSZB; + int fyinc = _aux_frame_buffer->linesize / PSZB; + + int fyt = 0; + for (int ty = 0; ty < ysize; ++ty) { + int fy = fyt / ysize; + fyt += fb_ysize; + + PIXEL *tp = _current_frame_buffer->pbuf + xmin + (ymin + ty) * tyinc; + PIXEL *fp = _aux_frame_buffer->pbuf + fy * fyinc; + ZPOINT *tz = _current_frame_buffer->zbuf + xmin + (ymin + ty) * _current_frame_buffer->xsize; + ZPOINT *fz = _aux_frame_buffer->zbuf + fy * _aux_frame_buffer->xsize; + int fxt = 0; + for (int tx = 0; tx < xsize; ++tx) { + int fx = fxt / xsize; + fxt += fb_xsize; + + tp[tx] = fp[fx]; + tz[tx] = fz[fx]; + } + } + _c->zb = _current_frame_buffer; + } GraphicsStateGuardian::end_scene(); } diff --git a/panda/src/tinydisplay/tinyGraphicsStateGuardian.h b/panda/src/tinydisplay/tinyGraphicsStateGuardian.h index 68432db7c8..d6badb941f 100644 --- a/panda/src/tinydisplay/tinyGraphicsStateGuardian.h +++ b/panda/src/tinydisplay/tinyGraphicsStateGuardian.h @@ -124,6 +124,10 @@ public: ZBuffer *_current_frame_buffer; private: + // Allocated by prepare_display_region when necessary for a zoomed + // display region. + ZBuffer *_aux_frame_buffer; + GLContext *_c; enum ColorMaterialFlags { diff --git a/panda/src/tinydisplay/tinyWinGraphicsWindow.cxx b/panda/src/tinydisplay/tinyWinGraphicsWindow.cxx index c099ed3cf1..b443b25d9a 100755 --- a/panda/src/tinydisplay/tinyWinGraphicsWindow.cxx +++ b/panda/src/tinydisplay/tinyWinGraphicsWindow.cxx @@ -48,6 +48,7 @@ TinyWinGraphicsWindow(GraphicsPipe *pipe, { _frame_buffer = NULL; _hdc = (HDC)0; + update_pixel_factor(); } //////////////////////////////////////////////////////////////////// @@ -133,17 +134,46 @@ begin_flip() { HDC bmdc = CreateCompatibleDC(_hdc); SelectObject(bmdc, bm); - SetDIBits(_hdc, bm, 0, _frame_buffer->ysize, _frame_buffer->pbuf, + int fb_xsize = get_fb_x_size(); + int fb_ysize = get_fb_y_size(); + int fb_ytop = _frame_buffer->ysize - fb_ysize; + + SetDIBits(_hdc, bm, fb_ytop, fb_ysize, _frame_buffer->pbuf, &_bitmap_info, DIB_RGB_COLORS); - BitBlt(_hdc, 0, 0, _frame_buffer->xsize, _frame_buffer->ysize, - bmdc, 0, 0, SRCCOPY); - + if (fb_xsize == _frame_buffer->xsize) { + BitBlt(_hdc, 0, 0, fb_xsize, fb_ysize, + bmdc, 0, 0, SRCCOPY); + } else { + StretchBlt(_hdc, 0, 0, _frame_buffer->xsize, _frame_buffer->ysize, + bmdc, 0, 0,fb_xsize, fb_ysize, + SRCCOPY); + } + DeleteDC(bmdc); DeleteObject(bm); GdiFlush(); } +//////////////////////////////////////////////////////////////////// +// Function: TinyWinGraphicsWindow::supports_pixel_zoom +// Access: Published, Virtual +// Description: Returns true if a call to set_pixel_zoom() will be +// respected, false if it will be ignored. If this +// returns false, then get_pixel_factor() will always +// return 1.0, regardless of what value you specify for +// set_pixel_zoom(). +// +// This may return false if the underlying renderer +// doesn't support pixel zooming, or if you have called +// this on a DisplayRegion that doesn't have both +// set_clear_color() and set_clear_depth() enabled. +//////////////////////////////////////////////////////////////////// +bool TinyWinGraphicsWindow:: +supports_pixel_zoom() const { + return true; +} + //////////////////////////////////////////////////////////////////// // Function: TinyWinGraphicsWindow::close_window // Access: Protected, Virtual diff --git a/panda/src/tinydisplay/tinyWinGraphicsWindow.h b/panda/src/tinydisplay/tinyWinGraphicsWindow.h index 02aad7c6e0..a523165c09 100755 --- a/panda/src/tinydisplay/tinyWinGraphicsWindow.h +++ b/panda/src/tinydisplay/tinyWinGraphicsWindow.h @@ -46,6 +46,7 @@ public: virtual void end_frame(FrameMode mode, Thread *current_thread); virtual void begin_flip(); + virtual bool supports_pixel_zoom() const; protected: virtual void close_window(); diff --git a/panda/src/tinydisplay/vertex.cxx b/panda/src/tinydisplay/vertex.cxx index 3328ba94f5..d429ddb4ee 100644 --- a/panda/src/tinydisplay/vertex.cxx +++ b/panda/src/tinydisplay/vertex.cxx @@ -4,13 +4,13 @@ void gl_eval_viewport(GLContext * c) { GLViewport *v; - float zsize = (1 << (ZB_Z_BITS + ZB_POINT_Z_FRAC_BITS)); + float zsize = ((long long)1 << (ZB_Z_BITS + ZB_POINT_Z_FRAC_BITS)); v = &c->viewport; v->trans.X = ((v->xsize - 0.5f) / 2.0f) + v->xmin; v->trans.Y = ((v->ysize - 0.5f) / 2.0f) + v->ymin; - v->trans.Z = ((zsize - 0.5f) / 2.0f) + ((1 << ZB_POINT_Z_FRAC_BITS)) / 2; + v->trans.Z = ((zsize - 0.5f) / 2.0f); v->scale.X = (v->xsize - 0.5f) / 2.0f; v->scale.Y = -(v->ysize - 0.5f) / 2.0f; diff --git a/panda/src/tinydisplay/zbuffer.cxx b/panda/src/tinydisplay/zbuffer.cxx index b2994203f7..aa7dc881fd 100644 --- a/panda/src/tinydisplay/zbuffer.cxx +++ b/panda/src/tinydisplay/zbuffer.cxx @@ -12,7 +12,7 @@ ZBuffer *ZB_open(int xsize, int ysize, int mode, int nb_colors, unsigned char *color_indexes, - int *color_table, + unsigned int *color_table, void *frame_buffer) { ZBuffer *zb; @@ -49,9 +49,9 @@ ZBuffer *ZB_open(int xsize, int ysize, int mode, goto error; } - size = zb->xsize * zb->ysize * sizeof(unsigned short); + size = zb->xsize * zb->ysize * sizeof(ZPOINT); - zb->zbuf = (unsigned short *)gl_malloc(size); + zb->zbuf = (ZPOINT *)gl_malloc(size); if (zb->zbuf == NULL) goto error; @@ -100,9 +100,9 @@ void ZB_resize(ZBuffer * zb, void *frame_buffer, int xsize, int ysize) zb->ysize = ysize; zb->linesize = (xsize * PSZB + 3) & ~3; - size = zb->xsize * zb->ysize * sizeof(unsigned short); + size = zb->xsize * zb->ysize * sizeof(ZPOINT); gl_free(zb->zbuf); - zb->zbuf = (unsigned short *)gl_malloc(size); + zb->zbuf = (ZPOINT *)gl_malloc(size); if (zb->frame_buffer_allocated) gl_free(zb->pbuf); @@ -142,11 +142,11 @@ static void ZB_copyFrameBuffer5R6G5B(ZBuffer * zb, void *buf, int linesize) { PIXEL *q; - unsigned short *p, *p1; + unsigned char *p, *p1; int y, n; q = zb->pbuf; - p1 = (unsigned short *) buf; + p1 = (unsigned char *) buf; for (y = 0; y < zb->ysize; y++) { p = p1; @@ -159,7 +159,7 @@ static void ZB_copyFrameBuffer5R6G5B(ZBuffer * zb, q += 4; p += 4; } while (--n > 0); - p1 = (unsigned short *)((char *)p1 + linesize); + p1 = (unsigned char *)((char *)p1 + linesize); } } @@ -222,7 +222,7 @@ void memset_s(void *adr, int val, int count) { int i, n, v; unsigned int *p; - unsigned short *q; + unsigned char *q; p = (unsigned int *)adr; v = val | (val << 16); @@ -236,7 +236,7 @@ void memset_s(void *adr, int val, int count) p += 4; } - q = (unsigned short *) p; + q = (unsigned char *) p; n = count & 7; for (i = 0; i < n; i++) *q++ = val; @@ -294,15 +294,15 @@ void memset_RGB24(void *adr,int r, int v, int b,long count) } } -void ZB_clear(ZBuffer * zb, int clear_z, int z, - int clear_color, int r, int g, int b, int a) +void ZB_clear(ZBuffer * zb, int clear_z, ZPOINT z, + int clear_color, unsigned int r, unsigned int g, unsigned int b, unsigned int a) { - int color; + unsigned int color; int y; PIXEL *pp; if (clear_z) { - memset_s(zb->zbuf, z, zb->xsize * zb->ysize); + memset(zb->zbuf, 0, zb->xsize * zb->ysize * sizeof(ZPOINT)); } if (clear_color) { color = RGBA_TO_PIXEL(r, g, b, a); @@ -314,20 +314,19 @@ void ZB_clear(ZBuffer * zb, int clear_z, int z, } } -void ZB_clear_viewport(ZBuffer * zb, int clear_z, int z, - int clear_color, int r, int g, int b, int a, +void ZB_clear_viewport(ZBuffer * zb, int clear_z, ZPOINT z, + int clear_color, unsigned int r, unsigned int g, unsigned int b, unsigned int a, int xmin, int ymin, int xsize, int ysize) { - int color; + unsigned int color; int y; PIXEL *pp; - unsigned short *zz; - int ytop; + ZPOINT *zz; if (clear_z) { zz = zb->zbuf + xmin + ymin * zb->xsize; for (y = 0; y < ysize; ++y) { - memset_s(zz, z, xsize); + memset(zz, 0, xsize * sizeof(ZPOINT)); zz += zb->xsize; } } @@ -344,11 +343,11 @@ void ZB_clear_viewport(ZBuffer * zb, int clear_z, int z, #define ZB_ST_FRAC_HIGH (1 << ZB_POINT_ST_FRAC_BITS) #define ZB_ST_FRAC_MASK (ZB_ST_FRAC_HIGH - 1) -PIXEL lookup_texture_bilinear(ZTexture *texture, int s, int t) +PIXEL lookup_texture_bilinear(ZTexture *texture, unsigned int s, unsigned int t) { PIXEL p1, p2, p3, p4; - int sf, tf; - int r, g, b, a; + unsigned int sf, tf; + unsigned int r, g, b, a; p1 = ZB_LOOKUP_TEXTURE_NEAREST(texture, s, t); p2 = ZB_LOOKUP_TEXTURE_NEAREST(texture, s + ZB_ST_FRAC_HIGH, t); diff --git a/panda/src/tinydisplay/zbuffer.h b/panda/src/tinydisplay/zbuffer.h index fb974ac28b..6fe71ff7d1 100644 --- a/panda/src/tinydisplay/zbuffer.h +++ b/panda/src/tinydisplay/zbuffer.h @@ -7,14 +7,10 @@ #include "zfeatures.h" +typedef unsigned int ZPOINT; #define ZB_Z_BITS 16 - #define ZB_POINT_Z_FRAC_BITS 14 -/* The number of bits for lookup for S and T texture coords. This is - based on a fixed texture size of 256x256. */ -#define ZB_POINT_ST_BITS 8 - /* The number of fractional bits below the S and T texture coords. The more we have, the more precise the texel calculation will be when we zoom into small details of a texture; but the greater @@ -88,7 +84,7 @@ typedef unsigned int PIXEL; typedef struct { PIXEL *pixmap; - int s_mask, t_mask, t_shift; + unsigned int s_mask, t_mask, t_shift; } ZTexture; typedef struct { @@ -96,7 +92,7 @@ typedef struct { int linesize; /* line size, in bytes */ int mode; - unsigned short *zbuf; + ZPOINT *zbuf; PIXEL *pbuf; int frame_buffer_allocated; @@ -120,20 +116,20 @@ typedef struct { ZBuffer *ZB_open(int xsize,int ysize,int mode, int nb_colors, unsigned char *color_indexes, - int *color_table, + unsigned int *color_table, void *frame_buffer); void ZB_close(ZBuffer *zb); void ZB_resize(ZBuffer *zb,void *frame_buffer,int xsize,int ysize); -void ZB_clear(ZBuffer *zb,int clear_z,int z, - int clear_color,int r,int g,int b,int a); -void ZB_clear_viewport(ZBuffer * zb, int clear_z, int z, - int clear_color, int r, int g, int b, int a, +void ZB_clear(ZBuffer *zb, int clear_z, ZPOINT z, + int clear_color, unsigned int r, unsigned int g, unsigned int b, unsigned int a); +void ZB_clear_viewport(ZBuffer * zb, int clear_z, ZPOINT z, + int clear_color, unsigned int r, unsigned int g, unsigned int b, unsigned int a, int xmin, int ymin, int xsize, int ysize); -PIXEL lookup_texture_bilinear(ZTexture *texture, int s, int t); +PIXEL lookup_texture_bilinear(ZTexture *texture, unsigned int s, unsigned int t); /* linesize is in BYTES */ void ZB_copyFrameBuffer(ZBuffer *zb,void *buf,int linesize); diff --git a/panda/src/tinydisplay/zgl.h b/panda/src/tinydisplay/zgl.h index e9745da331..20efc8760a 100644 --- a/panda/src/tinydisplay/zgl.h +++ b/panda/src/tinydisplay/zgl.h @@ -207,7 +207,7 @@ void gl_eval_viewport(GLContext *c); void gl_vertex_transform(GLContext * c, GLVertex * v); /* image_util.c */ -void gl_convertRGB_to_5R6G5B(unsigned short *pixmap,unsigned char *rgb, +void gl_convertRGB_to_5R6G5B(unsigned char *pixmap,unsigned char *rgb, int xsize,int ysize); void gl_convertRGB_to_8A8R8G8B(unsigned int *pixmap, unsigned char *rgb, int xsize, int ysize); diff --git a/panda/src/tinydisplay/zline.cxx b/panda/src/tinydisplay/zline.cxx index afdafa4f45..a1789e6d37 100644 --- a/panda/src/tinydisplay/zline.cxx +++ b/panda/src/tinydisplay/zline.cxx @@ -2,13 +2,13 @@ #include #include "zbuffer.h" -#define ZCMP(z,zpix) ((z) >= (zpix)) +#define ZCMP(z,zpix) ((ZPOINT)(z) >= (ZPOINT)(zpix)) void ZB_plot(ZBuffer * zb, ZBufferPoint * p) { - unsigned short *pz; + ZPOINT *pz; PIXEL *pp; - int zz; + unsigned int zz; pz = zb->zbuf + (p->y * zb->xsize + p->x); pp = (PIXEL *) ((char *) zb->pbuf + zb->linesize * p->y + p->x * PSZB); @@ -21,7 +21,7 @@ void ZB_plot(ZBuffer * zb, ZBufferPoint * p) #define INTERP_Z static void ZB_line_flat_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2, - int color) + unsigned int color) { #include "zline.h" } @@ -37,7 +37,7 @@ static void ZB_line_interp_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) /* no Z interpolation */ static void ZB_line_flat(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2, - int color) + unsigned int color) { #include "zline.h" } @@ -50,7 +50,7 @@ static void ZB_line_interp(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) void ZB_line_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) { - int color1, color2; + unsigned int color1, color2; color1 = RGBA_TO_PIXEL(p1->r, p1->g, p1->b, p1->a); color2 = RGBA_TO_PIXEL(p2->r, p2->g, p2->b, p2->a); @@ -65,7 +65,7 @@ void ZB_line_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) void ZB_line(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2) { - int color1, color2; + unsigned int color1, color2; color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b); color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b); diff --git a/panda/src/tinydisplay/zline.h b/panda/src/tinydisplay/zline.h index 128870ee3a..0c659c49ac 100644 --- a/panda/src/tinydisplay/zline.h +++ b/panda/src/tinydisplay/zline.h @@ -9,7 +9,7 @@ register unsigned int rinc, ginc, binc; #endif #ifdef INTERP_Z - register unsigned short *pz; + register ZPOINT *pz; int zinc; register int z, zz; #endif diff --git a/panda/src/tinydisplay/ztriangle.cxx b/panda/src/tinydisplay/ztriangle.cxx index 831df3af88..74b744e12d 100644 --- a/panda/src/tinydisplay/ztriangle.cxx +++ b/panda/src/tinydisplay/ztriangle.cxx @@ -12,7 +12,7 @@ #define STORE_Z(zpix, z) (zpix) = (z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb) #define ACMP(zb,a) 1 -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zon_noblend_anone_zless #include "ztriangle_two.h" @@ -26,7 +26,7 @@ #define STORE_Z(zpix, z) (zpix) = (z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb) #define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zon_noblend_aless_zless #include "ztriangle_two.h" @@ -40,7 +40,7 @@ #define STORE_Z(zpix, z) (zpix) = (z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb) #define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zon_noblend_amore_zless #include "ztriangle_two.h" @@ -54,7 +54,7 @@ #define STORE_Z(zpix, z) (zpix) = (z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a) #define ACMP(zb,a) 1 -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zon_blend_anone_zless #include "ztriangle_two.h" @@ -68,7 +68,7 @@ #define STORE_Z(zpix, z) (zpix) = (z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a) #define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zon_blend_aless_zless #include "ztriangle_two.h" @@ -82,7 +82,7 @@ #define STORE_Z(zpix, z) (zpix) = (z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a) #define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zon_blend_amore_zless #include "ztriangle_two.h" @@ -96,7 +96,7 @@ #define STORE_Z(zpix, z) (zpix) = (z) #define STORE_PIX(pix, rgb, r, g, b, a) #define ACMP(zb,a) 1 -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zon_nocolor_anone_zless #include "ztriangle_two.h" @@ -110,7 +110,7 @@ #define STORE_Z(zpix, z) (zpix) = (z) #define STORE_PIX(pix, rgb, r, g, b, a) #define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zon_nocolor_aless_zless #include "ztriangle_two.h" @@ -124,7 +124,7 @@ #define STORE_Z(zpix, z) (zpix) = (z) #define STORE_PIX(pix, rgb, r, g, b, a) #define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zon_nocolor_amore_zless #include "ztriangle_two.h" @@ -138,7 +138,7 @@ #define STORE_Z(zpix, z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb) #define ACMP(zb,a) 1 -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zoff_noblend_anone_zless #include "ztriangle_two.h" @@ -152,7 +152,7 @@ #define STORE_Z(zpix, z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb) #define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zoff_noblend_aless_zless #include "ztriangle_two.h" @@ -166,7 +166,7 @@ #define STORE_Z(zpix, z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = (rgb) #define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zoff_noblend_amore_zless #include "ztriangle_two.h" @@ -180,7 +180,7 @@ #define STORE_Z(zpix, z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a) #define ACMP(zb,a) 1 -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zoff_blend_anone_zless #include "ztriangle_two.h" @@ -194,7 +194,7 @@ #define STORE_Z(zpix, z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a) #define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zoff_blend_aless_zless #include "ztriangle_two.h" @@ -208,7 +208,7 @@ #define STORE_Z(zpix, z) #define STORE_PIX(pix, rgb, r, g, b, a) (pix) = PIXEL_BLEND_RGB(pix, r, g, b, a) #define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zoff_blend_amore_zless #include "ztriangle_two.h" @@ -222,7 +222,7 @@ #define STORE_Z(zpix, z) #define STORE_PIX(pix, rgb, r, g, b, a) #define ACMP(zb,a) 1 -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zoff_nocolor_anone_zless #include "ztriangle_two.h" @@ -236,7 +236,7 @@ #define STORE_Z(zpix, z) #define STORE_PIX(pix, rgb, r, g, b, a) #define ACMP(zb,a) (((unsigned int)(a)) < (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zoff_nocolor_aless_zless #include "ztriangle_two.h" @@ -250,6 +250,6 @@ #define STORE_Z(zpix, z) #define STORE_PIX(pix, rgb, r, g, b, a) #define ACMP(zb,a) (((unsigned int)(a)) > (zb)->reference_alpha) -#define ZCMP(zpix, z) ((zpix) < (z)) +#define ZCMP(zpix, z) ((ZPOINT)(zpix) < (ZPOINT)(z)) #define FNAME(name) name ## _xx_zoff_nocolor_amore_zless #include "ztriangle_two.h" diff --git a/panda/src/tinydisplay/ztriangle.h b/panda/src/tinydisplay/ztriangle.h index 761d5646c7..916d9d2d08 100644 --- a/panda/src/tinydisplay/ztriangle.h +++ b/panda/src/tinydisplay/ztriangle.h @@ -5,7 +5,7 @@ { ZBufferPoint *t,*pr1,*pr2,*l1,*l2; float fdx1, fdx2, fdy1, fdy2, fz, d1, d2; - unsigned short *pz1; + ZPOINT *pz1; PIXEL *pp1; int part,update_left,update_right; @@ -258,7 +258,7 @@ register PIXEL *pp; register int n; #ifdef INTERP_Z - register unsigned short *pz; + register ZPOINT *pz; register unsigned int z,zz; #endif #ifdef INTERP_RGB diff --git a/panda/src/tinydisplay/ztriangle_two.h b/panda/src/tinydisplay/ztriangle_two.h index 52d6f882e1..6b080ea97c 100644 --- a/panda/src/tinydisplay/ztriangle_two.h +++ b/panda/src/tinydisplay/ztriangle_two.h @@ -276,7 +276,7 @@ void FNAME(ZB_fillTriangleMappingPerspective) (ZBuffer *zb, #define DRAW_LINE() \ { \ - register unsigned short *pz; \ + register ZPOINT *pz; \ register PIXEL *pp; \ register unsigned int s,t,z,zz; \ register int n,dsdx,dtdx; \ @@ -294,8 +294,8 @@ void FNAME(ZB_fillTriangleMappingPerspective) (ZBuffer *zb, float ss,tt; \ ss=(sz * zinv); \ tt=(tz * zinv); \ - s=(int) ss; \ - t=(int) tt; \ + s=(unsigned int) ss; \ + t=(unsigned int) tt; \ dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ fz+=fndzdx; \ @@ -319,8 +319,8 @@ void FNAME(ZB_fillTriangleMappingPerspective) (ZBuffer *zb, float ss,tt; \ ss=(sz * zinv); \ tt=(tz * zinv); \ - s=(int) ss; \ - t=(int) tt; \ + s=(unsigned int) ss; \ + t=(unsigned int) tt; \ dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ } \ @@ -394,7 +394,7 @@ void FNAME(ZB_fillTriangleMappingPerspectiveFlat) (ZBuffer *zb, #define DRAW_LINE() \ { \ - register unsigned short *pz; \ + register ZPOINT *pz; \ register PIXEL *pp; \ register unsigned int s,t,z,zz; \ register int n,dsdx,dtdx; \ @@ -417,8 +417,8 @@ void FNAME(ZB_fillTriangleMappingPerspectiveFlat) (ZBuffer *zb, float ss,tt; \ ss=(sz * zinv); \ tt=(tz * zinv); \ - s=(int) ss; \ - t=(int) tt; \ + s=(unsigned int) ss; \ + t=(unsigned int) tt; \ dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ fz+=fndzdx; \ @@ -442,8 +442,8 @@ void FNAME(ZB_fillTriangleMappingPerspectiveFlat) (ZBuffer *zb, float ss,tt; \ ss=(sz * zinv); \ tt=(tz * zinv); \ - s=(int) ss; \ - t=(int) tt; \ + s=(unsigned int) ss; \ + t=(unsigned int) tt; \ dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ } \ @@ -529,7 +529,7 @@ void FNAME(ZB_fillTriangleMappingPerspectiveSmooth) (ZBuffer *zb, #define DRAW_LINE() \ { \ - register unsigned short *pz; \ + register ZPOINT *pz; \ register PIXEL *pp; \ register unsigned int s,t,z,zz; \ register int n,dsdx,dtdx; \ @@ -552,8 +552,8 @@ void FNAME(ZB_fillTriangleMappingPerspectiveSmooth) (ZBuffer *zb, float ss,tt; \ ss=(sz * zinv); \ tt=(tz * zinv); \ - s=(int) ss; \ - t=(int) tt; \ + s=(unsigned int) ss; \ + t=(unsigned int) tt; \ dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ fz+=fndzdx; \ @@ -577,8 +577,8 @@ void FNAME(ZB_fillTriangleMappingPerspectiveSmooth) (ZBuffer *zb, float ss,tt; \ ss=(sz * zinv); \ tt=(tz * zinv); \ - s=(int) ss; \ - t=(int) tt; \ + s=(unsigned int) ss; \ + t=(unsigned int) tt; \ dsdx= (int)( (dszdx - ss*fdzdx)*zinv ); \ dtdx= (int)( (dtzdx - tt*fdzdx)*zinv ); \ } \