2
// Copyright (C) 1997 - 2007, Paul C. Gregory
4
// Contact: pgregory@aqsis.org
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.
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.
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
22
* \brief Interface to texture buffer sampling machinery.
24
* \author Chris Foster [ chris42f (at) gmail (dot) com ]
27
#include <aqsis/tex/filtering/itexturesampler.h>
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>
41
//------------------------------------------------------------------------------
47
boost::shared_ptr<IqTextureSampler> createMipmapSampler(
48
const boost::shared_ptr<IqTiledTexInputFile>& file)
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));
57
} // unnamed namespace
60
//------------------------------------------------------------------------------
61
// IqTextureSampler implementation
63
void IqTextureSampler::sample(const SqSampleQuad& sampleQuad,
64
const CqTextureSampleOptions& sampleOpts, TqFloat* outSamps) const
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);
72
const CqTextureSampleOptions& IqTextureSampler::defaultSampleOptions() const
74
static const CqTextureSampleOptions defaultOptions;
75
return defaultOptions;
78
boost::shared_ptr<IqTextureSampler> IqTextureSampler::create(
79
const boost::shared_ptr<IqTiledTexInputFile>& 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))
86
case TextureFormat_CubeEnvironment:
87
case TextureFormat_LatLongEnvironment:
88
Aqsis::log() << warning << "Accessing an environment map as a plain texture\n";
90
case TextureFormat_Shadow:
91
Aqsis::log() << warning << "Accessing a shadow map as a plain texture\n";
94
// no warnings in generic case.
97
// Create a texture sampler based on the underlying pixel type.
98
switch(header.channelList().sharedChannelType())
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:
108
return createMipmapSampler<half>(file);
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);
120
case Channel_TypeUnknown:
123
AQSIS_THROW_XQERROR(XqBadTexture, EqE_BadFile,
124
"Could not create a texture sampler for file \"" << file->fileName() << "\"");
125
return createDummy();
128
boost::shared_ptr<IqTextureSampler> IqTextureSampler::create(
129
const boost::shared_ptr<IqMultiTexInputFile>& file)
131
return createDummy();
134
boost::shared_ptr<IqTextureSampler> IqTextureSampler::createDummy()
136
return boost::shared_ptr<IqTextureSampler>(new CqDummyTextureSampler());