[mapserver-commits] r8546 - sandbox/graphics

svn at osgeo.org svn at osgeo.org
Thu Feb 12 22:57:09 EST 2009


Author: toby
Date: 2009-02-12 22:57:09 -0500 (Thu, 12 Feb 2009)
New Revision: 8546

Modified:
   sandbox/graphics/mapogl.cpp
   sandbox/graphics/mapoglrenderer.cpp
   sandbox/graphics/mapoglrenderer.h
   sandbox/graphics/mapoutput.c
   sandbox/graphics/maprendering.c
   sandbox/graphics/mapserver.h
Log:
Completed opengl pixmap rendering. Added createTilePixmap to the 
rendering vtable.


Modified: sandbox/graphics/mapogl.cpp
===================================================================
--- sandbox/graphics/mapogl.cpp	2009-02-13 00:37:18 UTC (rev 8545)
+++ sandbox/graphics/mapogl.cpp	2009-02-13 03:57:09 UTC (rev 8546)
@@ -75,6 +75,17 @@
 	renderer->renderVectorSymbol(x, y, symbol, scale, angle, c, oc, ow);
 }
 
+void* msCreateTilePixmapOgl(symbolObj *symbol, double scale, double angle, colorObj *bc)
+{
+	double canvasWidth = symbol->sizex*scale;
+	double canvasHeight = symbol->sizey*scale;
+	OglTexture* renderer = new OglTexture(canvasWidth, canvasHeight, bc);
+	renderer->renderPixmap(symbol, 0, 0, angle, scale);
+	ogl_cache* tile = renderer->renderToTile();
+	delete renderer;
+	return tile;
+}
+
 void *msCreateTileEllipseOgl(double width, double height, double angle,
 		colorObj *c, colorObj *bc, colorObj *oc, double ow)
 {

Modified: sandbox/graphics/mapoglrenderer.cpp
===================================================================
--- sandbox/graphics/mapoglrenderer.cpp	2009-02-13 00:37:18 UTC (rev 8545)
+++ sandbox/graphics/mapoglrenderer.cpp	2009-02-13 03:57:09 UTC (rev 8546)
@@ -72,16 +72,18 @@
 //
 //	glClear(GL_COLOR_BUFFER_BIT);
 	glPushMatrix();
+	glRasterPos2d(TEXTURE_BORDER/2, TEXTURE_BORDER/2);
+	glPixelZoom((float)pow2width/width, (float)pow2height/height);
 
-
 	glTranslated(TEXTURE_BORDER/2, TEXTURE_BORDER/2, 0);
 	glScaled((double)pow2width/width, (double)pow2height/height, 1.0);
 }
 
 OglTexture::~OglTexture()
 {
-	//glEnable(GL_MULTISAMPLE_ARB);
 	glPopMatrix();
+	glPixelZoom(1.0f, 1.0f);
+	glRasterPos2d(0, 0);
 }
 
 ogl_cache* OglTexture::renderToTile()
@@ -93,8 +95,6 @@
 
 	tile->width = width;
 	tile->height = height;
-	tile->texWidth = pow2width;
-	tile->texHeight = pow2height;
 	return tile;
 }
 
@@ -220,26 +220,25 @@
 	glReadPixels(0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
 }
 
-void OglRenderer::gd2ogl(int** gdBuffer, int sx, int sy, GLubyte* imgPixels)
+GLubyte* OglRenderer::gd2ogl(gdImagePtr img)
 {
+	int sx = gdImageSX(img);
+	int sy = gdImageSY(img);
+	GLubyte* imgPixels = new GLubyte[sx*sy*4];
 	GLubyte* rowptr = imgPixels;
-	int stride = ((sx * 1 + 3) >> 2) << 2;
-
-	for (int i = sy - 1; i >= 0; i--)
+	for (int i = 0; i < sy; ++i)
 	{
-		for (int j = 0; j < stride; j++)
+		for (int j = 0; j < sx; ++j)
 		{
-			// We need to flip the color bytes and invert the alpha
-			rowptr[j * 4 + 3] = (127 - ((unsigned char*) &gdBuffer[i][j])[3])
-					* 2;//55/127; // alpha
-
-			rowptr[j * 4 + 0] = ((unsigned char*) &gdBuffer[i][j])[2]; // blue -> red
-			rowptr[j * 4 + 1] = ((unsigned char*) &gdBuffer[i][j])[1]; // green -> green
-			rowptr[j * 4 + 2] = ((unsigned char*) &gdBuffer[i][j])[0]; // red -> blue
-
+			uint32_t pixel = gdImageGetTrueColorPixel(img, j, i);
+			rowptr[j * 4 + 0] = gdTrueColorGetRed(pixel);
+			rowptr[j * 4 + 1] = gdTrueColorGetGreen(pixel);
+			rowptr[j * 4 + 2] = gdTrueColorGetBlue(pixel);
+			rowptr[j * 4 + 3] = (127 - gdTrueColorGetAlpha(pixel)) * 2;
 		}
-		rowptr += 4 * stride;
+		rowptr += 4 * sx;
 	}
+	return imgPixels;
 }
 
 void OglRenderer::setTransparency(double transparency)
