[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17671] branches/soc-2008-mxcurioni/source /blender: The GL-based renderer was removed.

Maxime Curioni maxime.curioni at gmail.com
Mon Dec 1 22:30:45 CET 2008


Revision: 17671
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17671
Author:   mxcurioni
Date:     2008-12-01 22:30:44 +0100 (Mon, 01 Dec 2008)

Log Message:
-----------
The GL-based renderer was removed. Freestyle now uses Blender's internal renderer to raster strokes.

The render generated from Freestyle's data is currently stored in the original scene's render structure ( as 'freestyle_render'): when the render database is generated, the scene's geometrical data is first imported into Freestyle and strokes are calculated. The generated strokes are used to create a Blender scene, rendered independently. The render result is used in the rendering loop.

The final rendering is performed the same way edge rendering is, in a function ('freestyle_enhance_add') operating on each individual render part. Freestyle strokes are only included if the toggle button "Freestyle" (in the 'Output' panel) is active and if the "Freestyle" render layer is also selected. Freestyle's panel appears when the toggle button 'Freestyle' is active.

IMPORTANT: as of now, rendering ONLY works when OSA is disabled and when Xparts = Yparts = 1. If these settings are not set, a bogus image will be created.

To make the render happen, many modifications had to be made:
- the Canvas::Draw and Operators::create methods no longer render strokes. They only generate shading and locational information. 
- a BlenderStrokeRenderer class was added to turn Freestyle's strokes into a Blender scene. Basically, the scene consists of strokes in their projected image 2D coordinates and an orthographic camera centered in the middle of the corresponding canvas. The scene is rendered using vertex colors, in shadeless mode (therefore, no lamp is needed). BlenderStrokeRenderer uses the old GLTextureManager to load textures (as required by the StrokeRenderer class), even though stroke textures are probably not supported (not tested). After the scene is rendered, it is safely and automatically discarded.
- AppCanvas' code was greatly reduced to the bare minimum. The former AppCanvas would use an OpenGL-based back buffer and z buffer to determine the scene's color and depth information. In the future, this data will be determined from the corresponding render passes. Currently, the integration is not achieved so all style modules using depth/color information are sure to fail.
- before, Freestyle needed an OpenGL context to determine the camera's information and to compute the view map. As of now, the modelview and projection matrices are fully determined using data provided by Blender. This means both perspective and orthographic projections are supported. The AppGLWidget will very soon be removed completely.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppCanvas.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppCanvas.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppGLWidget.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppGLWidget.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/rendering/GLStrokeRenderer.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Canvas.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Operators.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/system/PythonInterpreter.h
    branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2008-mxcurioni/source/blender/python/api2_2x/sceneRender.c
    branches/soc-2008-mxcurioni/source/blender/render/intern/include/render_types.h
    branches/soc-2008-mxcurioni/source/blender/render/intern/source/convertblender.c
    branches/soc-2008-mxcurioni/source/blender/render/intern/source/pipeline.c
    branches/soc-2008-mxcurioni/source/blender/render/intern/source/rendercore.c
    branches/soc-2008-mxcurioni/source/blender/src/buttons_scene.c

Added Paths:
-----------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/BlenderStrokeRenderer.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/BlenderStrokeRenderer.h

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h	2008-12-01 21:23:58 UTC (rev 17670)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h	2008-12-01 21:30:44 UTC (rev 17671)
@@ -13,9 +13,14 @@
 	extern float freestyle_sphere_radius;
 	extern float freestyle_dkr_epsilon;
 	
+	extern float freestyle_viewpoint[3];
+	extern float freestyle_mv[4][4];
+	extern float freestyle_proj[4][4];
+	extern int freestyle_viewport[4];
+	
 	void FRS_initialize();
 	void FRS_prepare(Render* re);
