root/OpenSceneGraph/trunk/src/osg/Texture2DMultisample.cpp @ 13041

Revision 13041, 4.5 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12 *
13 * Texture2DMultisample codes Copyright (C) 2010 Marcin Hajder
14 * Thanks to to my company http://www.ai.com.pl for allowing me free this work.
15*/
16
17#include <osg/GLExtensions>
18#include <osg/Texture2DMultisample>
19#include <osg/State>
20#include <osg/Notify>
21
22using namespace osg;
23
24Texture2DMultisample::Texture2DMultisample():
25            _textureWidth(0),
26            _textureHeight(0),
27            _numSamples(1),
28            _fixedsamplelocations(GL_FALSE)
29{
30}
31
32Texture2DMultisample::Texture2DMultisample(GLsizei numSamples, GLboolean fixedsamplelocations):
33            _textureWidth(0),
34            _textureHeight(0),
35            _numSamples(numSamples),
36            _fixedsamplelocations(fixedsamplelocations)
37{
38}
39
40Texture2DMultisample::Texture2DMultisample(const Texture2DMultisample& text,const CopyOp& copyop):
41            Texture(text,copyop),
42            _textureWidth(text._textureWidth),
43            _textureHeight(text._textureHeight),
44            _numSamples(text._numSamples),
45            _fixedsamplelocations(text._fixedsamplelocations)
46{
47}
48
49Texture2DMultisample::~Texture2DMultisample()
50{
51}
52
53int Texture2DMultisample::compare(const StateAttribute& sa) const
54{
55    // check the types are equal and then create the rhs variable
56    // used by the COMPARE_StateAttribute_Parameter macros below.
57    COMPARE_StateAttribute_Types(Texture2DMultisample,sa)
58
59
60    int result = compareTexture(rhs);
61    if (result!=0) return result;
62
63    // compare each parameter in turn against the rhs.
64    if (_textureWidth != 0 && rhs._textureWidth != 0)
65    {
66        COMPARE_StateAttribute_Parameter(_textureWidth)
67    }
68    if (_textureHeight != 0 && rhs._textureHeight != 0)
69    {
70        COMPARE_StateAttribute_Parameter(_textureHeight)
71    }
72    if (_numSamples != 0 && rhs._numSamples != 0)
73    {
74        COMPARE_StateAttribute_Parameter(_numSamples)
75    }
76    if (_fixedsamplelocations != 0 && rhs._fixedsamplelocations != 0)
77    {
78        COMPARE_StateAttribute_Parameter(_fixedsamplelocations)
79    }
80
81
82    return 0; // passed all the above comparison macros, must be equal.
83}
84
85void Texture2DMultisample::apply(State& state) const
86{
87    // current OpenGL context.
88    const unsigned int contextID = state.getContextID();
89    const Extensions* extensions = getExtensions(contextID,true);
90    if (!extensions->isTextureMultisampledSupported())
91    {
92        OSG_INFO<<"Texture2DMultisample not supoorted."<<std::endl;
93        return;
94    }
95
96    Texture::TextureObjectManager* tom = Texture::getTextureObjectManager(contextID).get();
97    ElapsedTime elapsedTime(&(tom->getApplyTime()));
98    tom->getNumberApplied()++;
99
100    // get the texture object for the current contextID.
101    TextureObject* textureObject = getTextureObject(contextID);
102
103    if (textureObject)
104    {
105        textureObject->bind();
106    }
107    else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_numSamples!=0) )
108    {
109        _textureObjectBuffer[contextID] = textureObject =
110          generateTextureObject( this,
111                                 contextID,
112                                 getTextureTarget(),
113                                 1,
114                                 _internalFormat,
115                                 _textureWidth,
116                                 _textureHeight,
117                                 1,
118                                 _borderWidth);
119
120        textureObject->bind();
121
122        extensions->glTexImage2DMultisample( getTextureTarget(),
123                                             _numSamples,
124                                             _internalFormat,
125                                             _textureWidth,
126                                             _textureHeight,
127                                             _fixedsamplelocations );
128
129    }
130    else
131    {
132        glBindTexture( getTextureTarget(), 0 );
133    }
134}
135
136void Texture2DMultisample::computeInternalFormat() const
137{
138    computeInternalFormatType();
139}
Note: See TracBrowser for help on using the browser.