[Bf-blender-cvs] [1949987] temp_viewport_fx_merge: Painstakingly merge branch 'master' into temp_viewport_fx_merge

Antony Riakiotakis noreply at git.blender.org
Sun Jun 19 21:17:59 CEST 2016


Commit: 194998766c651750acbc74049a7467b55169a641
Author: Antony Riakiotakis
Date:   Sun Jun 19 21:17:17 2016 +0200
Branches: temp_viewport_fx_merge
https://developer.blender.org/rB194998766c651750acbc74049a7467b55169a641

Painstakingly merge branch 'master' into temp_viewport_fx_merge

This branch will not make it into blender, however there are a few things that might be useful here for people who work on the viewport project and could be merged to master:

* Matrix stacks
There is working code for matrix stacks in gpu_matrix.c. Basically it works by overriding all draw calls with a special version that loads our custom stack in OpenGL. To refactor this out, coders should do this in three stages:

1) Inspect all calls to GPUBegin/GPUDraw*/GPURect* and only add one call to upload the matrices once to the relevant uniform of the shader, then substitute with the normal GL call.

2) Remove all hardcoded GL matrices from shaders. Shaders should use generic uniforms/uniform blocks for matrices

3) Do not use GL-style stacks. Actually stacks should be generic and local, not global. We do not care about a global projection/modelview etc matrix, rather we want to add matrix stacks locally in places where they are needed and upload those matrices to our shaders. The code can be generalized to do that by substituting the enum in the gpuMatrix* functions with a GPUMatrixStack* though it will be slightly tedious to do - like everything viewport related.

* GLU removal:

This branch also removes glu completely from blender by providing a helper library that handles drawing of some helper shapes. The way this is handled is not ideal, since it uses the GSOC code that is not the way we want to do things here, however it could be improved and made with a proper design.

There are some graphical glitches still here, but should be fixable.

===================================================================



===================================================================

diff --cc CMakeLists.txt
index 1275bb5,1c933d3..35cd52f
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@@ -421,9 -459,14 +459,8 @@@ mark_as_advanced
  	WITH_GL_PROFILE_COMPAT
  	WITH_GL_PROFILE_CORE
  	WITH_GL_PROFILE_ES20
- 	WITH_GPU_DEBUG
  )
  
 -if(WITH_GL_PROFILE_COMPAT)
 -	set(WITH_GLU ON)
 -else()
 -	set(WITH_GLU OFF)
 -endif()
 -
  if(WIN32)
  	option(WITH_GL_ANGLE "Link with the ANGLE library, an OpenGL ES 2.0 implementation based on Direct3D, instead of the system OpenGL library." OFF)
  	mark_as_advanced(WITH_GL_ANGLE)