@@ -368,9 +367,6 @@
 
 void OglRenderer::renderPolylineTile(shapeObj *shape, double width, ogl_cache* tile)
 {
-	static bool done = false;
-	//if (done) return;
-	done = true;
 	context->makeCurrent();
 	glBindTexture(GL_TEXTURE_2D, tile->texture); // Select Our Texture
 	glBegin(GL_TRIANGLE_STRIP);
@@ -382,10 +378,7 @@
 		{
 			double dist = drawTriangles(&shape->line[i].point[j], &shape->line[i].point[j + 1], width, tile->width, place / tile->width);
 			place = (place + dist);
-			while (place >= tile->width)
-			{
-				place -= tile->width; // better than mod, no rounding
-			}
+			while (place >= tile->width) place -= tile->width;
 		}
 	}
 	glEnd();
@@ -625,29 +618,17 @@
 		double angle, double scale)
 {
 	context->makeCurrent();
-	ogl_cache* cache = (ogl_cache*) symbol->renderer_cache;
-	glBindTexture(GL_TEXTURE_2D, cache->texture); // Select Our Texture
-	glPushMatrix();
-	glTranslated(x, y, 0);
-	if (angle)
-		glRotated(angle, 0, 0, 1);
-	if (scale)
-		glScaled(scale, scale, 0);
-	glTranslated(-x, -y, 0);
-	glBegin(GL_QUADS);
-	glTexCoord2d(0, 1);
-	glVertex2d(x - (symbol->sizex / 2), y - (symbol->sizey / 2)); // Bottom Left Of The Texture and Quad
-	glTexCoord2d(1, 1);
-	glVertex2d(x + (symbol->sizex / 2), y - (symbol->sizey / 2)); // Bottom Right Of The Texture and Quad
-	glTexCoord2d(1, 0);
-	glVertex2d(x + (symbol->sizex / 2), y + (symbol->sizey / 2)); // Top Right Of The Texture and Quad
-	glTexCoord2d(0, 0);
-	glVertex2d(x - (symbol->sizex / 2), y + (symbol->sizey / 2)); // Top Left Of The Texture and Quad
-	glEnd();
 
-	glPopMatrix();
-	glBindTexture(GL_TEXTURE_2D, 0);
+	float zoomX, zoomY;
+	glGetFloatv(GL_ZOOM_X, &zoomX);
+	glGetFloatv(GL_ZOOM_Y, &zoomY);
 
+	GLubyte* imgdata = gd2ogl(symbol->img);
+	glPixelZoom(zoomX*scale, zoomY*scale);
+	glRasterPos2d(x, y);
+	glDrawPixels(symbol->img->sx, symbol->img->sy, GL_RGBA, GL_UNSIGNED_BYTE, imgdata);
+	glPixelZoom(zoomX, zoomY);
+	delete imgdata;
 }
 
 void OglRenderer::renderEllipse(double x, double y, double angle, double width, double height,
@@ -669,7 +650,7 @@
 		glRotated(angle, 0, 0, 1);
 	}
 	glTranslated(x, y, 0);
-	glScaled(width / SHAPE_CIRCLE_RADIUS / 2, height / SHAPE_CIRCLE_RADIUS / 2, 0);
+	glScaled(width / SHAPE_CIRCLE_RADIUS / 2, height / SHAPE_CIRCLE_RADIUS / 2, 1);
 	glCallList(shapes[circle]);
 	glPopMatrix();
 

Modified: sandbox/graphics/mapoglrenderer.h
===================================================================
--- sandbox/graphics/mapoglrenderer.h	2009-02-13 00:37:18 UTC (rev 8545)
+++ sandbox/graphics/mapoglrenderer.h	2009-02-13 03:57:09 UTC (rev 8546)
@@ -17,8 +17,6 @@
 	uint texture;
 	uint width;
 	uint height;
-	uint texWidth;
-	uint texHeight;
 	uint patternDistance;
 } ogl_cache;
 
@@ -27,7 +25,7 @@
 	OglRenderer(uint width, uint height, colorObj* color = NULL);
 	OglRenderer() {}
 	~OglRenderer();
-    static void gd2ogl(int** gdBuffer, int sx, int sy, GLubyte* imgPixels);
+    GLubyte* gd2ogl(gdImagePtr img);
 
 	void renderPolyline(shapeObj *p,colorObj *c, double width, int patternlength, int* pattern, int lineCap = MS_CJC_ROUND, int joinStyle = MS_CJC_ROUND, colorObj *outlinecolor = NULL, double outlinewidth = 0);
 	void renderPolygon(shapeObj*, colorObj *color, colorObj *outlinecolor, double outlinewidth, int lineCap=MS_CJC_ROUND, int joinStyle=MS_CJC_ROUND);

