~ubuntu-branches/ubuntu/quantal/aqsis/quantal

« back to all changes in this revision

Viewing changes to libs/tex/filtering/itexturesampler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-06 04:53:26 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806045326-z6xeaaao62idxcc6
Tags: 1.6.0-0ubuntu1
* New upstream release
* debian/control:
  - changed name of lib package to libaqsis1 instead of aqsis-libsc2a
  - changed name of dev package to libaqsis-dev instead of aqsis-libs-dev
  - Added aqsis-data package
  - Revised summary text according to that specified by the RISpec (Pixar)
* Moved examples installation from aqsis.install to aqsis-data.install
* debian/rules: 
  - added content to binary-indep target
* debian/rules: added explicit name of mime file to force dh_installmime
  to generate postinst and prerm scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright (C) 1997 - 2007, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.org
 
5
//
 
6
// This library is free software; you can redistribute it and/or
 
7
// modify it under the terms of the GNU General Public
 
8
// License as published by the Free Software Foundation; either
 
9
// version 2 of the License, or (at your option) any later version.
 
10
//
 
11
// This library is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
// General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public
 
17
// License along with this library; if not, write to the Free Software
 
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
/** \file
 
21
 *
 
22
 * \brief Interface to texture buffer sampling machinery.
 
23
 *
 
24
 * \author Chris Foster [ chris42f (at) gmail (dot) com ]
 
25
 */
 
26
 
 
27
#include <aqsis/tex/filtering/itexturesampler.h>
 
28
 
 
29
#ifdef USE_OPENEXR
 
30
#       include <half.h>
 
31
#endif
 
32
 
 
33
#include "dummytexturesampler.h"
 
34
#include <aqsis/tex/io/itexinputfile.h>
 
35
#include "texturesampler.h"
 
36
#include <aqsis/tex/buffers/texturebuffer.h>
 
37
#include <aqsis/tex/buffers/tilearray.h>
 
38
 
 
39
namespace Aqsis {
 
40
 
 
41
//------------------------------------------------------------------------------
 
42
namespace {
 
43
 
 
44
// Helper functions.
 
45
 
 
46
template<typename T>
 
47
boost::shared_ptr<IqTextureSampler> createMipmapSampler(
 
48
                const boost::shared_ptr<IqTiledTexInputFile>& file)
 
49
{
 
50
        typedef CqMipmap<CqTileArray<T> > TqLevelCache;
 
51
        boost::shared_ptr<TqLevelCache> levels(new TqLevelCache(file));
 
52
        boost::shared_ptr<IqTextureSampler> sampler(
 
53
                        new CqTextureSampler<TqLevelCache>(levels));
 
54
        return sampler;
 
55
}
 
56
 
 
57
} // unnamed namespace
 
58
 
 
59
 
 
60
//------------------------------------------------------------------------------
 
61
// IqTextureSampler implementation
 
62
 
 
63
void IqTextureSampler::sample(const SqSampleQuad& sampleQuad,
 
64
                const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const
 
65
{
 
66
        // Default implementation for texture quadrilateral sampling.  This just
 
67
        // approximates the quad with a parallelogram and calls through to the
 
68
        // other version of sample().
 
69
        sample(SqSamplePllgram(sampleQuad), sampleOpts, outSamps);
 
70
}
 
71
 
 
72
const CqTextureSampleOptions& IqTextureSampler::defaultSampleOptions() const
 
73
{
 
74
        static const CqTextureSampleOptions defaultOptions;
 
75
        return defaultOptions;
 
76
}
 
77
 
 
78
boost::shared_ptr<IqTextureSampler> IqTextureSampler::create(
 
79
                const boost::shared_ptr<IqTiledTexInputFile>& file)
 
80
{
 
81
        assert(file);
 
82
        // Check the texture format and complain if it's not a plain texture
 
83
        const CqTexFileHeader& header = file->header();
 
84
        switch(header.find<Attr::TextureFormat>(TextureFormat_Unknown))
 
85
        {
 
86
                case TextureFormat_CubeEnvironment:
 
87
                case TextureFormat_LatLongEnvironment:
 
88
                        Aqsis::log() << warning << "Accessing an environment map as a plain texture\n";
 
89
                        break;
 
90
                case TextureFormat_Shadow:
 
91
                        Aqsis::log() << warning << "Accessing a shadow map as a plain texture\n";
 
92
                        break;
 
93
                default:
 
94
                        // no warnings in generic case.
 
95
                        break;
 
96
        }
 
97
        // Create a texture sampler based on the underlying pixel type.
 
98
        switch(header.channelList().sharedChannelType())
 
99
        {
 
100
                case Channel_Float32:
 
101
                        return createMipmapSampler<TqFloat>(file);
 
102
                case Channel_Unsigned32:
 
103
                        return createMipmapSampler<TqUint32>(file);
 
104
                case Channel_Signed32:
 
105
                        return createMipmapSampler<TqInt32>(file);
 
106
                case Channel_Float16:
 
107
#                       ifdef USE_OPENEXR
 
108
                        return createMipmapSampler<half>(file);
 
109
#                       endif
 
110
                        break;
 
111
                case Channel_Unsigned16:
 
112
                        return createMipmapSampler<TqUint16>(file);
 
113
                case Channel_Signed16:
 
114
                        return createMipmapSampler<TqInt16>(file);
 
115
                case Channel_Unsigned8:
 
116
                        return createMipmapSampler<TqUint8>(file);
 
117
                case Channel_Signed8:
 
118
                        return createMipmapSampler<TqInt8>(file);
 
119
                default:
 
120
                case Channel_TypeUnknown:
 
121
                        break;
 
122
        }
 
123
        AQSIS_THROW_XQERROR(XqBadTexture, EqE_BadFile,
 
124
                "Could not create a texture sampler for file \"" << file->fileName() << "\"");
 
125
        return createDummy();
 
126
}
 
127
 
 
128
boost::shared_ptr<IqTextureSampler> IqTextureSampler::create(
 
129
                const boost::shared_ptr<IqMultiTexInputFile>& file)
 
130
{
 
131
        return createDummy();
 
132
}
 
133
 
 
134
boost::shared_ptr<IqTextureSampler> IqTextureSampler::createDummy()
 
135
{
 
136
        return boost::shared_ptr<IqTextureSampler>(new CqDummyTextureSampler());
 
137
}
 
138
 
 
139
} // namespace Aqsis