2.50: svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r19323...
[blender.git] / source / blender / gpu / intern / gpu_draw.c
index 3c1c280..0e123d8 100644 (file)
@@ -83,7 +83,18 @@ void GPU_render_text(MTFace *tface, int mode,
                Image* ima;
                int characters, index, character;
                float centerx, centery, sizex, sizey, transx, transy, movex, movey, advance;
-
+               float advance_tab;
+               
+               
+               /* multiline */
+               float line_start= 0.0f, line_height; 
+               if (v4)
+                       line_height= MAX4(v1[1], v2[1], v3[1], v4[2]) - MIN4(v1[1], v2[1], v3[1], v4[2]);
+               else
+                       line_height= MAX3(v1[1], v2[1], v3[1]) - MIN3(v1[1], v2[1], v3[1]);
+               line_height *= 1.2; /* could be an option? */
+               /* end multiline */
+               
                characters = textlen;
 
                ima = (Image*)tface->tpage;
@@ -97,12 +108,32 @@ void GPU_render_text(MTFace *tface, int mode,
                        glColor3f(1.0f, 1.0f, 1.0f);
 
                glPushMatrix();
+               
+               /* get the tab width */
+               matrixGlyph((ImBuf *)ima->ibufs.first, ' ', & centerx, &centery,
+                       &sizex, &sizey, &transx, &transy, &movex, &movey, &advance);
+               
+               advance_tab= advance * 4; /* tab width could also be an option */
+               
+               
                for (index = 0; index < characters; index++) {
                        float uv[4][2];
 
                        // lets calculate offset stuff
                        character = textstr[index];
                        
+                       if (character=='\n') {
+                               glTranslatef(line_start, -line_height, 0.0);
+                               line_start = 0.0f;
+                               continue;
+                       }
+                       else if (character=='\t') {
+                               glTranslatef(advance_tab, 0.0, 0.0);
+                               line_start -= advance_tab; /* so we can go back to the start of the line */
+                               continue;
+                               
+                       }
+                       
                        // space starts at offset 1
                        // character = character - ' ' + 1;
                        matrixGlyph((ImBuf *)ima->ibufs.first, character, & centerx, &centery,
@@ -143,6 +174,7 @@ void GPU_render_text(MTFace *tface, int mode,
                        glEnd();
 
                        glTranslatef(advance, 0.0, 0.0);
+                       line_start -= advance; /* so we can go back to the start of the line */
                }
                glPopMatrix();
        }
@@ -762,6 +794,9 @@ static struct GPUMaterialState {
        Material *gboundmat;
        Object *gob;
        Scene *gscene;
+       int glay;
+       float (*gviewmat)[4];
+       float (*gviewinv)[4];
 
        GPUBlendMode blendmode[MAXMATBUF];
        int alphapass;
@@ -784,7 +819,7 @@ Material *gpu_active_node_material(Material *ma)
        return ma;
 }
 
-void GPU_set_object_materials(Scene *scene, Object *ob, int glsl, int *do_alpha_pass)
+void GPU_set_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, Object *ob, int glsl, int *do_alpha_pass)
 {
        extern Material defmaterial; /* from material.c */
        Material *ma;
@@ -801,8 +836,11 @@ void GPU_set_object_materials(Scene *scene, Object *ob, int glsl, int *do_alpha_
        GMS.gob = ob;
        GMS.gscene = scene;
        GMS.totmat= ob->totcol;
+       GMS.glay= v3d->lay;
+       GMS.gviewmat= rv3d->viewmat;
+       GMS.gviewinv= rv3d->viewinv;
 
-       GMS.alphapass = (G.vd && G.vd->transp);
+       GMS.alphapass = (v3d && v3d->transp);
        if(do_alpha_pass)
                *do_alpha_pass = 0;
 
@@ -923,8 +961,8 @@ int GPU_enable_material(int nr, void *attribs)
 
                        gpumat = GPU_material_from_blender(GMS.gscene, mat);
                        GPU_material_vertex_attributes(gpumat, gattribs);
-                       GPU_material_bind(gpumat, GMS.gob->lay, G.vd->lay, 1.0);
-                       GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, G.vd->viewmat, G.vd->viewinv, GMS.gob->col);
+                       GPU_material_bind(gpumat, GMS.gob->lay, GMS.glay, 1.0);
+                       GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, GMS.gviewmat, GMS.gviewinv, GMS.gob->col);
                        GMS.gboundmat= mat;
 
                        if(GMS.alphapass) glDepthMask(1);
@@ -1067,7 +1105,7 @@ int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[][4
                glPushMatrix();
                glLoadMatrixf((float *)viewmat);
                
-               where_is_object_simul(base->object);
+               where_is_object_simul(scene, base->object);
                
                if(la->type==LA_SUN) {
                        /* sun lamp */