-	void FRS_render_GL(Render* re);
+	void FRS_render_Blender(Render* re);
 
 #ifdef __cplusplus
 }

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppCanvas.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppCanvas.cpp	2008-12-01 21:23:58 UTC (rev 17670)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppCanvas.cpp	2008-12-01 21:30:44 UTC (rev 17671)
@@ -80,283 +80,59 @@
 void AppCanvas::preDraw()
 {
   Canvas::preDraw();
-
-  _pViewer->prepareCanvas();
-  glClearColor(0,0,0,0);
-	glClear(GL_COLOR_BUFFER_BIT);
-	glDisable(GL_LIGHTING);
-	glPolygonMode(GL_FRONT, GL_FILL);
-	glShadeModel(GL_SMOOTH);
-	glDisable(GL_DEPTH_TEST);
-	glEnable(GL_TEXTURE_2D);
-  glEnable(GL_BLEND);
 }
 
 void AppCanvas::init() 
 {
 
-  static bool firsttime = true;
-  if (firsttime) {
-
-	GLenum err = glewInit();
-	if (GLEW_OK != err)
-	{
-		cerr << "Error: problem occurred while initializing GLEW" << endl;	
-	}
-	cout << "GLEW initialized: ";
-
-	if(glBlendEquation) {
-		cout << "using glBlendEquation" << endl;
-	} else if(glBlendEquationEXT) {
-		cout << "using glBlendEquationEXT" << endl;
-	} else {
-        _basic = true;
-        cout << "glBlendEquation or glBlendEquationEXT unavailable on this hardware -> switching to strokes basic rendering mode" << endl;
-     }
-    firsttime=false;
-   }
-
-  _Renderer = new GLStrokeRenderer;
-  if(!StrokeRenderer::loadTextures())
-    {
-      cerr << "unable to load stroke textures" << endl;
-      return;
-    }
+	//   static bool firsttime = true;
+	//   if (firsttime) {
+	// 
+	//   _Renderer = new BlenderStrokeRenderer;
+	//   if(!StrokeRenderer::loadTextures())
+	//     {
+	//       cerr << "unable to load stroke textures" << endl;
+	//       return;
+	//     }
+	// 	}
 }
 
 void AppCanvas::postDraw()
 {
-  //inverse frame buffer
-  glDisable(GL_TEXTURE_2D);
-  glDisable(GL_BLEND);
-  _pViewer->releaseCanvas();
-
-  Canvas::postDraw();
+	Canvas::postDraw();
 }
 
 void AppCanvas::Erase()
 {
   Canvas::Erase();
-  //_pViewer->clear();
 }
 
+// Abstract
+
 #include "../image/GaussianFilter.h"
 void AppCanvas::readColorPixels(int x,int y,int w, int h, RGBImage& oImage) const
 {
   //static unsigned number = 0;
   float *rgb = new float[3*w*h];
-  _pViewer->readPixels(x,y,w,h,AppGLWidget::RGB,rgb);
+  //_pViewer->readPixels(x,y,w,h,AppGLWidget::RGB,rgb);
   oImage.setArray(rgb, width(), height(), w,h, x, y, false);
-  // FIXME
-  //  QImage qtmp(w, h, 32);
-  //  for(unsigned py=0;py<h;++py){
-  //    for(unsigned px=0;px<w;++px){
-  //      int r = (int)255*(oImage.getR(x+px,y+py));
-  //      int g = (int)255*(oImage.getG(x+px,y+py));
-  //      int b = (int)255*(oImage.getB(x+px,y+py));
-  //      qtmp.setPixel(px,py,qRgb(r,g,b));
-  //    }
-  //  }
-  //  qtmp.save("densityQuery"+QString::number(number)+".png", "PNG");
-  //  if(number == 1090){
-  //    RGBImage img;
-  //    float *rgbtmp = new float[3*width()*height()];
-  //    _pViewer->readPixels(0,0,width(),height(),AppGLWidget::RGB,rgbtmp);
-  //    img.setArray(rgbtmp, width(), height(), width(), height(), 0, 0, false);
-  //    QImage qtmp(width(), height(), 32);
-  //    for(unsigned py=0;py<height();++py){
-  //      for(unsigned px=0;px<width();++px){
-  //        int r = (int)255*(img.getR(px,py));
-  //        int g = (int)255*(img.getG(px,py));
-  //        int b = (int)255*(img.getB(px,py));
-  //        qtmp.setPixel(px,height()-1-py,qRgb(r,g,b));
-  //      }
-  //    }
-  //    qtmp.save("densityQuery"+QString::number(number)+".png", "PNG");
-  //    
-  //    GaussianFilter filter;
-  //    filter.setSigma(4.0);
-  //    int bound = filter.getBound();
-  //    QImage qtmp2(width(), height(), 32);
-  //    for(int py2=0;py2<height();++py2){
-  //      for(int px2=0;px2<width();++px2){  
-  //        if( (px2-bound < 0) || (px2+bound>width())
-  //	      || (py2-bound < 0) || (py2+bound>height()))
-  //          continue;
-  //        int g = 255*filter.getSmoothedPixel<RGBImage>(&img, px2,py2);
-  //        qtmp2.setPixel(px2,height()-1-py2,qRgb(g,g,g));
-  //      }
-  //    }
-  //    qtmp2.save("blurredCausalDensity"+QString::number(number)+".png", "PNG");
-  //  }
-  //  cout << number << endl;
-  //  ++number;
 }
 
 void AppCanvas::readDepthPixels(int x,int y,int w, int h, GrayImage& oImage) const
 {
   float *rgb = new float[w*h];
-  _pViewer->readPixels(x,y,w,h,AppGLWidget::DEPTH,rgb);
+  //_pViewer->readPixels(x,y,w,h,AppGLWidget::DEPTH,rgb);
   oImage.setArray(rgb, width(), height(), w,h, x, y, false);
 }
 