Modified: sandbox/graphics/mapoutput.c
===================================================================
--- sandbox/graphics/mapoutput.c	2009-02-13 00:37:18 UTC (rev 8545)
+++ sandbox/graphics/mapoutput.c	2009-02-13 03:57:09 UTC (rev 8546)
@@ -1016,12 +1016,12 @@
         r->transformShape=&msTransformShapeAGG;
         r->renderPolygon=&msDrawPolygonOgl;
         r->renderGlyphs=&msRenderGlyphsOgl;
-        r->freeImage=&msFreeImageOgl;
         r->renderEllipse = &msRenderEllipseOgl;
         r->renderVectorSymbol = &msRenderVectorSymbolOgl;
         r->renderPixmap = &msRenderPixmapOgl;
         r->mergeImages = &msMergeImagesOgl;
         r->getTruetypeTextBBox = &msGetTruetypeTextBBoxOgl;
+        r->createTilePixmap = &msCreateTilePixmapOgl;
         r->createTileVector = &msCreateTileVectorOgl;
         r->createTileEllipse = &msCreateTileEllipseOgl;
         r->createTileTruetype = &msCreateTileTruetypeOgl;
@@ -1030,6 +1030,7 @@
         r->renderLineTiled = &msDrawLineTiledOgl;
         r->freeTile = &msFreeTileOgl;
         r->freeSymbol = &msFreeSymbolOgl;
+        r->freeImage=&msFreeImageOgl;
         return r;
 #endif
 

Modified: sandbox/graphics/maprendering.c
===================================================================
--- sandbox/graphics/maprendering.c	2009-02-13 00:37:18 UTC (rev 8545)
+++ sandbox/graphics/maprendering.c	2009-02-13 03:57:09 UTC (rev 8546)
@@ -27,19 +27,18 @@
 		bc->alpha = MS_NINT(style->opacity * 2.55);
 		switch(symbol->type) {
 		case MS_SYMBOL_VECTOR:
-			tile = r->createTileVector(symbol, scale, angle,
-									c,bc,oc, width);
+			tile = r->createTileVector(symbol, scale, angle, c,bc,oc, width);
 			break;
 		case MS_SYMBOL_ELLIPSE:
-			tile = r->createTileEllipse(scale * symbol->sizex,
-					scale * symbol->sizey, angle, c, bc, oc, width);
-
+			tile = r->createTileEllipse(scale * symbol->sizex, scale * width, angle, c, bc, oc, scale * style->outlinewidth);
 			break;
 		case MS_SYMBOL_TRUETYPE: {
-			char* font = msLookupHashTable(&(symbolset->fontset->fonts),
-									symbol->font);
+			char* font = msLookupHashTable(&(symbolset->fontset->fonts), symbol->font);
 			tile = r->createTileTruetype(img,symbol->character,font,scale,angle,c,bc,oc,width);
 		}
+		case MS_SYMBOL_PIXMAP: {
+			tile = r->createTilePixmap(symbol, scale, angle, bc);
+		}
 		break;
 		}
 		symbolset->imagecache = addImageCache(symbolset->imagecache,
@@ -294,10 +293,10 @@
 			if(style->offsety==-99) {
 				theShape = msOffsetPolyline(p,ox,-99);
 			}
-			if(style->symbol == 0 || (symbol->type==MS_SYMBOL_SIMPLE)) {
+			if(style->symbol == 0 || (symbol->type==MS_SYMBOL_SIMPLE)  || (symbol->type==MS_SYMBOL_ELLIPSE)) {
 				r->renderLine(image, theShape, &c, width, symbol->patternlength,symbol->pattern);
 			}
-			else if ((symbol->type==MS_SYMBOL_VECTOR) || (symbol->type==MS_SYMBOL_ELLIPSE) || (symbol->type==MS_SYMBOL_TRUETYPE))
+			else if ((symbol->type==MS_SYMBOL_VECTOR) || (symbol->type==MS_SYMBOL_TRUETYPE))
 			{
 				void* tile = getTile(image, symbolset, style, size/symbol->sizey, width, 0);
 				r->renderLineTiled(image, theShape, size, tile);

Modified: sandbox/graphics/mapserver.h
===================================================================
--- sandbox/graphics/mapserver.h	2009-02-13 00:37:18 UTC (rev 8545)
+++ sandbox/graphics/mapserver.h	2009-02-13 03:57:09 UTC (rev 8546)
@@ -2376,6 +2376,8 @@
 			colorObj *outlinecolor,
 	double outlinewidth);
 
+void* msCreateTilePixmapOgl(symbolObj *symbol, double scale, double angle, colorObj *bc);
+
 void* msCreateTileTruetypeOgl(imageObj *img, char *text, char *font,
 	double size, double angle, colorObj *c, colorObj *bc, colorObj *oc,
 	double ow);
@@ -2497,6 +2499,8 @@
     		colorObj *outlinecolor,
 			double outlinewidth);
 
+    void* (*createTilePixmap)(symbolObj *symbol, double scale, double angle, colorObj *bc);
+
 	void* (*createTileEllipse)(double width, double height, double angle,
 			colorObj *color,
 			colorObj *backgroundcolor,



More information about the mapserver-commits mailing list