-// File: OpenGl_View_2.cxx
-// Created: 20 September 2011
-// Author: Sergey ZERCHANINOV
-// Copyright: OPEN CASCADE 2011
-
-#define G003 /* EUG 20-09-99 ; Animation management
-*/
-
-/*----------------------------------------------------------------------*/
-/*
-* Includes
-*/
+// Created on: 2011-09-20
+// Created by: Sergey ZERCHANINOV
+// Copyright (c) 2011-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
#include <stdio.h>
#include <stdlib.h>
-#include <OpenGl_tgl_all.hxx>
+#include <OpenGl_GlCore11.hxx>
#include <OpenGl_tgl_funcs.hxx>
-#include <OpenGl_TextureBox.hxx>
-#include <AlienImage.hxx>
-#include <Image_Image.hxx>
+#include <Image_AlienPixMap.hxx>
#include <Visual3d_Layer.hxx>
-#if defined(WNT)
-#include <GL/glu.h>
-#endif
+#include <NCollection_Mat4.hxx>
#include <OpenGl_AspectLine.hxx>
+#include <OpenGl_Context.hxx>
#include <OpenGl_Display.hxx>
+#include <OpenGl_Matrix.hxx>
#include <OpenGl_Workspace.hxx>
#include <OpenGl_View.hxx>
#include <OpenGl_Trihedron.hxx>
#include <OpenGl_GraduatedTrihedron.hxx>
#include <OpenGl_PrinterContext.hxx>
-
-/*----------------------------------------------------------------------*/
-/*
-* Constantes
-*/
+#include <OpenGl_ShaderManager.hxx>
+#include <OpenGl_ShaderProgram.hxx>
+#include <OpenGl_Structure.hxx>
#define EPSI 0.0001
-#ifndef M_PI
-# define M_PI 3.14159265358979323846
-#endif
+namespace
+{
+
+ static const GLfloat THE_DEFAULT_AMBIENT[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
+ static const GLfloat THE_DEFAULT_SPOT_DIR[3] = { 0.0f, 0.0f, -1.0f };
+ static const GLfloat THE_DEFAULT_SPOT_EXPONENT = 0.0f;
+ static const GLfloat THE_DEFAULT_SPOT_CUTOFF = 180.0f;
-static const GLfloat default_amb[4] = { 0.F, 0.F, 0.F, 1.F };
-static const GLfloat default_sptdir[3] = { 0.F, 0.F, -1.F };
-static const GLfloat default_sptexpo = 0.F;
-static const GLfloat default_sptcutoff = 180.F;
+};
-extern void InitLayerProp (const int AListId); //szvgl: defined in OpenGl_GraphicDriver_Layer.cxx
+extern void InitLayerProp (const int theListId); //szvgl: defined in OpenGl_GraphicDriver_Layer.cxx
/*----------------------------------------------------------------------*/
{
GLboolean isEnabled;
GLdouble Equation[4];
- IMPLEMENT_MEMORY_OPERATORS
+ DEFINE_STANDARD_ALLOC
};
/*----------------------------------------------------------------------*/
/*
* Set des lumieres
*/
-static void bind_light(const OpenGl_Light *lptr, int *gl_lid)
+static void bind_light (const OpenGl_Light& theLight,
+ GLenum& theLightGlId,
+ Graphic3d_Vec4& theAmbientColor)
{
// Only 8 lights in OpenGL...
- if (*gl_lid > GL_LIGHT7) return;
-
- // the light is a headlight ?
- GLint cur_matrix;
- if (lptr->HeadLight)
+ if (theLightGlId > GL_LIGHT7)
{
- glGetIntegerv(GL_MATRIX_MODE, &cur_matrix);
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
+ return;
}
- GLfloat data_amb[4];
- GLfloat data_diffu[4];
- GLfloat data_pos[4];
- GLfloat data_sptdir[3];
- GLfloat data_sptexpo;
- GLfloat data_sptcutoff;
- GLfloat data_constantattenuation;
- GLfloat data_linearattenuation;
-
- /* set la light en fonction de son type */
- switch (lptr->type)
+ if (theLight.Type == Visual3d_TOLS_AMBIENT)
{
- case TLightAmbient:
- data_amb[0] = lptr->col.rgb[0];
- data_amb[1] = lptr->col.rgb[1];
- data_amb[2] = lptr->col.rgb[2];
- data_amb[3] = 1.0;
-
- /*------------------------- Ambient ---------------------------*/
- /*
- * The GL_AMBIENT parameter refers to RGBA intensity of the ambient
- * light.
- */
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, data_amb);
- break;
-
-
- case TLightDirectional:
- data_diffu[0] = lptr->col.rgb[0];
- data_diffu[1] = lptr->col.rgb[1];
- data_diffu[2] = lptr->col.rgb[2];
- data_diffu[3] = 1.0;
-
- /*------------------------- Direction ---------------------------*/
- /* From Open GL Programming Rev 1 Guide Chapt 6 :
- Lighting The Mathematics of Lighting ( p 168 )
-
- Directional Light Source ( Infinite ) :
- if the last parameter of GL_POSITION , w , is zero, the
- corresponding light source is a Directional one.
-
- GL_SPOT_CUTOFF a 180 signifie que ce n'est pas un spot.
- To create a realistic effect, set the GL_SPECULAR parameter
- to the same value as the GL_DIFFUSE.
- */
-
- data_pos[0] = -lptr->dir[0];
- data_pos[1] = -lptr->dir[1];
- data_pos[2] = -lptr->dir[2];
- data_pos[3] = 0.0;
-
- glLightfv(*gl_lid, GL_AMBIENT, default_amb);
- glLightfv(*gl_lid, GL_DIFFUSE, data_diffu);
- glLightfv(*gl_lid, GL_SPECULAR, data_diffu);
-
- glLightfv(*gl_lid, GL_POSITION, data_pos);
- glLightfv(*gl_lid, GL_SPOT_DIRECTION, default_sptdir);
- glLightf(*gl_lid, GL_SPOT_EXPONENT, default_sptexpo);
- glLightf(*gl_lid, GL_SPOT_CUTOFF, default_sptcutoff);
- break;
-
-
- case TLightPositional:
- data_diffu[0] = lptr->col.rgb[0];
- data_diffu[1] = lptr->col.rgb[1];
- data_diffu[2] = lptr->col.rgb[2];
- data_diffu[3] = 1.0;
-
- /*------------------------- Position -----------------------------*/
- /* From Open GL Programming Rev 1 Guide Chapt 6 :
- Lighting The Mathematics of Lighting ( p 168 )
- Positional Light Source :
- if the last parameter of GL_POSITION , w , is nonzero,
- the corresponding light source is a Positional one.
-
- GL_SPOT_CUTOFF a 180 signifie que ce n'est pas un spot.
-
- To create a realistic effect, set the GL_SPECULAR parameter
- to the same value as the GL_DIFFUSE.
- */
+ // add RGBA intensity of the ambient light
+ theAmbientColor += theLight.Color;
+ return;
+ }
- data_pos[0] = lptr->pos[0];
- data_pos[1] = lptr->pos[1];
- data_pos[2] = lptr->pos[2];
- data_pos[3] = 1.0;
-
- data_constantattenuation = lptr->atten[0];
- data_linearattenuation = lptr->atten[1];
-
- glLightfv(*gl_lid, GL_AMBIENT, default_amb);
- glLightfv(*gl_lid, GL_DIFFUSE, data_diffu);
- glLightfv(*gl_lid, GL_SPECULAR, data_diffu);
-
- glLightfv(*gl_lid, GL_POSITION, data_pos);
- glLightfv(*gl_lid, GL_SPOT_DIRECTION, default_sptdir);
- glLightf(*gl_lid, GL_SPOT_EXPONENT, default_sptexpo);
- glLightf(*gl_lid, GL_SPOT_CUTOFF, default_sptcutoff);
- glLightf(*gl_lid, GL_CONSTANT_ATTENUATION, data_constantattenuation);
- glLightf(*gl_lid, GL_LINEAR_ATTENUATION, data_linearattenuation);
- glLightf(*gl_lid, GL_QUADRATIC_ATTENUATION, 0.0);
- break;
-
-
- case TLightSpot:
- data_diffu[0] = lptr->col.rgb[0];
- data_diffu[1] = lptr->col.rgb[1];
- data_diffu[2] = lptr->col.rgb[2];
- data_diffu[3] = 1.0;
-
- data_pos[0] = lptr->pos[0];
- data_pos[1] = lptr->pos[1];
- data_pos[2] = lptr->pos[2];
- data_pos[3] = 1.0;
-
- data_sptdir[0] = lptr->dir[0];
- data_sptdir[1] = lptr->dir[1];
- data_sptdir[2] = lptr->dir[2];
-
- data_sptexpo = ( float )lptr->shine * 128.0F;
- data_sptcutoff = ( float )(lptr->angle * 180.0F)/( float )M_PI;
-
- data_constantattenuation = lptr->atten[0];
- data_linearattenuation = lptr->atten[1];
-
- glLightfv(*gl_lid, GL_AMBIENT, default_amb);
- glLightfv(*gl_lid, GL_DIFFUSE, data_diffu);
- glLightfv(*gl_lid, GL_SPECULAR, data_diffu);
-
- glLightfv(*gl_lid, GL_POSITION, data_pos);
- glLightfv(*gl_lid, GL_SPOT_DIRECTION, data_sptdir);
- glLightf(*gl_lid, GL_SPOT_EXPONENT, data_sptexpo);
- glLightf(*gl_lid, GL_SPOT_CUTOFF, data_sptcutoff);
- glLightf(*gl_lid, GL_CONSTANT_ATTENUATION, data_constantattenuation);
- glLightf(*gl_lid, GL_LINEAR_ATTENUATION, data_linearattenuation);
- glLightf(*gl_lid, GL_QUADRATIC_ATTENUATION, 0.0);
- break;
+ // the light is a headlight?
+ GLint aMatrixModeOld = 0;
+ if (theLight.IsHeadlight)
+ {
+ glGetIntegerv (GL_MATRIX_MODE, &aMatrixModeOld);
+ glMatrixMode (GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
}
- if (lptr->type != TLightAmbient)
- {
- glEnable(*gl_lid);
- (*gl_lid)++;
+ // setup light type
+ switch (theLight.Type)
+ {
+ case Visual3d_TOLS_DIRECTIONAL:
+ {
+ // if the last parameter of GL_POSITION, is zero, the corresponding light source is a Directional one
+ const OpenGl_Vec4 anInfDir = -theLight.Direction;
+
+ // to create a realistic effect, set the GL_SPECULAR parameter to the same value as the GL_DIFFUSE.
+ glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT);
+ glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData());
+ glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData());
+ glLightfv (theLightGlId, GL_POSITION, anInfDir.GetData());
+ glLightfv (theLightGlId, GL_SPOT_DIRECTION, THE_DEFAULT_SPOT_DIR);
+ glLightf (theLightGlId, GL_SPOT_EXPONENT, THE_DEFAULT_SPOT_EXPONENT);
+ glLightf (theLightGlId, GL_SPOT_CUTOFF, THE_DEFAULT_SPOT_CUTOFF);
+ break;
+ }
+ case Visual3d_TOLS_POSITIONAL:
+ {
+ // to create a realistic effect, set the GL_SPECULAR parameter to the same value as the GL_DIFFUSE
+ glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT);
+ glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData());
+ glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData());
+ glLightfv (theLightGlId, GL_POSITION, theLight.Position.GetData());
+ glLightfv (theLightGlId, GL_SPOT_DIRECTION, THE_DEFAULT_SPOT_DIR);
+ glLightf (theLightGlId, GL_SPOT_EXPONENT, THE_DEFAULT_SPOT_EXPONENT);
+ glLightf (theLightGlId, GL_SPOT_CUTOFF, THE_DEFAULT_SPOT_CUTOFF);
+ glLightf (theLightGlId, GL_CONSTANT_ATTENUATION, theLight.ConstAttenuation());
+ glLightf (theLightGlId, GL_LINEAR_ATTENUATION, theLight.LinearAttenuation());
+ glLightf (theLightGlId, GL_QUADRATIC_ATTENUATION, 0.0);
+ break;
+ }
+ case Visual3d_TOLS_SPOT:
+ {
+ glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT);
+ glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData());
+ glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData());
+ glLightfv (theLightGlId, GL_POSITION, theLight.Position.GetData());
+ glLightfv (theLightGlId, GL_SPOT_DIRECTION, theLight.Direction.GetData());
+ glLightf (theLightGlId, GL_SPOT_EXPONENT, theLight.Concentration() * 128.0f);
+ glLightf (theLightGlId, GL_SPOT_CUTOFF, (theLight.Angle() * 180.0f) / GLfloat(M_PI));
+ glLightf (theLightGlId, GL_CONSTANT_ATTENUATION, theLight.ConstAttenuation());
+ glLightf (theLightGlId, GL_LINEAR_ATTENUATION, theLight.LinearAttenuation());
+ glLightf (theLightGlId, GL_QUADRATIC_ATTENUATION, 0.0f);
+ break;
+ }
}
- /* si la light etait une headlight alors restaure la matrice precedente */
- if (lptr->HeadLight)
+ // restore matrix in case of headlight
+ if (theLight.IsHeadlight)
{
glPopMatrix();
- glMatrixMode(cur_matrix);
+ glMatrixMode (aMatrixModeOld);
}
+
+ glEnable (theLightGlId++);
}
/*----------------------------------------------------------------------*/
void call_func_eval_ori_matrix3 (const point3* vrp, // view reference point
const vec3* vpn, // view plane normal
const vec3* vup, // view up vector
- int* err_ind,
+ int* err_ind,
float mout[4][4]) // OUT view orientation matrix
{
*/
/* OCC18942: obsolete in OCCT6.3, might be removed in further versions! */
void call_func_eval_map_matrix3(
- view_map3 *Map,
- int *err_ind,
+ view_map3 *Map,
+ int *err_ind,
matrix3 mat)
{
int i, j;
/*
* Type Parallele
- */
+ */
if (Map->proj_type == TYPE_PARAL)
{
float umid, vmid;
call_util_mat_mul( tmat, shmat, tshmat );
call_util_mat_mul( smat, tshmat, mat );
- return;
+ return;
#endif
/* CAL */
aux_mat1[3][2] = Map->proj_vp.z_min;
call_util_mat_mul (aux_mat2, aux_mat1, mat);
- return;
- }
+ return;
+ }
/*
* Type Perspective
- */
+ */
else if (Map->proj_type == TYPE_PERSPECT)
{
float umid, vmid;
/*----------------------------------------------------------------------*/
-//call_func_redraw_all_structs_proc
-void OpenGl_View::Render (const Handle(OpenGl_Workspace) &AWorkspace,
- const Graphic3d_CView& ACView,
- const Aspect_CLayer2d& ACUnderLayer,
- const Aspect_CLayer2d& ACOverLayer)
+void OpenGl_View::DrawBackground (const Handle(OpenGl_Workspace) &AWorkspace)
{
- // Reset FLIST status after modification of myBackfacing
- if (myResetFLIST)
- {
- AWorkspace->NamedStatus &= ~OPENGL_NS_FLIST;
- myResetFLIST = Standard_False;
- }
-
- // Store and disable current clipping planes
- GLint maxplanes;
- glGetIntegerv(GL_MAX_CLIP_PLANES, &maxplanes);
- const GLenum lastid = GL_CLIP_PLANE0 + maxplanes;
- OPENGL_CLIP_PLANE *oldPlanes = new OPENGL_CLIP_PLANE[maxplanes];
- OPENGL_CLIP_PLANE *ptrPlane = oldPlanes;
- GLenum planeid = GL_CLIP_PLANE0;
- for ( ; planeid < lastid; planeid++, ptrPlane++ )
- {
- glGetClipPlane( planeid, ptrPlane->Equation );
- if ( ptrPlane->isEnabled )
- {
- glDisable( planeid );
- ptrPlane->isEnabled = GL_TRUE;
- }
- else
- ptrPlane->isEnabled = GL_FALSE;
- }
-
/////////////////////////////////////////////////////////////////////////////
// Step 1: Prepare for redraw
// Render background
if ( (AWorkspace->NamedStatus & OPENGL_NS_WHITEBACK) == 0 &&
- ( myBgTexture.TexId != 0 || myBgGradient.type != Aspect_GFM_NONE ) )
+ ( myBgTexture.TexId != 0 || myBgGradient.type != Aspect_GFM_NONE ) )
{
const Standard_Integer aViewWidth = AWorkspace->Width();
const Standard_Integer aViewHeight = AWorkspace->Height();
// - gradient fill type is not Aspect_GFM_NONE and
// - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode
if ( ( myBgGradient.type != Aspect_GFM_NONE ) &&
- ( myBgTexture.TexId == 0 || myBgTexture.Style == Aspect_FM_CENTERED ||
- myBgTexture.Style == Aspect_FM_NONE ) )
+ ( myBgTexture.TexId == 0 || myBgTexture.Style == Aspect_FM_CENTERED ||
+ myBgTexture.Style == Aspect_FM_NONE ) )
{
Tfloat* corner1 = 0;/* -1,-1*/
Tfloat* corner2 = 0;/* 1,-1*/
switch( myBgGradient.type )
{
- case Aspect_GFM_HOR:
- corner1 = myBgGradient.color1.rgb;
- corner2 = myBgGradient.color2.rgb;
- corner3 = myBgGradient.color2.rgb;
- corner4 = myBgGradient.color1.rgb;
- break;
- case Aspect_GFM_VER:
- corner1 = myBgGradient.color2.rgb;
- corner2 = myBgGradient.color2.rgb;
- corner3 = myBgGradient.color1.rgb;
- corner4 = myBgGradient.color1.rgb;
- break;
- case Aspect_GFM_DIAG1:
- corner2 = myBgGradient.color2.rgb;
- corner4 = myBgGradient.color1.rgb;
- dcorner1 [0] = dcorner2[0] = 0.5F * (corner2[0] + corner4[0]);
- dcorner1 [1] = dcorner2[1] = 0.5F * (corner2[1] + corner4[1]);
- dcorner1 [2] = dcorner2[2] = 0.5F * (corner2[2] + corner4[2]);
- corner1 = dcorner1;
- corner3 = dcorner2;
- break;
- case Aspect_GFM_DIAG2:
- corner1 = myBgGradient.color2.rgb;
- corner3 = myBgGradient.color1.rgb;
- dcorner1 [0] = dcorner2[0] = 0.5F * (corner1[0] + corner3[0]);
- dcorner1 [1] = dcorner2[1] = 0.5F * (corner1[1] + corner3[1]);
- dcorner1 [2] = dcorner2[2] = 0.5F * (corner1[2] + corner3[2]);
- corner2 = dcorner1;
- corner4 = dcorner2;
- break;
- case Aspect_GFM_CORNER1:
- corner1 = myBgGradient.color2.rgb;
- corner2 = myBgGradient.color2.rgb;
- corner3 = myBgGradient.color2.rgb;
- corner4 = myBgGradient.color1.rgb;
- break;
- case Aspect_GFM_CORNER2:
- corner1 = myBgGradient.color2.rgb;
- corner2 = myBgGradient.color2.rgb;
- corner3 = myBgGradient.color1.rgb;
- corner4 = myBgGradient.color2.rgb;
- break;
- case Aspect_GFM_CORNER3:
- corner1 = myBgGradient.color2.rgb;
- corner2 = myBgGradient.color1.rgb;
- corner3 = myBgGradient.color2.rgb;
- corner4 = myBgGradient.color2.rgb;
- break;
- case Aspect_GFM_CORNER4:
- corner1 = myBgGradient.color1.rgb;
- corner2 = myBgGradient.color2.rgb;
- corner3 = myBgGradient.color2.rgb;
- corner4 = myBgGradient.color2.rgb;
- break;
- default:
- //printf("gradient background type not right\n");
- break;
+ case Aspect_GFM_HOR:
+ corner1 = myBgGradient.color1.rgb;
+ corner2 = myBgGradient.color2.rgb;
+ corner3 = myBgGradient.color2.rgb;
+ corner4 = myBgGradient.color1.rgb;
+ break;
+ case Aspect_GFM_VER:
+ corner1 = myBgGradient.color2.rgb;
+ corner2 = myBgGradient.color2.rgb;
+ corner3 = myBgGradient.color1.rgb;
+ corner4 = myBgGradient.color1.rgb;
+ break;
+ case Aspect_GFM_DIAG1:
+ corner2 = myBgGradient.color2.rgb;
+ corner4 = myBgGradient.color1.rgb;
+ dcorner1 [0] = dcorner2[0] = 0.5F * (corner2[0] + corner4[0]);
+ dcorner1 [1] = dcorner2[1] = 0.5F * (corner2[1] + corner4[1]);
+ dcorner1 [2] = dcorner2[2] = 0.5F * (corner2[2] + corner4[2]);
+ corner1 = dcorner1;
+ corner3 = dcorner2;
+ break;
+ case Aspect_GFM_DIAG2:
+ corner1 = myBgGradient.color2.rgb;
+ corner3 = myBgGradient.color1.rgb;
+ dcorner1 [0] = dcorner2[0] = 0.5F * (corner1[0] + corner3[0]);
+ dcorner1 [1] = dcorner2[1] = 0.5F * (corner1[1] + corner3[1]);
+ dcorner1 [2] = dcorner2[2] = 0.5F * (corner1[2] + corner3[2]);
+ corner2 = dcorner1;
+ corner4 = dcorner2;
+ break;
+ case Aspect_GFM_CORNER1:
+ corner1 = myBgGradient.color2.rgb;
+ corner2 = myBgGradient.color2.rgb;
+ corner3 = myBgGradient.color2.rgb;
+ corner4 = myBgGradient.color1.rgb;
+ break;
+ case Aspect_GFM_CORNER2:
+ corner1 = myBgGradient.color2.rgb;
+ corner2 = myBgGradient.color2.rgb;
+ corner3 = myBgGradient.color1.rgb;
+ corner4 = myBgGradient.color2.rgb;
+ break;
+ case Aspect_GFM_CORNER3:
+ corner1 = myBgGradient.color2.rgb;
+ corner2 = myBgGradient.color1.rgb;
+ corner3 = myBgGradient.color2.rgb;
+ corner4 = myBgGradient.color2.rgb;
+ break;
+ case Aspect_GFM_CORNER4:
+ corner1 = myBgGradient.color1.rgb;
+ corner2 = myBgGradient.color2.rgb;
+ corner3 = myBgGradient.color2.rgb;
+ corner4 = myBgGradient.color2.rgb;
+ break;
+ default:
+ //printf("gradient background type not right\n");
+ break;
}
// Save GL parameters
glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.);
glColor3f(corner3[0],corner3[1],corner3[2]); glVertex2f( 1., 1.);
glColor3f(corner4[0],corner4[1],corner4[2]); glVertex2f(-1., 1.);
- }
+ }
else //if ( myBgGradient.type == Aspect_GFM_CORNER1 || myBgGradient.type == Aspect_GFM_CORNER3 )
{
glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.);
GLfloat texX_range = 1.F; // texture <s> coordinate
GLfloat texY_range = 1.F; // texture <t> coordinate
- // Set up for stretching or tiling
+ // Set up for stretching or tiling
GLfloat x_offset, y_offset;
if ( myBgTexture.Style == Aspect_FM_CENTERED )
{
}
}
+ // OCCT issue 0023000: Improve the way the gradient and textured
+ // background is managed in 3d viewer (note 0020339)
+ // Setting this coefficient to -1.F allows to tile textures relatively
+ // to the top-left corner of the view (value 1.F corresponds to the
+ // initial behaviour - tiling from the bottom-left corner)
+ GLfloat aCoef = -1.F;
+
glEnable( GL_TEXTURE_2D ); //push GL_ENABLE_BIT
glBindTexture( GL_TEXTURE_2D, myBgTexture.TexId ); //push GL_TEXTURE_BIT
glColor3fv( AWorkspace->BackgroundColor().rgb );
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); //push GL_TEXTURE_BIT
+ // Note that texture is mapped using GL_REPEAT wrapping mode so integer part
+ // is simply ignored, and negative multiplier is here for convenience only
+ // and does not result e.g. in texture mirroring
glBegin( GL_QUADS );
- glTexCoord2f(0.F, 0.F); glVertex2f( -x_offset, -y_offset );
- glTexCoord2f(texX_range, 0.F); glVertex2f( x_offset, -y_offset );
- glTexCoord2f(texX_range, texY_range); glVertex2f( x_offset, y_offset );
- glTexCoord2f(0.F, texY_range); glVertex2f( -x_offset, y_offset );
+ glTexCoord2f(0.F, 0.F); glVertex2f( -x_offset, -aCoef * y_offset );
+ glTexCoord2f(texX_range, 0.F); glVertex2f( x_offset, -aCoef * y_offset );
+ glTexCoord2f(texX_range, aCoef * texY_range); glVertex2f( x_offset, aCoef * y_offset );
+ glTexCoord2f(0.F, aCoef * texY_range); glVertex2f( -x_offset, aCoef * y_offset );
glEnd();
}
else
glDisable (GL_DITHER);
}
+}
+
+/*----------------------------------------------------------------------*/
+
+//call_func_redraw_all_structs_proc
+void OpenGl_View::Render (const Handle(OpenGl_PrinterContext)& thePrintContext,
+ const Handle(OpenGl_Workspace) &AWorkspace,
+ const Graphic3d_CView& ACView,
+ const Aspect_CLayer2d& ACUnderLayer,
+ const Aspect_CLayer2d& ACOverLayer)
+{
+ // Store and disable current clipping planes
+ const Handle(OpenGl_Context)& aContext = AWorkspace->GetGlContext();
+ const Standard_Integer aMaxClipPlanes = aContext->MaxClipPlanes();
+ const GLenum lastid = GL_CLIP_PLANE0 + aMaxClipPlanes;
+ OPENGL_CLIP_PLANE *oldPlanes = new OPENGL_CLIP_PLANE[aMaxClipPlanes];
+ OPENGL_CLIP_PLANE *ptrPlane = oldPlanes;
+ GLenum planeid = GL_CLIP_PLANE0;
+ for ( ; planeid < lastid; planeid++, ptrPlane++ )
+ {
+ glGetClipPlane( planeid, ptrPlane->Equation );
+ if ( ptrPlane->isEnabled )
+ {
+ glDisable( planeid );
+ ptrPlane->isEnabled = GL_TRUE;
+ }
+ else
+ {
+ ptrPlane->isEnabled = GL_FALSE;
+ }
+ }
+
+ // Set OCCT state uniform variables
+ const Handle(OpenGl_ShaderManager) aManager = aContext->ShaderManager();
+ if (StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index()) != myLastLightSourceState)
+ {
+ aManager->UpdateLightSourceStateTo (&myLights);
+ myLastLightSourceState = StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index());
+ }
+ if (StateInfo (myCurrViewMappingState, aManager->ProjectionState().Index()) != myLastViewMappingState)
+ {
+ aManager->UpdateProjectionStateTo (myMappingMatrix);
+ myLastViewMappingState = StateInfo (myCurrViewMappingState, aManager->ProjectionState().Index());
+ }
+ if (StateInfo (myCurrOrientationState, aManager->WorldViewState().Index()) != myLastOrientationState)
+ {
+ aManager->UpdateWorldViewStateTo (myOrientationMatrix);
+ myLastOrientationState = StateInfo (myCurrOrientationState, aManager->WorldViewState().Index());
+ }
+ if (aManager->ModelWorldState().Index() == 0)
+ {
+ Tmatrix3 aModelWorldState = { { 1.f, 0.f, 0.f, 0.f },
+ { 0.f, 1.f, 0.f, 0.f },
+ { 0.f, 0.f, 1.f, 0.f },
+ { 0.f, 0.f, 0.f, 1.f } };
+
+ aManager->UpdateModelWorldStateTo (aModelWorldState);
+ }
+
+ /////////////////////////////////////////////////////////////////////////////
+ // Step 1: Prepare for redraw
+
+ // Render background
+ DrawBackground (AWorkspace);
// Switch off lighting by default
glDisable(GL_LIGHTING);
/////////////////////////////////////////////////////////////////////////////
// Step 2: Draw underlayer
- RedrawLayer2d(AWorkspace, ACView, ACUnderLayer);
+ RedrawLayer2d (thePrintContext, ACView, ACUnderLayer);
/////////////////////////////////////////////////////////////////////////////
// Step 3: Redraw main plane
//TsmPushAttri(); /* save previous graphics context */
// if the view is scaled normal vectors are scaled to unit length for correct displaying of shaded objects
- if(myExtra.scaleFactors[0] != 1.F ||
+ if(myExtra.scaleFactors[0] != 1.F ||
myExtra.scaleFactors[1] != 1.F ||
myExtra.scaleFactors[2] != 1.F)
glEnable(GL_NORMALIZE);
- else if(glIsEnabled(GL_NORMALIZE))
+ else if(glIsEnabled(GL_NORMALIZE))
glDisable(GL_NORMALIZE);
// Apply View Projection
glMatrixMode( GL_PROJECTION );
-#ifdef WNT
+#ifdef _WIN32
// add printing scale/tiling transformation
- OpenGl_PrinterContext* aPrinterContext = OpenGl_PrinterContext::GetPrinterContext(AWorkspace->GetGContext());
-
- if (aPrinterContext)
+ if (!thePrintContext.IsNull())
{
- GLfloat aProjMatrix[16];
- aPrinterContext->GetProjTransformation(aProjMatrix);
- glLoadMatrixf((GLfloat*) aProjMatrix);
+ thePrintContext->LoadProjTransformation();
}
else
#endif
*/
- glPushAttrib( GL_FOG_BIT | GL_LIGHTING_BIT | GL_ENABLE_BIT );
-
// Apply Fog
if ( myFog.IsOn )
{
// Apply Lights
{
- int i;
+ // setup lights
+ Graphic3d_Vec4 anAmbientColor (THE_DEFAULT_AMBIENT[0],
+ THE_DEFAULT_AMBIENT[1],
+ THE_DEFAULT_AMBIENT[2],
+ THE_DEFAULT_AMBIENT[3]);
+ GLenum aLightGlId = GL_LIGHT0;
+ for (OpenGl_ListOfLight::Iterator aLightIt (myLights);
+ aLightIt.More(); aLightIt.Next())
+ {
+ bind_light (aLightIt.Value(), aLightGlId, anAmbientColor);
+ }
- // Switch off all lights
- for (i = GL_LIGHT0; i <= GL_LIGHT7; i++)
- glDisable(i);
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, default_amb);
+ // apply accumulated ambient color
+ anAmbientColor.a() = 1.0f;
+ glLightModelfv (GL_LIGHT_MODEL_AMBIENT, anAmbientColor.GetData());
- /* set les lights */
- int gl_lid = GL_LIGHT0;
- OpenGl_ListOfLight::Iterator itl(myLights);
- for (; itl.More(); itl.Next())
+ if (aLightGlId != GL_LIGHT0)
{
- const OpenGl_Light &alight = itl.Value();
- bind_light(&alight, &gl_lid);
+ glEnable (GL_LIGHTING);
+ }
+ // switch off unused lights
+ for (; aLightGlId <= GL_LIGHT7; ++aLightGlId)
+ {
+ glDisable (aLightGlId);
}
-
- if (gl_lid != GL_LIGHT0) glEnable(GL_LIGHTING);
}
// Apply InteriorShadingMethod
// Apply clipping planes
{
- // Define starting plane id
- planeid = GL_CLIP_PLANE0;
-
- GLdouble equation[4];
-
- if ( myZClip.Back.IsOn || myZClip.Front.IsOn )
+ if (myZClip.Back.IsOn || myZClip.Front.IsOn)
{
- // Apply front and back clipping planes
- GLfloat mat[4][4];
- glMatrixMode( GL_MODELVIEW );
- glGetFloatv( GL_MODELVIEW_MATRIX,(GLfloat *) mat );
- glLoadIdentity();
-
const GLdouble ramp = myExtra.map.fpd - myExtra.map.bpd;
- if ( myZClip.Back.IsOn )
+ Handle(Graphic3d_ClipPlane) aPlaneBack;
+ Handle(Graphic3d_ClipPlane) aPlaneFront;
+
+ if (myZClip.Back.IsOn)
{
const GLdouble back = ramp * myZClip.Back.Limit + myExtra.map.bpd;
- equation[0] = 0.0; /* Nx */
- equation[1] = 0.0; /* Ny */
- equation[2] = 1.0; /* Nz */
- equation[3] = -back; /* P dot N */
- glClipPlane( planeid, equation );
- glEnable( planeid );
- planeid++;
+ const Graphic3d_ClipPlane::Equation aBackEquation (0.0, 0.0, 1.0, -back);
+ aPlaneBack = new Graphic3d_ClipPlane (aBackEquation);
}
- if ( myZClip.Front.IsOn )
+ if (myZClip.Front.IsOn)
{
const GLdouble front = ramp * myZClip.Front.Limit + myExtra.map.bpd;
- equation[0] = 0.0; /* Nx */
- equation[1] = 0.0; /* Ny */
- equation[2] = -1.0; /* Nz */
- equation[3] = front; /* P dot N */
- glClipPlane( planeid, equation );
- glEnable( planeid );
- planeid++;
+ const Graphic3d_ClipPlane::Equation aFrontEquation (0.0, 0.0, -1.0, front);
+ aPlaneFront = new Graphic3d_ClipPlane (aFrontEquation);
}
- glLoadMatrixf( (GLfloat *) mat );
+ // do some "memory allocation"-wise optimization
+ if (!aPlaneBack.IsNull() || !aPlaneFront.IsNull())
+ {
+ Graphic3d_SetOfHClipPlane aSlicingPlanes;
+ if (!aPlaneBack.IsNull())
+ {
+ aSlicingPlanes.Add (aPlaneBack);
+ }
+
+ if (!aPlaneFront.IsNull())
+ {
+ aSlicingPlanes.Add (aPlaneFront);
+ }
+
+ // add planes at loaded view matrix state
+ aContext->ChangeClipping().AddView (aSlicingPlanes, AWorkspace);
+ }
}
// Apply user clipping planes
- NCollection_List<OPENGL_CLIP_REP>::Iterator planeIter(myClippingPlanes);
- for ( ; planeIter.More(); planeIter.Next() )
+ if (!myClipPlanes.IsEmpty())
{
- glClipPlane( planeid, planeIter.Value().equation );
- glEnable( planeid );
- planeid++;
+ Graphic3d_SetOfHClipPlane aUserPlanes;
+ Graphic3d_SetOfHClipPlane::Iterator aClippingIt (myClipPlanes);
+ for (; aClippingIt.More(); aClippingIt.Next())
+ {
+ const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value();
+ if (aClipPlane->IsOn())
+ {
+ aUserPlanes.Add (aClipPlane);
+ }
+ }
+
+ if (!aUserPlanes.IsEmpty())
+ {
+ // add planes at actual matrix state.
+ aContext->ChangeClipping().AddWorld (aUserPlanes);
+ }
+ }
+
+ if (!aManager->IsEmpty())
+ {
+ aManager->UpdateClippingState();
}
}
AWorkspace->NamedStatus &= ~OPENGL_NS_ANTIALIASING;
}
- Standard_Boolean isAnimationListOpen = Standard_False;
+ // Clear status bitfields
+ AWorkspace->NamedStatus &= ~(OPENGL_NS_2NDPASSNEED | OPENGL_NS_2NDPASSDO);
- // Request for update of animation mode?
- if ( (AWorkspace->NamedStatus & OPENGL_NS_UPDATEAM) != 0 )
+ // Added PCT for handling of textures
+ switch (mySurfaceDetail)
{
- // Request to rebuild display list
- myAnimationListReady = Standard_False;
- // Reset request for update of animation mode
- AWorkspace->NamedStatus &= ~OPENGL_NS_UPDATEAM;
- }
-
- // Is in animation mode?
- if ( AWorkspace->NamedStatus & OPENGL_NS_ANIMATION )
- {
- // Is the animation list ready?
- if (myAnimationListReady)
- {
- // Execute the animation list
- glCallList(myAnimationListIndex);
- }
- else
- {
- // Update the animation list
- if ( AWorkspace->NamedStatus & OPENGL_NS_FLIST )
+ case Visual3d_TOD_NONE:
+ AWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
+ AWorkspace->DisableTexture();
+ // Render the view
+ RenderStructs(AWorkspace);
+ break;
+
+ case Visual3d_TOD_ENVIRONMENT:
+ AWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
+ AWorkspace->EnableTexture (myTextureEnv);
+ // Render the view
+ RenderStructs(AWorkspace);
+ AWorkspace->DisableTexture();
+ break;
+
+ case Visual3d_TOD_ALL:
+ // First pass
+ AWorkspace->NamedStatus &= ~OPENGL_NS_FORBIDSETTEX;
+ // Render the view
+ RenderStructs(AWorkspace);
+ AWorkspace->DisableTexture();
+
+ // Second pass
+ if (AWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED)
{
- if (myAnimationListIndex == 0)
- myAnimationListIndex = glGenLists(1);
-
- if (myAnimationListIndex != 0)
- {
- glNewList(myAnimationListIndex, GL_COMPILE_AND_EXECUTE);
- isAnimationListOpen = Standard_True;
- }
- }
- else
- AWorkspace->NamedStatus |= OPENGL_NS_FLIST;
- }
- }
- else
- myAnimationListReady = Standard_False;
-
- if (!myAnimationListReady)
- {
- // Clear status bitfields
- AWorkspace->NamedStatus &= ~(OPENGL_NS_2NDPASSNEED | OPENGL_NS_2NDPASSDO);
-
- // Added PCT for handling of textures
- switch (mySurfaceDetail)
- {
- case Visual3d_TOD_NONE:
- AWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
- DisableTexture();
- // Render the view
- RenderStructs(AWorkspace);
- break;
+ AWorkspace->NamedStatus |= OPENGL_NS_2NDPASSDO;
+ AWorkspace->EnableTexture (myTextureEnv);
+
+ /* sauvegarde de quelques parametres OpenGL */
+ GLint blend_dst, blend_src;
+ GLint zbuff_f;
+ GLboolean zbuff_w;
+ glGetBooleanv(GL_DEPTH_WRITEMASK, &zbuff_w);
+ glGetIntegerv(GL_DEPTH_FUNC, &zbuff_f);
+ glGetIntegerv(GL_BLEND_DST, &blend_dst);
+ glGetIntegerv(GL_BLEND_SRC, &blend_src);
+ GLboolean zbuff_state = glIsEnabled(GL_DEPTH_TEST);
+ GLboolean blend_state = glIsEnabled(GL_BLEND);
+
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ glDepthFunc(GL_EQUAL);
+ glDepthMask(GL_FALSE);
+ glEnable(GL_DEPTH_TEST);
- case Visual3d_TOD_ENVIRONMENT:
AWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
- SetCurrentTexture(myTextureEnv);
- EnableTexture();
- // Render the view
- RenderStructs(AWorkspace);
- DisableTexture();
- break;
- case Visual3d_TOD_ALL:
- // First pass
- AWorkspace->NamedStatus &= ~OPENGL_NS_FORBIDSETTEX;
// Render the view
RenderStructs(AWorkspace);
- DisableTexture();
+ AWorkspace->DisableTexture();
- // Second pass
- if (AWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED)
- {
- AWorkspace->NamedStatus |= OPENGL_NS_2NDPASSDO;
- SetCurrentTexture(myTextureEnv);
- EnableTexture();
-
- /* sauvegarde de quelques parametres OpenGL */
- GLint blend_dst, blend_src;
- GLint zbuff_f;
- GLboolean zbuff_w;
- glGetBooleanv(GL_DEPTH_WRITEMASK, &zbuff_w);
- glGetIntegerv(GL_DEPTH_FUNC, &zbuff_f);
- glGetIntegerv(GL_BLEND_DST, &blend_dst);
- glGetIntegerv(GL_BLEND_SRC, &blend_src);
- GLboolean zbuff_state = glIsEnabled(GL_DEPTH_TEST);
- GLboolean blend_state = glIsEnabled(GL_BLEND);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
-
- glDepthFunc(GL_EQUAL);
- glDepthMask(GL_FALSE);
- glEnable(GL_DEPTH_TEST);
-
- AWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX;
-
- // Render the view
- RenderStructs(AWorkspace);
- DisableTexture();
-
- /* restauration des parametres OpenGL */
- glBlendFunc(blend_src, blend_dst);
- if (!blend_state) glDisable(GL_BLEND);
-
- glDepthFunc(zbuff_f);
- glDepthMask(zbuff_w);
- if (!zbuff_state) glDisable(GL_DEPTH_FUNC);
- }
- break;
- }
+ /* restauration des parametres OpenGL */
+ glBlendFunc(blend_src, blend_dst);
+ if (!blend_state) glDisable(GL_BLEND);
- if (isAnimationListOpen)
- {
- glEndList();
- myAnimationListReady = Standard_True;
- }
+ glDepthFunc(zbuff_f);
+ glDepthMask(zbuff_w);
+ if (!zbuff_state) glDisable(GL_DEPTH_FUNC);
+ }
+ break;
}
- /* restore previous graphics context; before update lights */
- //TsmPopAttri();
+ // Resetting GL parameters according to the default aspects
+ // in order to synchronize GL state with the graphic driver state
+ // before drawing auxiliary stuff (trihedrons, overlayer)
+ // and invoking optional callbacks
+ AWorkspace->ResetAppliedAspect();
+
+ aContext->ChangeClipping().RemoveAll();
- // Disable current clipping planes
- for ( planeid = GL_CLIP_PLANE0; planeid < lastid; planeid++ )
- glDisable( planeid );
+ if (!aManager->IsEmpty())
+ {
+ aManager->ResetMaterialStates();
+ aManager->RevertClippingState();
- /* affichage de Triedre Non Zoomable de la vue s'il existe */
- if (!myTrihedron.IsNull())
- myTrihedron->Render(AWorkspace);
- if (!myGraduatedTrihedron.IsNull())
- myGraduatedTrihedron->Render(AWorkspace);
+ // We need to disable (unbind) all shaders programs to ensure
+ // that all objects without specified aspect will be drawn
+ // correctly (such as background)
+ OpenGl_ShaderProgram::Unbind (aContext);
+ }
- glPopAttrib(); // GL_FOG_BIT | GL_LIGHTING_BIT | GL_ENABLE_BIT
+ // display global trihedron
+ if (myTrihedron != NULL)
+ {
+ myTrihedron->Render (AWorkspace);
+ }
+ if (myGraduatedTrihedron != NULL)
+ {
+ myGraduatedTrihedron->Render (AWorkspace);
+ }
// Restore face culling
if ( myBackfacing )
const int aMode = 0;
AWorkspace->DisplayCallback (ACView, (aMode | OCC_PRE_OVERLAY));
- RedrawLayer2d(AWorkspace, ACView, ACOverLayer);
+ RedrawLayer2d (thePrintContext, ACView, ACOverLayer);
AWorkspace->DisplayCallback (ACView, aMode);
//ExecuteViewDisplay
void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace) &AWorkspace)
{
- if ( myStructures.NbStructures() <= 0 ) return;
+ if ( myZLayers.NbStructures() <= 0 )
+ return;
glPushAttrib ( GL_DEPTH_BUFFER_BIT );
- const OpenGl_AspectLine *aspect_line = AWorkspace->AspectLine( Standard_True );
-
//TsmPushAttri(); /* save previous graphics context */
if ( (AWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) == 0 )
glEnable(GL_POINT_SMOOTH);
glEnable(GL_LINE_SMOOTH);
if( antiAliasingMode & 2 ) glEnable(GL_POLYGON_SMOOTH);
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable (GL_BLEND);
}
}
- myStructures.Render(AWorkspace);
+ myZLayers.Render (AWorkspace);
//TsmPopAttri(); /* restore previous graphics context; before update lights */
-
- if ( AWorkspace->DegenerateModel > 1 )
- {
- glLineWidth ( aspect_line->Width() );
- if ( aspect_line->Type() != Aspect_TOL_SOLID ) glEnable ( GL_LINE_STIPPLE );
- }
-
- glPopAttrib ();
+ glPopAttrib();
}
/*----------------------------------------------------------------------*/
//call_togl_redraw_layer2d
-void OpenGl_View::RedrawLayer2d (const Handle(OpenGl_Workspace) &AWorkspace, const Graphic3d_CView& ACView, const Aspect_CLayer2d& ACLayer)
+void OpenGl_View::RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintContext,
+ const Graphic3d_CView& ACView,
+ const Aspect_CLayer2d& ACLayer)
{
if (&ACLayer == NULL
|| ACLayer.ptrLayer == NULL
GLsizei dispWidth = (GLsizei )ACLayer.viewport[0];
GLsizei dispHeight = (GLsizei )ACLayer.viewport[1];
- const GLboolean isl = glIsEnabled(GL_LIGHTING); /*OCC6247*/
- if (isl)
- glDisable(GL_LIGHTING); /*OCC6247*/
-
- /*
- * On positionne la projection
- */
glMatrixMode( GL_MODELVIEW );
glPushMatrix ();
glLoadIdentity ();
ratio = ACView.DefWindow.dx/ACView.DefWindow.dy;
float delta;
- if (ratio >= 1.0) { /* fenetre horizontale */
+ if (ratio >= 1.0) {
delta = (float )((top - bottom)/2.0);
switch (attach) {
case 0: /* Aspect_TOC_BOTTOM_LEFT */
break;
}
}
- else { /* fenetre verticale */
+ else {
delta = (float )((right - left)/2.0);
switch (attach) {
case 0: /* Aspect_TOC_BOTTOM_LEFT */
}
}
-#ifdef WNT
+#ifdef _WIN32
// Check printer context that exists only for print operation
- OpenGl_PrinterContext* aPrinterContext = OpenGl_PrinterContext::GetPrinterContext (AWorkspace->GetGContext());
-
- if (aPrinterContext)
+ if (!thePrintContext.IsNull())
{
// additional transformation matrix could be applied to
// render only those parts of viewport that will be
// tiling; scaling of graphics by matrix helps render a
// part of a view (frame) in same viewport, but with higher
// resolution
- GLfloat aProjMatrix[16];
- aPrinterContext->GetProjTransformation (aProjMatrix);
- glLoadMatrixf ((GLfloat*) aProjMatrix);
+ thePrintContext->LoadProjTransformation();
// printing operation also assumes other viewport dimension
// to comply with transformation matrix or graphics scaling
// factors for tiling for layer redraw
GLsizei anViewportX = 0;
GLsizei anViewportY = 0;
- aPrinterContext->GetLayerViewport (anViewportX, anViewportY);
+ thePrintContext->GetLayerViewport (anViewportX, anViewportY);
if (anViewportX != 0 && anViewportY != 0)
glViewport (0, 0, anViewportX, anViewportY);
}
-#endif
+#endif
glOrtho (left, right, bottom, top, -1.0, 1.0);
- /*
- * On trace la display-list associee au layer.
- */
glPushAttrib (
GL_LIGHTING_BIT | GL_LINE_BIT | GL_POLYGON_BIT |
GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT | GL_TEXTURE_BIT );
+
glDisable (GL_DEPTH_TEST);
+ glDisable (GL_TEXTURE_1D);
+ glDisable (GL_TEXTURE_2D);
+ glDisable (GL_LIGHTING);
+
+ // TODO: Obsolete code, the display list is always empty now, to be removed
glCallList (ACLayer.ptrLayer->listIndex);
//calling dynamic render of LayerItems
if ( ACLayer.ptrLayer->layerData )
{
- InitLayerProp(ACLayer.ptrLayer->listIndex);
+ InitLayerProp (ACLayer.ptrLayer->listIndex);
((Visual3d_Layer*)ACLayer.ptrLayer->layerData)->RenderLayerItems();
- InitLayerProp(0);
+ InitLayerProp (0);
}
glPopAttrib ();
- /*
- * On retire la projection
- */
glMatrixMode (GL_PROJECTION);
glPopMatrix ();
glMatrixMode( GL_MODELVIEW );
glPopMatrix ();
- /*
- * Restauration du Viewport en cas de modification
- */
if (!ACLayer.sizeDependent)
glViewport (0, 0, (GLsizei) ACView.DefWindow.dx, (GLsizei) ACView.DefWindow.dy);
glFlush ();
-
- if (isl)
- glEnable(GL_LIGHTING); /*OCC6247*/
}
/*----------------------------------------------------------------------*/
//call_togl_create_bg_texture
-void OpenGl_View::CreateBackgroundTexture (const Standard_CString AFileName, const Aspect_FillMethod AFillStyle)
+void OpenGl_View::CreateBackgroundTexture (const Standard_CString theFilePath,
+ const Aspect_FillMethod theFillStyle)
{
- // Delete existing texture
- if ( myBgTexture.TexId != 0 )
+ if (myBgTexture.TexId != 0)
{
- glDeleteTextures( 1, (GLuint*)&(myBgTexture.TexId) );
+ // delete existing texture
+ glDeleteTextures (1, (GLuint* )&(myBgTexture.TexId));
myBgTexture.TexId = 0;
}
- Standard_Integer width, height;
- Handle(Image_Image) image;
- if ( AlienImage::LoadImageFile( AFileName, image, width, height ) )
+ // load image from file
+ Image_AlienPixMap anImageLoaded;
+ if (!anImageLoaded.Load (theFilePath))
+ {
+ return;
+ }
+
+ Image_PixMap anImage;
+ if (anImageLoaded.RowExtraBytes() == 0 &&
+ (anImageLoaded.Format() == Image_PixMap::ImgRGB
+ || anImageLoaded.Format() == Image_PixMap::ImgRGB32
+ || anImageLoaded.Format() == Image_PixMap::ImgRGBA))
+ {
+ anImage.InitWrapper (anImageLoaded.Format(), anImageLoaded.ChangeData(),
+ anImageLoaded.SizeX(), anImageLoaded.SizeY(), anImageLoaded.SizeRowBytes());
+ }
+ else
{
- const int nbbytes = width * height * 3;
- GLubyte *data = new GLubyte[nbbytes];
- GLubyte *pdata = data;
- Standard_Integer i, j;
- for ( j = height - 1; j >= 0; j-- )
- for ( i = 0; i < width; i++ )
+ // convert image to RGB format
+ if (!anImage.InitTrash (Image_PixMap::ImgRGB, anImageLoaded.SizeX(), anImageLoaded.SizeY()))
+ {
+ return;
+ }
+
+ anImage.SetTopDown (false);
+ Image_PixMapData<Image_ColorRGB>& aDataNew = anImage.EditData<Image_ColorRGB>();
+ Quantity_Color aSrcColor;
+ for (Standard_Size aRow = 0; aRow < anImage.SizeY(); ++aRow)
+ {
+ for (Standard_Size aCol = 0; aCol < anImage.SizeX(); ++aCol)
{
- const Quantity_Color &color = image->PixelColor( i, j );
- *pdata++ = (GLubyte)( 255 * color.Red() );
- *pdata++ = (GLubyte)( 255 * color.Green() );
- *pdata++ = (GLubyte)( 255 * color.Blue() );
+ aSrcColor = anImageLoaded.PixelColor ((Standard_Integer )aCol, (Standard_Integer )aRow);
+ Image_ColorRGB& aColor = aDataNew.ChangeValue (aRow, aCol);
+ aColor.r() = Standard_Byte(255.0 * aSrcColor.Red());
+ aColor.g() = Standard_Byte(255.0 * aSrcColor.Green());
+ aColor.b() = Standard_Byte(255.0 * aSrcColor.Blue());
}
+ }
+ anImageLoaded.Clear();
+ }
- GLuint texture = 0;
- glGenTextures( 1, &texture );
- glBindTexture( GL_TEXTURE_2D, texture );
+ // create MipMapped texture
+ glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
- /* Create MipMapped Texture */
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
+ GLuint aTextureId = 0;
+ glGenTextures (1, &aTextureId);
+ glBindTexture (GL_TEXTURE_2D, aTextureId);
- gluBuild2DMipmaps( GL_TEXTURE_2D, 3/*4*/, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
- delete[] data;
+ const GLenum aDataFormat = (anImage.Format() == Image_PixMap::ImgRGB) ? GL_RGB : GL_RGBA;
+ gluBuild2DMipmaps (GL_TEXTURE_2D, 3/*4*/,
+ GLint(anImage.SizeX()), GLint(anImage.SizeY()),
+ aDataFormat, GL_UNSIGNED_BYTE, anImage.Data());
- myBgTexture.TexId = texture;
- myBgTexture.Width = width;
- myBgTexture.Height = height;
- myBgTexture.Style = AFillStyle;
- }
+ myBgTexture.TexId = aTextureId;
+ myBgTexture.Width = (Standard_Integer )anImage.SizeX();
+ myBgTexture.Height = (Standard_Integer )anImage.SizeY();
+ myBgTexture.Style = theFillStyle;
}
/*----------------------------------------------------------------------*/
myBgGradient.type = AType;
}
-/*----------------------------------------------------------------------*/
+//=======================================================================
+//function : AddZLayer
+//purpose :
+//=======================================================================
+
+void OpenGl_View::AddZLayer (const Standard_Integer theLayerId)
+{
+ myZLayers.AddLayer (theLayerId);
+}
+
+//=======================================================================
+//function : RemoveZLayer
+//purpose :
+//=======================================================================
+
+void OpenGl_View::RemoveZLayer (const Standard_Integer theLayerId)
+{
+ myZLayers.RemoveLayer (theLayerId);
+}
+
+//=======================================================================
+//function : DisplayStructure
+//purpose :
+//=======================================================================
+
+void OpenGl_View::DisplayStructure (const OpenGl_Structure *theStructure,
+ const Standard_Integer thePriority)
+{
+ Standard_Integer aZLayer = theStructure->GetZLayer ();
+ myZLayers.AddStructure (theStructure, aZLayer, thePriority);
+}
+
+//=======================================================================
+//function : EraseStructure
+//purpose :
+//=======================================================================
+
+void OpenGl_View::EraseStructure (const OpenGl_Structure *theStructure)
+{
+ Standard_Integer aZLayer = theStructure->GetZLayer ();
+ myZLayers.RemoveStructure (theStructure, aZLayer);
+}
+
+//=======================================================================
+//function : ChangeZLayer
+//purpose :
+//=======================================================================
+
+void OpenGl_View::ChangeZLayer (const OpenGl_Structure *theStructure,
+ const Standard_Integer theNewLayerId)
+{
+ Standard_Integer anOldLayer = theStructure->GetZLayer ();
+ myZLayers.ChangeLayer (theStructure, anOldLayer, theNewLayerId);
+}