-void AppCanvas::update()
-{
-//  static int counter = 0;
-//  char fileName[100] = "framebuffer";
-//  char number[10];
-//
-  _pViewer->updateGL();
-  //_pViewer->swapBuffers();
-  //QImage fb = _pViewer->grabFrameBuffer();
-  //  sprintf(number, "%3d", counter);
-  //  strcat(fileName, number);
-  //  strcat(fileName, ".bmp");
-  //  fb.save(fileName, "BMP");
-  //counter++;
-}
-
-void AppCanvas::Render(const StrokeRenderer *iRenderer)
-{
-  if(_basic){
-    RenderBasic(iRenderer);
-    return;
-  }
-
-  glClearColor(1,1,1,1);
-  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-  glDisable(GL_LIGHTING);
-  glPolygonMode(GL_FRONT, GL_FILL);
-  glShadeModel(GL_SMOOTH);
-  
-  if(_pViewer->draw3DsceneEnabled())
-  {
-    glClearColor(1,1,1,0);
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-    glMatrixMode(GL_PROJECTION);
-    glPushMatrix();
-    glMatrixMode(GL_MODELVIEW);
-    glPushMatrix();
-    
-    glEnable(GL_LIGHTING);
-    glEnable(GL_DEPTH_TEST);
-    _pViewer->set3DContext();
-    _pViewer->DrawScene(_pViewer->glRenderer());
-    glDisable(GL_DEPTH_TEST);
-    glDisable(GL_LIGHTING);
-    glMatrixMode(GL_PROJECTION);
-    glPopMatrix();
-    glMatrixMode(GL_MODELVIEW);
-    glPopMatrix();
-  }
-  
-  
-  glDisable(GL_DEPTH_TEST);
-  FRS_glBlendEquation(GL_ADD);
-  
-  glBlendFunc(GL_DST_COLOR, GL_ZERO);
-  
-  glPushAttrib(GL_COLOR_BUFFER_BIT);
-  FRS_glBlendEquation(GL_FUNC_SUBTRACT);
-  glBlendFunc(GL_ONE, GL_ONE);
-  
-  glDisable(GL_TEXTURE_2D);
-  glEnable(GL_BLEND);
-  glColor4f(1,1,1,1);
-  glBegin(GL_TRIANGLE_STRIP);
-  {  
-    glVertex2f(0, 0);
-    glVertex2f(2048, 0);
-    glVertex2f(0, 2048);
-    glVertex2f(2048, 2048);
-  }  
-  glEnd();
-  glPopAttrib();
-  
-  glDisable(GL_DEPTH_TEST);
-  FRS_glBlendEquation(GL_ADD);
-  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
-  
-  glEnable(GL_TEXTURE_2D);
-
-  Canvas::Render(iRenderer);
-  //  
-  glPushAttrib(GL_COLOR_BUFFER_BIT);
-  FRS_glBlendEquation(GL_FUNC_SUBTRACT);
-  glBlendFunc(GL_ONE, GL_ONE);
-  
-  glDisable(GL_TEXTURE_2D);
-  glEnable(GL_BLEND);
-  glColor3f(1,1,1);
-  glBegin(GL_TRIANGLE_STRIP);
-  { 
-    glVertex2f(0, 0);
-    glVertex2f(2048, 0);
-    glVertex2f(0, 2048);
-    glVertex2f(2048, 2048);
-  } 
-  glEnd();
-  glPopAttrib();
-  
-  glDisable(GL_TEXTURE_2D);
-  glDisable(GL_BLEND);
-}
-
-void AppCanvas::RenderBasic(const StrokeRenderer *iRenderer)
-{
-  glClearColor(1,1,1,1);
-  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-  glDisable(GL_LIGHTING);
-  glPolygonMode(GL_FRONT, GL_FILL);
-  glShadeModel(GL_SMOOTH);
-  
-  if(_pViewer->draw3DsceneEnabled())
-  {
-    glClearColor(1,1,1,0);
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-    glMatrixMode(GL_PROJECTION);
-    glPushMatrix();
-    glMatrixMode(GL_MODELVIEW);
-    glPushMatrix();
-    
-    glEnable(GL_LIGHTING);
-    glEnable(GL_DEPTH_TEST);
-    _pViewer->set3DContext();
-    _pViewer->DrawScene(_pViewer->glRenderer());
-    glDisable(GL_DEPTH_TEST);
-    glDisable(GL_LIGHTING);
-    glMatrixMode(GL_PROJECTION);
-    glPopMatrix();
-    glMatrixMode(GL_MODELVIEW);
-    glPopMatrix();
-  }
-
-  glBlendFunc(GL_DST_COLOR, GL_ZERO);
-
-  glDisable(GL_DEPTH_TEST);
-  glPushAttrib(GL_COLOR_BUFFER_BIT);
-  glEnable(GL_BLEND);
-  glPopAttrib();
-
-  glDisable(GL_DEPTH_TEST);
-  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
-  
-  glEnable(GL_TEXTURE_2D);
-  Canvas::RenderBasic(iRenderer);
-
-  glDisable(GL_TEXTURE_2D);
-  glDisable(GL_BLEND);
-}
-
-
 void AppCanvas::RenderStroke(Stroke *iStroke) {
 
 	if(_basic)
 		iStroke->RenderBasic(_Renderer);
 	else
 		iStroke->Render(_Renderer);
-
-  if(_pViewer->getRecordFlag()){
-     _pViewer->saveSnapshot(true);
-  }
 }
