File: Texture2DMultisample.cpp

package info (click to toggle)
openscenegraph 3.6.5%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 39,988 kB
  • sloc: cpp: 392,058; ansic: 21,495; java: 1,020; yacc: 548; makefile: 430; objc: 406; xml: 155; lex: 151; javascript: 34
file content (141 lines) | stat: -rw-r--r-- 5,036 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
 *
 * Texture2DMultisample codes Copyright (C) 2010 Marcin Hajder
 * Thanks to to my company http://www.ai.com.pl for allowing me free this work.
*/

#include <osg/GLExtensions>
#include <osg/Texture2DMultisample>
#include <osg/State>
#include <osg/Notify>

using namespace osg;

Texture2DMultisample::Texture2DMultisample():
            _textureWidth(0),
            _textureHeight(0),
            _numSamples(1),
            _fixedsamplelocations(GL_FALSE)
{
}

Texture2DMultisample::Texture2DMultisample(GLsizei numSamples, GLboolean fixedsamplelocations):
            _textureWidth(0),
            _textureHeight(0),
            _numSamples(numSamples),
            _fixedsamplelocations(fixedsamplelocations)
{
}

Texture2DMultisample::Texture2DMultisample(const Texture2DMultisample& text,const CopyOp& copyop):
            Texture(text,copyop),
            _textureWidth(text._textureWidth),
            _textureHeight(text._textureHeight),
            _numSamples(text._numSamples),
            _fixedsamplelocations(text._fixedsamplelocations)
{
}

Texture2DMultisample::~Texture2DMultisample()
{
}

int Texture2DMultisample::compare(const StateAttribute& sa) const
{
    // check the types are equal and then create the rhs variable
    // used by the COMPARE_StateAttribute_Parameter macros below.
    COMPARE_StateAttribute_Types(Texture2DMultisample,sa)


    int result = compareTexture(rhs);
    if (result!=0) return result;

    // compare each parameter in turn against the rhs.
    if (_textureWidth != 0 && rhs._textureWidth != 0)
    {
        COMPARE_StateAttribute_Parameter(_textureWidth)
    }
    if (_textureHeight != 0 && rhs._textureHeight != 0)
    {
        COMPARE_StateAttribute_Parameter(_textureHeight)
    }
    if (_numSamples != 0 && rhs._numSamples != 0)
    {
        COMPARE_StateAttribute_Parameter(_numSamples)
    }
    if (_fixedsamplelocations != 0 && rhs._fixedsamplelocations != 0)
    {
        COMPARE_StateAttribute_Parameter(_fixedsamplelocations)
    }


    return 0; // passed all the above comparison macros, must be equal.
}

void Texture2DMultisample::apply(State& state) const
{
    // current OpenGL context.
    const unsigned int contextID = state.getContextID();
    const GLExtensions* extensions = state.get<GLExtensions>();
    if (!extensions->isTextureMultisampledSupported)
    {
        OSG_INFO<<"Texture2DMultisample not supported."<<std::endl;
        return;
    }

    // get the texture object for the current contextID.
    TextureObject* textureObject = getTextureObject(contextID);

    if (textureObject)
    {
        textureObject->bind();
    }
    else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_numSamples!=0) )
    {
        // no image present, but dimensions at set so lets create the texture
        GLenum texStorageSizedInternalFormat = extensions->isTextureStorageEnabled && (_borderWidth==0) ? selectSizedInternalFormat() : 0;
        if (texStorageSizedInternalFormat!=0)
        {
            textureObject = generateAndAssignTextureObject(contextID, getTextureTarget(), 1, texStorageSizedInternalFormat, _textureWidth, _textureHeight, 1, 0);
            textureObject->bind();
            if(!textureObject->_allocated)
            {
                extensions->glTexStorage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, _numSamples, texStorageSizedInternalFormat, _textureWidth, _textureHeight, _fixedsamplelocations);
            }
        }
        else
        {
            textureObject = generateAndAssignTextureObject(contextID, getTextureTarget(), 1, _internalFormat, _textureWidth, _textureHeight, 1, _borderWidth);
            textureObject->bind();

            extensions->glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE,
                                             _numSamples,
                                             _internalFormat,
                                             _textureWidth,
                                             _textureHeight,
                                             _fixedsamplelocations );
        }
        textureObject->setAllocated(1, texStorageSizedInternalFormat!=0? texStorageSizedInternalFormat: _internalFormat, _textureWidth, _textureHeight, 1, _borderWidth);

    }
    else
    {
        glBindTexture( GL_TEXTURE_2D_MULTISAMPLE, 0 );
    }
}

void Texture2DMultisample::computeInternalFormat() const
{
    computeInternalFormatType();
}