diff --cc intern/elbeem/intern/solver_control.cpp
index c3015b8,c3015b8..8d1d26e
--- a/intern/elbeem/intern/solver_control.cpp
+++ b/intern/elbeem/intern/solver_control.cpp
@@@ -894,7 -894,7 +894,7 @@@ void LbmFsgrSolver::cpDebugDisplay(int 
  		// dot influence
  		if((mpControl->mDebugCpscale>0.) && cpDots) {
  			glPointSize(mpControl->mDebugCpscale * 8.);
--			glBegin(GL_POINTS);
++			GPUBegin(GL_POINTS);
  			for(int i=0; i<cparts->getSize(); i++) {
  				if((cpHideIna)&&( (cparts->getParticle(i)->influence<=0.) || (cparts->getParticle(i)->size<=0.) )) continue;
  				ntlVec3Gfx org( vec2G(cparts->getParticle(i)->pos ) );
@@@ -911,7 -911,7 +911,7 @@@
  		// cp positions
  		if((mpControl->mDebugCpscale>0.) && cpDots) {
  			glPointSize(mpControl->mDebugCpscale * 3.);
--			glBegin(GL_POINTS); 
++			GPUBegin(GL_POINTS); 
  			glColor3f( 0,1,0 );
  		}
  		for(int i=0; i<cparts->getSize(); i++) {
@@@ -934,7 -934,7 +934,7 @@@
  			const float scale = mpControl->mDebugAvgVelScale;
  
  			glColor3f( 1.0,1.0,1 );
--			glBegin(GL_LINES); 
++			GPUBegin(GL_LINES); 
  			for(int i=0; i<cparts->getSize(); i++) {
  				if((cpHideIna)&&( (cparts->getParticle(i)->influence<=0.) || (cparts->getParticle(i)->size<=0.) )) continue;
  				ntlVec3Gfx  org( vec2G(cparts->getParticle(i)->pos ) );
@@@ -955,7 -955,7 +955,7 @@@
  			// debug, for use of e.g. LBMGET_FORCE LbmControlData *mpControl = this;
  #			define TESTGET_FORCE(lev,i,j,k)   mpControl->mCpForces[lev][ ((k*mLevel[lev].lSizey)+j)*mLevel[lev].lSizex+i ]
  	
--			glBegin(GL_LINES);
++			GPUBegin(GL_LINES);
  			//const int lev=0; 
  			for(int lev=0; lev<=mMaxRefine; lev++) {
  			FSGR_FORIJK_BOUNDS(lev) {
diff --cc intern/elbeem/intern/solver_util.cpp
index 6eca427,6eca427..39987f2
--- a/intern/elbeem/intern/solver_util.cpp
+++ b/intern/elbeem/intern/solver_util.cpp
@@@ -1782,7 -1782,7 +1782,7 @@@ void LbmFsgrSolver::debugDisplayNode(in
  		case FLUIDDISPVelocities: {
  				// dont use cube display
  				LbmVec vel = this->getCellVelocity( cell, set );
--				glBegin(GL_LINES);
++				GPUBegin(GL_LINES);
  				glColor3f( 0.0,0.0,0.0 );
  				glVertex3f( org[0], org[1], org[2] );
  				org += vec2G(vel * 10.0 * cscale);
diff --cc intern/glew-mx/intern/gl-deprecated.h
index 1a23642,1a23642..2f40c82
--- a/intern/glew-mx/intern/gl-deprecated.h
+++ b/intern/glew-mx/intern/gl-deprecated.h
@@@ -38,8 -38,8 +38,8 @@@
  #define glAccum DO_NOT_USE_glAccum
  #undef glAlphaFunc
  #define glAlphaFunc DO_NOT_USE_glAlphaFunc
--#undef glBegin
--#define glBegin DO_NOT_USE_glBegin
++#undef GPUBegin
++#define GPUBegin DO_NOT_USE_GPUBegin
  #undef glBitmap
  #define glBitmap DO_NOT_USE_glBitmap
  #undef glCallList
diff --cc source/blender/blenfont/intern/blf.c
index b5be69f,132a0ec..19da90c
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@@ -493,7 -490,7 +492,7 @@@ void BLF_rotation_default(float angle
  	}
  }
  
- static void blf_draw__start(FontBLF *font, GLint *param)
 -static void blf_draw_gl__start(FontBLF *font, GLint *mode)
++static void blf_draw_gl__start(FontBLF *font)
  {
  	/*
  	 * The pixmap alignment hack is handle
@@@ -501,84 -498,118 +500,104 @@@
  	 */
  
  	glEnable(GL_BLEND);
- 	glEnable(GL_TEXTURE_2D);
  	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
+ #ifndef BLF_STANDALONE
+ 	GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
+ #endif
+ 
 -	/* Save the current matrix mode. */
 -	glGetIntegerv(GL_MATRIX_MODE, mode);
 -
 -	glMatrixMode(GL_TEXTURE);
 -	glPushMatrix();
 -	glLoadIdentity();
 +	gpuPushMatrix(GPU_TEXTURE_MATRIX);
 +	gpuLoadIdentity(GPU_TEXTURE_MATRIX);
  
 -	glMatrixMode(GL_MODELVIEW);
 -	glPushMatrix();
 +	gpuPushMatrix(GPU_MODELVIEW_MATRIX);
  
  	if (font->flags & BLF_MATRIX)
 -		glMultMatrixf(font->m);
 +		gpuMultMatrixd(GPU_MODELVIEW_MATRIX, font->m);
  
 -	glTranslate3fv(font->pos);
 +	gpuTranslate(GPU_MODELVIEW_MATRIX, font->pos[0], font->pos[1], font->pos[2]);
  
  	if (font->flags & BLF_ASPECT)
 -		glScalef(font->aspect[0], font->aspect[1], font->aspect[2]);
 +		gpuScale(GPU_MODELVIEW_MATRIX, font->aspect[0], font->aspect[1], font->aspect[2]);
  
  	if (font->flags & BLF_ROTATION)  /* radians -> degrees */
 -		glRotatef(font->angle * (float)(180.0 / M_PI), 0.0f, 0.0f, 1.0f);
 +		gpuRotateAxis(GPU_MODELVIEW_MATRIX, font->angle * (float)(180.0 / M_PI), 'Z');
  
  	if (font->shadow || font->blur)
  		glGetFloatv(GL_CURRENT_COLOR, font->orig_col);
  
  	/* always bind the texture for the first glyph */
  	font->tex_bind_state = -1;
- 
- 	/* Save the current parameter to restore it later. */
- 	glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param);
- 	if (*param != GL_MODULATE)
- 		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  }
  
- static void blf_draw__end(GLint param)
 -static void blf_draw_gl__end(GLint mode)
++static void blf_draw_gl__end()
  {
- 	/* and restore the original value. */
- 	if (param != GL_MODULATE)
- 		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, param);
 -	glMatrixMode(GL_TEXTURE);
 -	glPopMatrix();
 -
 -	glMatrixMode(GL_MODELVIEW);
 -	glPopMatrix();
--
 -	if (mode != GL_MODELVIEW)
 -		glMatrixMode(mode);
 +	gpuPopMatrix(GPU_TEXTURE_MATRIX);
 +	gpuPopMatrix(GPU_MODELVIEW_MATRIX);
  
+ #ifndef BLF_STANDALONE
+ 	GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ #endif
  	glDisable(GL_BLEND);
- 	glDisable(GL_TEXTURE_2D);
  }
  
- void BLF_draw(int fontid, const char *str, size_t len)
+ void BLF_draw_ex(
+         int fontid, const char *str, size_t len,
+         struct ResultBLF *r_info)
  {
  	FontBLF *font = blf_get(fontid);
- 	GLint param;
 -	GLint mode;
+ 
+ 	BLF_RESULT_CHECK_INIT(r_info);
  
  	if (font && font->glyph_cache) {
- 		blf_draw__start(font, &param);
- 		blf_font_draw(font, str, len);
- 		blf_draw__end(param);
 -		blf_draw_gl__start(font, &mode);
++		blf_draw_gl__start(font);
+ 		if (font->flags & BLF_WORD_WRAP) {
+ 			blf_font_draw__wrap(font, str, len, r_info);
+ 		}
+ 		else {
+ 			blf_font_draw(font, str, len, r_info);
+ 		}
 -		blf_draw_gl__end(mode);
++		blf_draw_gl__end();
  	}
  }
+ void BLF_draw(int fontid, const char *str, size_t len)
+ {
+ 	BLF_draw_ex(fontid, str, len, NULL);
+ }
  
- void BLF_draw_ascii(int fontid, const char *str, size_t len)
+ void BLF_draw_ascii_ex(
+         int fontid, const char *str, size_t len,
+         struct ResultBLF *r_info)
  {
  	FontBLF *font = blf_get(fontid);
- 	GLint param;
 -	GLint mode;
+ 
+ 	BLF_RESULT_CHECK_INIT(r_info);
  
  	if (font && font->glyph_cache) {
- 		blf_draw__start(font, &param);
- 		blf_font_draw_ascii(font, str, len);
- 		blf_draw__end(param);
 -		blf_draw_gl__start(font, &mode);
++		blf_draw_gl__start(font);
+ 		if (font->flags & BLF_WORD_WRAP) {
+ 			/* use non-ascii draw function for word-wrap */
+ 			blf_font_draw__wrap(font, str, len, r_info);
+ 		}
+ 		else {
+ 			blf_font_draw_ascii(font, str, len, r_info);
+ 		}
 -		blf_draw_gl__end(mode);
++		blf_draw_gl__end();
  	}
  }
+ void BLF_draw_ascii(int fontid, const char *str, size_t len)
+ {
+ 	BLF_draw_ascii_ex(fontid, str, len, NULL);
+ }
  
  int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth)
  {
  	FontBLF *font = blf_get(fontid);
- 	GLint param;
 -	GLint mode;
  	int columns = 0;
  
  	if (font && font->glyph_cache) {
- 		blf_draw__start(font, &param);
 -		blf_draw_gl__start(font, &mode);
++		blf_draw_gl__start(font);
  		columns = blf_font_draw_mono(font, str, len, cwidth);
- 		blf_draw__end(param);
 -		blf_draw_gl__end(mode);
++		blf_draw_gl__end();
  	}
  
  	return columns;
diff --cc source/blender/blenfont/intern/blf_glyph.c
index 4d30506,aa7d539..34675c4
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@@ -55,7 -55,9 +55,10 @@@
  #include "BIF_gl.h"
  #include "BLF_api.h"
  
 +#include "GPU_immediate.h"
+ #ifndef BLF_STANDALONE
+ #include "GPU_basic_shader.h"
+ #endif
  
  #include "blf_internal_types.h"
  #include "blf_internal.h"
diff --cc source/blender/blenkernel/intern/DerivedMesh.c
index ffb1dd8,d590a35..291e642
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@@ -73,8 -76,12 +76,14 @@@ static DerivedMesh *navmesh_dm_createNa
  #include "BLI_sys_types.h" /* for intptr_t support */
  
  #include "GPU_buffers.h"
 +#include "GPU_extensions.h"
 +#include "GPU_immediate.h"
+ #include "GPU_glew.h"
+ #include "GPU_shader.h"
+ 
+ #ifdef WITH_OPENSUBDIV
+ #  include "DNA_userdef_types.h"
+ #endif
  
  /* very slow! enable for testing only! */
  //#define USE_MODIFIER_VALIDATE
@@@ -3238,9 -3881,7 +3883,7 @@@ static void navmesh_drawColored(Derived
  	/* if (GPU_buffer_legacy(dm) ) */ /* TODO - VBO draw code, not high priority - campbell */
  	{
  		DEBUG_VBO("Using legacy code. drawNavMeshColored\n");
- 		//glShadeModel(GL_SMOOTH);
 -		glBegin(glmode = GL_QUADS);
 +		GPUBegin(glmode = GL_QUADS);
  		for (a = 0; a < dm->numTessFaceData; a++, mface++) {
  			int new_glmode = mface->v4 ? GL_QUADS : GL_TRIANGLES;
  			int pi = polygonIdx[a];
diff --cc source/blender/blenkernel/intern/cdderivedmesh.c
index c407ad0,267f7a6..1c3aa38
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@@ -57,8 -57,11 +57,13 @@@
  
  #include "GPU_buffers.h"
  #include "GPU_draw.h"
 +#include "GPU_extensions.h"
 +#include "GPU_immediate.h"
+ #include "GPU_glew.h"
+ #include "GPU_shader.h"
+ #include "GPU_basic_shader.h"
+ 
+ #include "WM_api.h"
  
  #include <string.h>
  #include <limits.h>
@@@ -341,52 -367,41 +369,41 @@@ static void cdDM_update_normals_from_pb
  static void cdDM_drawVerts(DerivedMesh *dm)
  {
  	GPU_vertex_setup(dm);
- 	if (dm->drawObject-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list