0028912: Visualization, TKOpenGl - multi-texture support
[occt.git] / src / OpenGl / OpenGl_PointSprite.cxx
1 // Created by: Kirill GAVRILOV
2 // Copyright (c) 2013-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <OpenGl_PointSprite.hxx>
16
17 #include <Graphic3d_TextureParams.hxx>
18 #include <OpenGl_Context.hxx>
19 #include <OpenGl_Sampler.hxx>
20 #include <Standard_Assert.hxx>
21 #include <Image_PixMap.hxx>
22
23 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_PointSprite,OpenGl_Texture)
24
25 // =======================================================================
26 // function : OpenGl_PointSprite
27 // purpose  :
28 // =======================================================================
29 OpenGl_PointSprite::OpenGl_PointSprite (const TCollection_AsciiString& theResourceId)
30 : OpenGl_Texture (theResourceId, Handle(Graphic3d_TextureParams)()),
31   myBitmapList (0)
32 {
33   //mySampler->Parameters()->SetFilter (Graphic3d_TOTF_NEAREST);
34   mySampler->Parameters()->SetModulate (Standard_False);
35   mySampler->Parameters()->SetGenMode (Graphic3d_TOTM_SPRITE,
36                                        Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f),
37                                        Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f));
38 }
39
40 // =======================================================================
41 // function : ~OpenGl_PointSprite
42 // purpose  :
43 // =======================================================================
44 OpenGl_PointSprite::~OpenGl_PointSprite()
45 {
46   Release (NULL);
47 }
48
49 // =======================================================================
50 // function : Release
51 // purpose  :
52 // =======================================================================
53 void OpenGl_PointSprite::Release (OpenGl_Context* theGlCtx)
54 {
55   if (myBitmapList != 0)
56   {
57     Standard_ASSERT_RETURN (theGlCtx != NULL,
58         "OpenGl_PointSprite destroyed without GL context! Possible GPU memory leakage...",);
59
60     if (theGlCtx->IsValid())
61     {
62     #if !defined(GL_ES_VERSION_2_0)
63       glDeleteLists (myBitmapList, 1);
64     #endif
65     }
66     myBitmapList = 0;
67   }
68
69   OpenGl_Texture::Release (theGlCtx);
70 }
71
72 // =======================================================================
73 // function : SetDisplayList
74 // purpose  :
75 // =======================================================================
76 void OpenGl_PointSprite::SetDisplayList (const Handle(OpenGl_Context)& theCtx,
77                                          const GLuint                  theBitmapList)
78 {
79   Release (theCtx.operator->());
80   myBitmapList = theBitmapList;
81 }
82
83 // =======================================================================
84 // function : DrawBitmap
85 // purpose  :
86 // =======================================================================
87 void OpenGl_PointSprite::DrawBitmap (const Handle(OpenGl_Context)& ) const
88 {
89   if (myBitmapList != 0)
90   {
91   #if !defined(GL_ES_VERSION_2_0)
92     glCallList (myBitmapList);
93   #endif
94   }
95 }