Mercurial > fife-parpg
changeset 430:ad1f09d954f9
Added the ability to render a vertex on the screen. The vertex is represented by a small square. fixes[t:455]
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 23 Feb 2010 19:25:59 +0000 |
parents | be291458d9b5 |
children | f44b149f63e7 |
files | engine/core/video/image.h engine/core/video/opengl/glimage.cpp engine/core/video/opengl/glimage.h engine/core/video/opengl/renderbackendopengl.cpp engine/core/video/opengl/renderbackendopengl.h engine/core/video/sdl/renderbackendsdl.cpp engine/core/video/sdl/renderbackendsdl.h engine/core/video/sdl/sdlimage.cpp engine/core/video/sdl/sdlimage.h engine/core/video/video.i engine/core/view/renderers/genericrenderer.cpp engine/core/view/renderers/genericrenderer.h engine/core/view/renderers/genericrenderer.i |
diffstat | 13 files changed, 193 insertions(+), 95 deletions(-) [+] |
line wrap: on
line diff
--- a/engine/core/video/image.h Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/video/image.h Tue Feb 23 19:25:59 2010 +0000 @@ -41,16 +41,16 @@ namespace FIFE { class Rect; - + class AbstractImage { public: virtual ~AbstractImage() {} - + /** Get the surface used by this image * @return pointer to used surface */ virtual SDL_Surface* getSurface() = 0; - + /** Returns the @b maximum width occupied by this image. * This should return the maximum width that could be covered by the * image. @@ -60,16 +60,16 @@ /** Returns the @b maximum height occupied by this image. */ virtual unsigned int getHeight() const = 0; - + /** Gets the area of the image * @return Image area in rect */ virtual const Rect& getArea() = 0; - + /** Writes pixel to given position. Returns true, if pixel was written (not out of bounds) */ virtual bool putPixel(int x, int y, int r, int g, int b) = 0; - + /** Draws line between given points with given RGBA */ virtual void drawLine(const Point& p1, const Point& p2, int r, int g, int b) = 0; @@ -77,7 +77,11 @@ /** Draws quad between given points with given RGBA */ virtual void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b) = 0; - + + /** Draws a quad that represents a vertex with given RGBA + */ + virtual void drawVertex(const Point& p, const uint8_t size, int r, int g, int b) = 0; + /** Returns pixel RGBA values from given position */ virtual void getPixelRGBA(int x, int y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a) = 0; @@ -97,23 +101,23 @@ * @see pushClipArea */ virtual const Rect& getClipArea() const = 0; - + /** Saves the image using given filename */ virtual void saveImage(const std::string& filename) = 0; - + /** Enable or disable the alpha 'optimizing' code * * @param optimize Wether the image shall be analysed for 'fake' alpha images. * Only implemented by and useful for the SDL backend at the moment. */ virtual void setAlphaOptimizerEnabled(bool enabled) = 0; - + /** @see setAlphaOptimizerEnabled */ virtual bool isAlphaOptimizerEnabled() = 0; }; - + /** Base Class for Images. */ class Image : public ResourceClass, public AbstractImage { @@ -145,12 +149,12 @@ * @param alpha The alpha value, with which to draw self. */ void render(const Rect& rect, unsigned char alpha = 255); - + /** Removes underlying SDL_Surface from the image (if exists) and returns this * @note this effectively causes SDL_Surface not to be freed on destruction */ SDL_Surface* detachSurface(); - + virtual ~Image(); SDL_Surface* getSurface() { return m_surface; } unsigned int getWidth() const; @@ -170,7 +174,7 @@ const Rect& getClipArea() const; void setAlphaOptimizerEnabled(bool enabled) { m_isalphaoptimized = enabled; } bool isAlphaOptimizerEnabled() { return m_isalphaoptimized; } - + protected: /** Sets given clip area into image * @see pushClipArea @@ -182,7 +186,7 @@ * @see pushClipArea */ virtual void clearClipArea(); - + // The SDL Surface used. SDL_Surface* m_surface; // The X shift of the Image @@ -196,11 +200,11 @@ bool clearing; }; std::stack<ClipInfo> m_clipstack; - + // image area Rect m_area; - bool m_isalphaoptimized; - + bool m_isalphaoptimized; + private: void reset(SDL_Surface* surface); };
--- a/engine/core/video/opengl/glimage.cpp Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/video/opengl/glimage.cpp Tue Feb 23 19:25:59 2010 +0000 @@ -64,7 +64,7 @@ m_chunk_size = RenderBackend::instance()->getChunkingSize(); m_colorkey = RenderBackend::instance()->getColorKey(); } - + void GLImage::cleanup() { for (unsigned int i = 0; i < m_rows*m_cols; ++i) { glDeleteTextures(1, &m_textureids[i]); @@ -94,14 +94,14 @@ // the amount of "zooming" for the image float scale_x = static_cast<float>(rect.w) / static_cast<float>(m_surface->w); float scale_y = static_cast<float>(rect.h) / static_cast<float>(m_surface->h); - + // rectangle used for drawing Rect target; - // zooming causes scaling sometimes to round pixels incorrectly. Instead of + // zooming causes scaling sometimes to round pixels incorrectly. Instead of // recalculating it all, store the values from previous round and calculate // new x & y Rect prev; - + /// setting transparency for the whole primitive: glColor4ub( 255, 255, 255, alpha ); @@ -119,7 +119,7 @@ } else { target.x = rect.x; } - + for (unsigned int j = 0; j < m_rows; ++j) { if (j == m_rows-1) { row_fill_ratio = m_last_row_fill_ratio; @@ -134,7 +134,7 @@ target.y = rect.y; } prev = target; - + glBindTexture(GL_TEXTURE_2D, m_textureids[j*m_cols + i]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); @@ -262,32 +262,32 @@ } } } - + void GLImage::saveImage(const std::string& filename) { const unsigned int swidth = getWidth(); const unsigned int sheight = getHeight(); Uint32 rmask, gmask, bmask, amask; SDL_Surface *surface = NULL; - uint8_t *pixels; - + uint8_t *pixels; + #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif - surface = SDL_CreateRGBSurface(SDL_SWSURFACE, swidth, - sheight, 24, + surface = SDL_CreateRGBSurface(SDL_SWSURFACE, swidth, + sheight, 24, rmask, gmask, bmask, 0); - + if(surface == NULL) { return; } - + SDL_LockSurface(surface); pixels = new uint8_t[swidth * sheight * 3]; glReadPixels(0, 0, swidth, sheight, GL_RGB, GL_UNSIGNED_BYTE, reinterpret_cast<GLvoid*>(pixels)); - + uint8_t *imagepixels = reinterpret_cast<uint8_t*>(surface->pixels); // Copy the "reversed_image" memory to the "image" memory for (int y = (sheight - 1); y >= 0; --y) { @@ -299,7 +299,7 @@ // Advance a row in the output surface. imagepixels += surface->pitch; } - + SDL_UnlockSurface(surface); saveAsPng(filename, *surface); SDL_FreeSurface(surface); @@ -314,19 +314,24 @@ glClear(GL_COLOR_BUFFER_BIT); } } - + bool GLImage::putPixel(int x, int y, int r, int g, int b) { cleanup(); return m_sdlimage->putPixel(x, y, r, g, b); } - + void GLImage::drawLine(const Point& p1, const Point& p2, int r, int g, int b) { cleanup(); m_sdlimage->drawLine(p1, p2, r, g, b); - } - + } + void GLImage::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b) { cleanup(); m_sdlimage->drawQuad(p1, p2, p3, p4, r, g, b); } + + void GLImage::drawVertex(const Point& p, const uint8_t size, int r, int g, int b) { + cleanup(); + m_sdlimage->drawVertex(p, size, r, g, b); + } }
--- a/engine/core/video/opengl/glimage.h Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/video/opengl/glimage.h Tue Feb 23 19:25:59 2010 +0000 @@ -65,6 +65,7 @@ bool putPixel(int x, int y, int r, int g, int b); void drawLine(const Point& p1, const Point& p2, int r, int g, int b); void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b); + void drawVertex(const Point& p, const uint8_t size, int r, int g, int b); protected: void setClipArea(const Rect& cliparea, bool clear); @@ -82,11 +83,11 @@ // @see m_last_col_fill_ratio float m_last_row_fill_ratio; - /** the width of last column to render. This is also power of two + /** the width of last column to render. This is also power of two * (e.g. if chunks are 256x256 and image width = 300, last column = 64 */ unsigned int m_last_col_width; - // see m_last_col_width + // see m_last_col_width unsigned int m_last_row_height; /** Holds texture ids that are used to access textures in GL rendering context @@ -96,18 +97,18 @@ /** Frees allocated memory and calls resetGlImage */ void cleanup(); - + /** Resets GLImage variables */ void resetGlimage(); - + //void saveAsPng(const std::string& filename, SDL_Surface& surface); /** Generates chunks for render. For reference, see * http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_4.html */ void generateTextureChunks(); - + /** Original SDLImage where GLImage is created from * FIXME: at the moment SDLImage is used to draw graphics (e.g. line) on screen * this is clearly not optimal, but image chunking makes somewhat harder to do @@ -116,7 +117,7 @@ * purpose */ SDLImage* m_sdlimage; - + unsigned int m_chunk_size; SDL_Color m_colorkey; };
--- a/engine/core/video/opengl/renderbackendopengl.cpp Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/video/opengl/renderbackendopengl.cpp Tue Feb 23 19:25:59 2010 +0000 @@ -200,7 +200,7 @@ } void RenderBackendOpenGL::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b) { - glColor4ub(r, g, b, 165); + glColor4ub(r, g, b, 165); glBegin(GL_QUADS); glVertex3f(p1.x, p1.y, 0); glVertex3f(p2.x, p2.y, 0); @@ -209,4 +209,23 @@ glEnd(); } + void RenderBackendOpenGL::drawVertex(const Point& p, const uint8_t size, int r, int g, int b){ + + GLfloat width; + + glGetFloatv(GL_LINE_WIDTH, &width); + glLineWidth(1.0); + + glBegin(GL_LINE_LOOP); + glColor4ub(r, g, b, 255); + + glVertex3f(p.x-size, p.y+size, 0); + glVertex3f(p.x+size, p.y+size, 0); + glVertex3f(p.x+size, p.y-size, 0); + glVertex3f(p.x-size, p.y-size, 0); + + glEnd(); + + glLineWidth(width); + } }
--- a/engine/core/video/opengl/renderbackendopengl.h Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/video/opengl/renderbackendopengl.h Tue Feb 23 19:25:59 2010 +0000 @@ -51,7 +51,8 @@ bool putPixel(int x, int y, int r, int g, int b); void drawLine(const Point& p1, const Point& p2, int r, int g, int b); void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b); - + void drawVertex(const Point& p, const uint8_t size, int r, int g, int b); + private: SDL_PixelFormat m_rgba_format; };
--- a/engine/core/video/sdl/renderbackendsdl.cpp Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/video/sdl/renderbackendsdl.cpp Tue Feb 23 19:25:59 2010 +0000 @@ -51,7 +51,7 @@ static std::string backend_name = "SDL"; return backend_name; } - + void RenderBackendSDL::init() { if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) throw SDLException(SDL_GetError()); @@ -124,7 +124,7 @@ void RenderBackendSDL::endFrame() { SDL_Flip(m_screen->getSurface()); - } + } Image* RenderBackendSDL::createImage(SDL_Surface* surface) { return new SDLImage(surface); @@ -133,16 +133,21 @@ Image* RenderBackendSDL::createImage(const uint8_t* data, unsigned int width, unsigned int height) { return new SDLImage(data, width, height); } - + bool RenderBackendSDL::putPixel(int x, int y, int r, int g, int b) { return static_cast<SDLImage*>(m_screen)->putPixel(x, y, r, g, b); } - + void RenderBackendSDL::drawLine(const Point& p1, const Point& p2, int r, int g, int b) { static_cast<SDLImage*>(m_screen)->drawLine(p1, p2, r, g, b); } - + void RenderBackendSDL::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b) { static_cast<SDLImage*>(m_screen)->drawQuad(p1, p2, p3, p4, r, g, b); } -} + + void RenderBackendSDL::drawVertex(const Point& p, const uint8_t size, int r, int g, int b){ + static_cast<SDLImage*>(m_screen)->drawVertex(p, 2, r, g, b); + } + +}//FIFE
--- a/engine/core/video/sdl/renderbackendsdl.h Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/video/sdl/renderbackendsdl.h Tue Feb 23 19:25:59 2010 +0000 @@ -53,6 +53,7 @@ bool putPixel(int x, int y, int r, int g, int b); void drawLine(const Point& p1, const Point& p2, int r, int g, int b); void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b); + void drawVertex(const Point& p, const uint8_t size, int r, int g, int b); }; }
--- a/engine/core/video/sdl/sdlimage.cpp Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/video/sdl/sdlimage.cpp Tue Feb 23 19:25:59 2010 +0000 @@ -40,7 +40,7 @@ namespace FIFE { static Logger _log(LM_VIDEO); - SDLImage::SDLImage(SDL_Surface* surface): + SDLImage::SDLImage(SDL_Surface* surface): Image(surface) { resetSdlimage(); } @@ -49,14 +49,14 @@ Image(data, width, height) { resetSdlimage(); } - + void SDLImage::resetSdlimage() { m_last_alpha = 255; m_finalized = false; m_isalphaoptimized = false; m_colorkey = RenderBackend::instance()->getColorKey(); } - + SDLImage::~SDLImage() { } @@ -128,7 +128,7 @@ unsigned char* srcData = reinterpret_cast< unsigned char* > ( src->pixels ); unsigned char* dstData = reinterpret_cast< unsigned char* > ( dst->pixels ); - + // move data pointers to the start of the pixels we're copying srcData += tY * src->pitch + tX * src->format->BytesPerPixel; dstData += screenY * dst->pitch + screenX * dst->format->BytesPerPixel; @@ -208,7 +208,7 @@ r.y = rect.y; r.w = rect.w; r.h = rect.h; - + if (m_surface->format->Amask == 0) { // Image has no alpha channel. This allows us to use the per-surface alpha. if (m_last_alpha != alpha) { @@ -281,7 +281,7 @@ int alphasquaresum = 0; bool colors[(1 << 12)]; memset(colors, 0, (1 << 12) * sizeof(bool)); - + int bpp = src->format->BytesPerPixel; if(SDL_MUSTLOCK(src)) { SDL_LockSurface(src); @@ -343,7 +343,7 @@ } alphasquaresum /= (opaque + semitransparent) ? (opaque + semitransparent) : 1; alphavariance = alphasquaresum - avgalpha*avgalpha; - if(semitransparent > ((transparent + opaque + semitransparent) / 8) + if(semitransparent > ((transparent + opaque + semitransparent) / 8) && alphavariance > 16) { FL_DBG(_log, LMsg("sdlimage") << "Trying to alpha-optimize image. FAILED: real alpha usage. " @@ -469,12 +469,12 @@ << "Trying to alpha-optimize image. SUCCESS: colorkey is " << key); return convert; } // end optimize - + bool SDLImage::putPixel(int x, int y, int r, int g, int b) { if ((x < 0) || (x >= m_surface->w) || (y < 0) || (y >= m_surface->h)) { return false; } - + int bpp = m_surface->format->BytesPerPixel; SDL_LockSurface(m_surface); Uint8* p = (Uint8*)m_surface->pixels + y * m_surface->pitch + x * bpp; @@ -484,11 +484,11 @@ case 1: *p = pixel; break; - + case 2: *(Uint16 *)p = pixel; break; - + case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; @@ -501,7 +501,7 @@ p[2] = (pixel >> 16) & 0xff; } break; - + case 4: *(Uint32 *)p = pixel; break; @@ -509,7 +509,7 @@ SDL_UnlockSurface(m_surface); return true; } - + void SDLImage::drawLine(const Point& p1, const Point& p2, int r, int g, int b) { // Draw a line with Bresenham, imitated from guichan int x1 = p1.x; @@ -518,24 +518,24 @@ int y2 = p2.y; int dx = ABS(x2 - x1); int dy = ABS(y2 - y1); - + if (dx > dy) { if (x1 > x2) { // swap x1, x2 x1 ^= x2; x2 ^= x1; x1 ^= x2; - + // swap y1, y2 y1 ^= y2; y2 ^= y1; y1 ^= y2; } - + if (y1 < y2) { int y = y1; int p = 0; - + for (int x = x1; x <= x2; x++) { putPixel(x, y, r, g, b); p += dy; @@ -548,10 +548,10 @@ else { int y = y1; int p = 0; - + for (int x = x1; x <= x2; x++) { putPixel(x, y, r, g, b); - + p += dy; if (p * 2 >= dx) { y--; @@ -566,17 +566,17 @@ y1 ^= y2; y2 ^= y1; y1 ^= y2; - + // swap x1, x2 x1 ^= x2; x2 ^= x1; x1 ^= x2; } - + if (x1 < x2) { int x = x1; int p = 0; - + for (int y = y1; y <= y2; y++) { putPixel(x, y, r, g, b); p += dx; @@ -589,7 +589,7 @@ else { int x = x1; int p = 0; - + for (int y = y1; y <= y2; y++) { putPixel(x, y, r, g, b); p += dx; @@ -600,8 +600,8 @@ } } } - } - + } + void SDLImage::drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b) { drawLine(p1, p2, r, g, b); drawLine(p2, p3, r, g, b); @@ -609,27 +609,39 @@ drawLine(p4, p1, r, g, b); } + void SDLImage::drawVertex(const Point& p, const uint8_t size, int r, int g, int b){ + Point p1 = Point(p.x-size, p.y+size); + Point p2 = Point(p.x+size, p.y+size); + Point p3 = Point(p.x+size, p.y-size); + Point p4 = Point(p.x-size, p.y-size); + + drawLine(p1, p2, r, g, b); + drawLine(p2, p3, r, g, b); + drawLine(p3, p4, r, g, b); + drawLine(p4, p1, r, g, b); + } + void SDLImage::saveImage(const std::string& filename) { if(m_surface) { const unsigned int swidth = getWidth(); const unsigned int sheight = getHeight(); Uint32 rmask, gmask, bmask, amask; SDL_Surface *surface = NULL; - + #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif - surface = SDL_CreateRGBSurface(SDL_SWSURFACE, swidth, - sheight, 24, + surface = SDL_CreateRGBSurface(SDL_SWSURFACE, swidth, + sheight, 24, rmask, gmask, bmask, 0); if(surface == NULL) { return; } - + SDL_BlitSurface(m_surface, NULL, surface, NULL); saveAsPng(filename, *surface); @@ -647,5 +659,5 @@ if (clear) { SDL_FillRect(m_surface, &rect, 0x00); } - } + } }
--- a/engine/core/video/sdl/sdlimage.h Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/video/sdl/sdlimage.h Tue Feb 23 19:25:59 2010 +0000 @@ -47,6 +47,7 @@ bool putPixel(int x, int y, int r, int g, int b); void drawLine(const Point& p1, const Point& p2, int r, int g, int b); void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b); + void drawVertex(const Point& p, const uint8_t size, int r, int g, int b); protected: void setClipArea(const Rect& cliparea, bool clear);
--- a/engine/core/video/video.i Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/video/video.i Tue Feb 23 19:25:59 2010 +0000 @@ -155,6 +155,7 @@ bool putPixel(int x, int y, int r, int g, int b); void drawLine(const Point& p1, const Point& p2, int r, int g, int b); void drawQuad(const Point& p1, const Point& p2, const Point& p3, const Point& p4, int r, int g, int b); + void drawVertex(const Point& p, int size, int r, int g, int b); void pushClipArea(const Rect& cliparea, bool clear=true); void popClipArea(); const Rect& getClipArea() const;
--- a/engine/core/view/renderers/genericrenderer.cpp Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/view/renderers/genericrenderer.cpp Tue Feb 23 19:25:59 2010 +0000 @@ -196,7 +196,7 @@ Point p2 = m_edge2.getCalculatedPoint(cam, layer, instances); renderbackend->drawLine(p1, p2, m_red, m_green, m_blue); } - + GenericRendererPointInfo::GenericRendererPointInfo(GenericRendererNode anchor, uint8_t r, uint8_t g, uint8_t b): GenericRendererElementInfo(), m_anchor(anchor), @@ -208,7 +208,7 @@ Point p = m_anchor.getCalculatedPoint(cam, layer, instances); renderbackend->putPixel(p.x, p.y, m_red, m_green, m_blue); } - + GenericRendererQuadInfo::GenericRendererQuadInfo(GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b): GenericRendererElementInfo(), m_edge1(n1), @@ -226,7 +226,20 @@ Point p4 = m_edge4.getCalculatedPoint(cam, layer, instances); renderbackend->drawQuad(p1, p2, p3, p4, m_red, m_green, m_blue); } - + + GenericRendererVertexInfo::GenericRendererVertexInfo(GenericRendererNode center, int size, uint8_t r, uint8_t g, uint8_t b): + GenericRendererElementInfo(), + m_center(center), + m_size(size), + m_red(r), + m_green(g), + m_blue(b) { + } + void GenericRendererVertexInfo::render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool) { + Point p = m_center.getCalculatedPoint(cam, layer, instances); + renderbackend->drawVertex(p, m_size, m_red, m_green, m_blue); + } + GenericRendererImageInfo::GenericRendererImageInfo(GenericRendererNode anchor, int image): GenericRendererElementInfo(), m_anchor(anchor), @@ -242,7 +255,7 @@ r.h = img->getHeight(); img->render(r); } - + GenericRendererAnimationInfo::GenericRendererAnimationInfo(GenericRendererNode anchor, int animation): GenericRendererElementInfo(), m_anchor(anchor), @@ -262,7 +275,7 @@ r.h = img->getHeight(); img->render(r); } - + GenericRendererTextInfo::GenericRendererTextInfo(GenericRendererNode anchor, AbstractFont* font, std::string text): GenericRendererElementInfo(), m_anchor(anchor), @@ -279,11 +292,11 @@ r.h = img->getHeight(); img->render(r); } - + GenericRenderer* GenericRenderer::getInstance(IRendererContainer* cnt) { return dynamic_cast<GenericRenderer*>(cnt->getRenderer("GenericRenderer")); } - + GenericRenderer::GenericRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool): RendererBase(renderbackend, position), m_imagepool(imagepool), @@ -318,6 +331,10 @@ GenericRendererElementInfo* info = new GenericRendererQuadInfo(n1, n2, n3, n4, r, g, b); m_groups[group].push_back(info); } + void GenericRenderer::addVertex(const std::string &group, GenericRendererNode n, int size, uint8_t r, uint8_t g, uint8_t b) { + GenericRendererElementInfo* info = new GenericRendererVertexInfo(n, size, r, g, b); + m_groups[group].push_back(info); + } void GenericRenderer::addText(const std::string &group, GenericRendererNode n, AbstractFont* font, const std::string &text) { GenericRendererElementInfo* info = new GenericRendererTextInfo(n, font, text); m_groups[group].push_back(info); @@ -330,6 +347,7 @@ GenericRendererElementInfo* info = new GenericRendererAnimationInfo(n, animation); m_groups[group].push_back(info); } + void GenericRenderer::removeAll(const std::string &group) { std::vector<GenericRendererElementInfo*>::const_iterator info_it = m_groups[group].begin(); for (;info_it != m_groups[group].end(); ++info_it) {
--- a/engine/core/view/renderers/genericrenderer.h Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/view/renderers/genericrenderer.h Tue Feb 23 19:25:59 2010 +0000 @@ -45,7 +45,7 @@ GenericRendererNode(Location* attached_location, const Point &relative_point = Point(0,0)); GenericRendererNode(const Point &attached_point); ~GenericRendererNode(); - + void setAttached(Instance* attached_instance, Location* relative_location, const Point &relative_point); void setAttached(Instance* attached_instance, Location* relative_location); void setAttached(Instance* attached_instance, const Point &relative_point); @@ -53,18 +53,18 @@ void setAttached(Location* attached_location, const Point &relative_point); void setAttached(Location* attached_location); void setAttached(const Point &attached_point); - + void setRelative(Location* relative_location); void setRelative(Location* relative_location, Point relative_point); void setRelative(const Point &relative_point); - + Instance* getAttachedInstance(); Location* getAttachedLocation(); Point getAttachedPoint(); - + Location* getOffsetLocation(); Point getOffsetPoint(); - + Instance* getInstance(); Location* getLocation(); Point getPoint(); @@ -118,6 +118,20 @@ uint8_t m_green; uint8_t m_blue; }; + + class GenericRendererVertexInfo : public GenericRendererElementInfo { + public: + void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); + GenericRendererVertexInfo(GenericRendererNode center, int size, uint8_t r, uint8_t g, uint8_t b); + virtual ~GenericRendererVertexInfo() {}; + private: + GenericRendererNode m_center; + int m_size; + uint8_t m_red; + uint8_t m_green; + uint8_t m_blue; + }; + class GenericRendererImageInfo : public GenericRendererElementInfo { public: void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); @@ -155,9 +169,9 @@ * @param position position for this renderer in rendering pipeline */ GenericRenderer(RenderBackend* renderbackend, int position, ImagePool* imagepool, AnimationPool* animpool); - + GenericRenderer(const GenericRenderer& old); - + RendererBase* clone(); /** Destructor. @@ -173,6 +187,7 @@ void addLine(const std::string &group, GenericRendererNode n1, GenericRendererNode n2, uint8_t r, uint8_t g, uint8_t b); void addPoint(const std::string &group, GenericRendererNode n, uint8_t r, uint8_t g, uint8_t b); void addQuad(const std::string &group, GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b); + void addVertex(const std::string &group, GenericRendererNode n, int size, uint8_t r, uint8_t g, uint8_t b); void addText(const std::string &group, GenericRendererNode n, AbstractFont* font, const std::string &text); void addImage(const std::string &group, GenericRendererNode n, int image); void addAnimation(const std::string &group, GenericRendererNode n, int animation);
--- a/engine/core/view/renderers/genericrenderer.i Tue Feb 23 17:36:21 2010 +0000 +++ b/engine/core/view/renderers/genericrenderer.i Tue Feb 23 19:25:59 2010 +0000 @@ -107,6 +107,20 @@ uint8_t m_green; uint8_t m_blue; }; + + class GenericRendererVertexInfo : public GenericRendererElementInfo { + public: + void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); + GenericRendererVertexInfo(GenericRendererNode center, int size, uint8_t r, uint8_t g, uint8_t b); + virtual ~GenericRendererVertexInfo() {}; + private: + GenericRendererNode m_center; + int m_size; + uint8_t m_red; + uint8_t m_green; + uint8_t m_blue; + }; + class GenericRendererImageInfo : public GenericRendererElementInfo { public: void render(Camera* cam, Layer* layer, std::vector<Instance*>& instances, RenderBackend* renderbackend, ImagePool* imagepool, AnimationPool* animpool); @@ -144,6 +158,7 @@ void addLine(const std::string &group, GenericRendererNode n1, GenericRendererNode n2, uint8_t r, uint8_t g, uint8_t b); void addPoint(const std::string &group, GenericRendererNode n, uint8_t r, uint8_t g, uint8_t b); void addQuad(const std::string &group, GenericRendererNode n1, GenericRendererNode n2, GenericRendererNode n3, GenericRendererNode n4, uint8_t r, uint8_t g, uint8_t b); + void addVertex(const std::string &group, GenericRendererNode n, int size, uint8_t r, uint8_t g, uint8_t b); void addText(const std::string &group, GenericRendererNode n, AbstractFont* font, const std::string &text); void addImage(const std::string &group, GenericRendererNode n, int image); void addAnimation(const std::string &group, GenericRendererNode n, int animation);