0023544: Texture management in TKOpenGl should be redesigned
[occt.git] / src / OpenGl / OpenGl_MarkerSet.cxx
CommitLineData
b311480e 1// Created on: 2011-07-13
2// Created by: Sergey ZERCHANINOV
3// Copyright (c) 2011-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
5f8b738e 20#include <OpenGl_GlCore11.hxx>
664cae74 21#include <OpenGl_Context.hxx>
2166f0fa 22
5f8b738e 23#include <OpenGl_MarkerSet.hxx>
2166f0fa
SK
24
25#include <OpenGl_AspectMarker.hxx>
26#include <OpenGl_Structure.hxx>
27#include <OpenGl_Display.hxx>
bf75be98 28#include <OpenGl_Workspace.hxx>
2166f0fa
SK
29
30/*----------------------------------------------------------------------*/
31
32OpenGl_MarkerSet::OpenGl_MarkerSet (const Standard_Integer ANbPoints, const Graphic3d_Vertex *APoints)
33: myNbPoints(ANbPoints),
34 myPoints(new TEL_POINT[ANbPoints])
35{
36 memcpy( myPoints, APoints, ANbPoints*sizeof(TEL_POINT) );
37}
38
39/*----------------------------------------------------------------------*/
40
41OpenGl_MarkerSet::~OpenGl_MarkerSet ()
42{
43 if (myPoints)
44 delete[] myPoints;
45}
46
47/*----------------------------------------------------------------------*/
48
49void OpenGl_MarkerSet::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
50{
51 const OpenGl_AspectMarker *aspect_marker = AWorkspace->AspectMarker( Standard_True );
52
53 // Use highlight colors
54 glColor3fv( (AWorkspace->NamedStatus & OPENGL_NS_HIGHLIGHT)? AWorkspace->HighlightColor->rgb : aspect_marker->Color().rgb );
55
56 const TEL_POINT *ptr;
57 Tint i;
58
59 switch ( aspect_marker->Type() )
60 {
61 case Aspect_TOM_O_POINT :
62 {
63 const char *str = AWorkspace->GetDisplay()->GetStringForMarker( Aspect_TOM_O, aspect_marker->Scale() );
64 AWorkspace->GetDisplay()->SetBaseForMarker();
65 for( i = 0, ptr = myPoints; i < myNbPoints; i++, ptr++ )
66 {
67 glRasterPos3fv( ptr->xyz );
68 glCallLists( strlen( str ), GL_UNSIGNED_BYTE, (const GLubyte *) str );
69 }
70 }
71 case Aspect_TOM_POINT :
72 {
2166f0fa
SK
73 glBegin( GL_POINTS );
74 for( i = 0, ptr = myPoints; i < myNbPoints; i++, ptr++ )
75 glVertex3fv( ptr->xyz );
76 glEnd();
77 break;
78 }
79 default:
80 {
81 switch ( aspect_marker->Type() )
82 {
83 case Aspect_TOM_RING1 :
84 case Aspect_TOM_RING2 :
85 case Aspect_TOM_RING3 :
86 {
87 const float ADelta = 0.1f;
88 float AScale = aspect_marker->Scale();
89 float ALimit = 0.f;
90 if (aspect_marker->Type() == Aspect_TOM_RING1)
91 ALimit = AScale * 0.2f;
92 else if (aspect_marker->Type() == Aspect_TOM_RING2)
93 ALimit = AScale * 0.5f;
94 else
95 ALimit = AScale * 0.8f;
96 AWorkspace->GetDisplay()->SetBaseForMarker();
97 for( i = 0, ptr = myPoints; i < myNbPoints; i++, ptr++ )
98 {
99 glRasterPos3fv( ptr->xyz );
100 AScale = aspect_marker->Scale();
101 while (AScale > ALimit && AScale >= 1.f)
102 {
103 const char *str = AWorkspace->GetDisplay()->GetStringForMarker( Aspect_TOM_O, AScale );
104 glCallLists( strlen( str ), GL_UNSIGNED_BYTE, (const GLubyte *) str );
105 AScale -= ADelta;
106 }
107 }
108 break;
109 }
110 case Aspect_TOM_USERDEFINED :
111 {
112 for( i = 0, ptr = myPoints; i < myNbPoints; i++, ptr++ )
113 {
114 glRasterPos3fv( ptr->xyz );
115 glCallList( openglDisplay->GetUserMarkerListIndex( (int)aspect_marker->Scale() ) );
116 }
117 break;
118 }
119 default :
120 {
121 AWorkspace->GetDisplay()->SetBaseForMarker();
122 const char *str = AWorkspace->GetDisplay()->GetStringForMarker( aspect_marker->Type(), aspect_marker->Scale() );
123 for( i = 0, ptr = myPoints; i < myNbPoints; i++, ptr++ )
124 {
125 glRasterPos3fv( ptr->xyz );
126 glCallLists( strlen( str ), GL_UNSIGNED_BYTE, (const GLubyte *) str );
127 }
128 }
129 }
664cae74 130
131 if (AWorkspace->GetGlContext()->IsFeedback())
2166f0fa
SK
132 {
133 glBegin( GL_POINTS );
134 for( i = 0, ptr = myPoints; i < myNbPoints; i++, ptr++ )
135 glVertex3fv( ptr->xyz );
136 glEnd();
137 }
138 }
139 }
140}
141
5e27df78 142void OpenGl_MarkerSet::Release (const Handle(OpenGl_Context)& theContext)
143{
144 //
145}