+
+
+void AppCanvas::update() {}
+

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppCanvas.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppCanvas.h	2008-12-01 21:23:58 UTC (rev 17670)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppCanvas.h	2008-12-01 21:30:44 UTC (rev 17671)
@@ -33,13 +33,10 @@
 
   virtual BBox<Vec3r> scene3DBBox() const ;
 
-  /*! update the canvas (display) */
-  virtual void update() ;
+	// abstract
+	virtual void RenderStroke(Stroke*);
+	virtual void update();
 
-  /*! Renders the created strokes */
-  virtual void Render(const StrokeRenderer *iRenderer);
-  virtual void RenderBasic(const StrokeRenderer *iRenderer);
-  virtual void RenderStroke(Stroke *iStroke) ;
 
   /*! accessors */
   virtual int width() const ;

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppGLWidget.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppGLWidget.cpp	2008-12-01 21:23:58 UTC (rev 17670)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/AppGLWidget.cpp	2008-12-01 21:30:44 UTC (rev 17671)
@@ -34,6 +34,7 @@
 #include "../scene_graph/NodeShape.h"
 #include "../scene_graph/VertexRep.h"
 #include "AppConfig.h"
+#include "AppCanvas.h"
 
 #include "../system/StringUtils.h"
 
@@ -203,7 +204,6 @@
       _pDebugRenderer = NULL;
     }

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list