00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027
#ifndef SHBASETEXTUREIMPL_HPP
00028
#define SHBASETEXTUREIMPL_HPP
00029
00030
#include "ShBaseTexture.hpp"
00031
#include "ShContext.hpp"
00032
#include "ShError.hpp"
00033
#include "ShLibMisc.hpp"
00034
00035
namespace SH {
00036
00037
template<
typename T>
00038 ShBaseTexture1D<T>::ShBaseTexture1D(
int width,
const ShTextureTraits& traits)
00039 : ShBaseTexture(new ShTextureNode(SH_TEXTURE_1D, T::typesize, traits, width))
00040 {
00041 }
00042
00043
template<
typename T>
00044 ShBaseTexture2D<T>::ShBaseTexture2D(
int width,
int height,
const ShTextureTraits& traits)
00045 : ShBaseTexture(new ShTextureNode(SH_TEXTURE_2D, T::typesize, traits, width, height))
00046 {
00047 }
00048
00049
template<
typename T>
00050 ShBaseTextureRect<T>::ShBaseTextureRect(
int width,
int height,
const ShTextureTraits& traits)
00051 : ShBaseTexture(new ShTextureNode(SH_TEXTURE_RECT, T::typesize, traits, width, height))
00052 {
00053 }
00054
00055
template<
typename T>
00056 ShBaseTexture3D<T>::ShBaseTexture3D(
int width,
int height,
int depth,
const ShTextureTraits& traits)
00057 : ShBaseTexture(new ShTextureNode(SH_TEXTURE_3D, T::typesize, traits, width, height, depth))
00058 {
00059 }
00060
00061
template<
typename T>
00062 ShBaseTextureCube<T>::ShBaseTextureCube(
int width,
int height,
const ShTextureTraits& traits)
00063 : ShBaseTexture(new ShTextureNode(SH_TEXTURE_CUBE, T::typesize, traits, width, height))
00064 {
00065 }
00066
00067
template<
typename T>
00068 ShBaseTexture1D<T>::ShBaseTexture1D(
const ShTextureTraits& traits)
00069 : ShBaseTexture(new ShTextureNode(SH_TEXTURE_1D, T::typesize, traits, 0))
00070 {
00071 }
00072
00073
template<
typename T>
00074 ShBaseTexture2D<T>::ShBaseTexture2D(
const ShTextureTraits& traits)
00075 : ShBaseTexture(new ShTextureNode(SH_TEXTURE_2D, T::typesize, traits, 0, 0))
00076 {
00077 }
00078
00079
template<
typename T>
00080 ShBaseTextureRect<T>::ShBaseTextureRect(
const ShTextureTraits& traits)
00081 : ShBaseTexture(new ShTextureNode(SH_TEXTURE_RECT, T::typesize, traits, 0, 0))
00082 {
00083 }
00084
00085
template<
typename T>
00086 ShBaseTexture3D<T>::ShBaseTexture3D(
const ShTextureTraits& traits)
00087 : ShBaseTexture(new ShTextureNode(SH_TEXTURE_3D, T::typesize, traits, 0, 0, 0))
00088 {
00089 }
00090
00091
template<
typename T>
00092 ShBaseTextureCube<T>::ShBaseTextureCube(
const ShTextureTraits& traits)
00093 : ShBaseTexture(new ShTextureNode(SH_TEXTURE_CUBE, T::typesize, traits, 0, 0))
00094 {
00095 }
00096
00097
template<
typename T>
00098 T ShBaseTexture1D<T>::operator()(
const ShGeneric<1, float>& coords)
const
00099
{
00100
if (ShContext::current()->parsing()) {
00101 T t;
00102 ShVariable texVar(m_node);
00103 ShStatement stmt(t, texVar, SH_OP_TEX, coords);
00104 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00105
return t;
00106 }
else {
00107
00108 T t;
00109
return t;
00110 }
00111 }
00112
00113
template<
typename T>
00114 T ShBaseTexture2D<T>::operator()(
const ShGeneric<2, float>& coords)
const
00115
{
00116
if (ShContext::current()->parsing()) {
00117 T t;
00118 ShVariable texVar(m_node);
00119 ShStatement stmt(t, texVar, SH_OP_TEX, coords);
00120 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00121
return t;
00122 }
else {
00123
00124 T t;
00125
return t;
00126 }
00127 }
00128
00129
template<
typename T>
00130 T
ShBaseTexture2D<T>::operator()(
const ShGeneric<2, float>& coords,
00131
const ShGeneric<2, float>& dx,
00132
const ShGeneric<2, float>& dy)
const
00133
{
00134
if (ShContext::current()->parsing()) {
00135 T t;
00136
ShVariable texVar(m_node);
00137
ShStatement stmt(t,
SH_OP_TEXD, texVar, coords,
join(
dx,
dy));
00138 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00139
return t;
00140 }
else {
00141
shError(
ShScopeException(
"Cannot do derivative texture lookup in immediate mode"));
00142 T t;
return t;
00143 }
00144 }
00145
00146
template<
typename T>
00147 T
ShBaseTextureRect<T>::operator()(
const ShGeneric<2, float>& coords)
const
00148
{
00149
if (ShContext::current()->parsing()) {
00150 T t;
00151
ShVariable texVar(m_node);
00152
ShStatement stmt(t, texVar, SH_OP_TEX, coords);
00153 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00154
return t;
00155 }
else {
00156
00157 T t;
00158
return t;
00159 }
00160 }
00161
00162
template<
typename T>
00163 T ShBaseTexture3D<T>::operator()(
const ShGeneric<3, float>& coords)
const
00164
{
00165
if (ShContext::current()->parsing()) {
00166 T t;
00167 ShVariable texVar(m_node);
00168 ShStatement stmt(t, texVar, SH_OP_TEX, coords);
00169 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00170
return t;
00171 }
else {
00172
00173 T t;
00174
return t;
00175 }
00176 }
00177
00178
template<
typename T>
00179 T ShBaseTextureCube<T>::operator()(
const ShGeneric<3, float>& coords)
const
00180
{
00181
if (ShContext::current()->parsing()) {
00182 T t;
00183 ShVariable texVar(m_node);
00184 ShStatement stmt(t, texVar, SH_OP_TEX, coords);
00185 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00186
return t;
00187 }
else {
00188
00189 T t;
00190
return t;
00191 }
00192 }
00193
00194
template<
typename T>
00195 T ShBaseTexture1D<T>::operator[](
const ShGeneric<1, float>& coords)
const
00196
{
00197
if (ShContext::current()->parsing()) {
00198 T t;
00199 ShVariable texVar(m_node);
00200 ShStatement stmt(t, texVar, SH_OP_TEXI, coords);
00201 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00202
return t;
00203 }
else {
00204
00205 T t;
00206
return t;
00207 }
00208 }
00209
00210
template<
typename T>
00211 T ShBaseTexture2D<T>::operator[](
const ShGeneric<2, float>& coords)
const
00212
{
00213
if (ShContext::current()->parsing()) {
00214 T t;
00215 ShVariable texVar(m_node);
00216 ShStatement stmt(t, texVar, SH_OP_TEXI, coords);
00217 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00218
return t;
00219 }
else {
00220
00221 T t;
00222
return t;
00223 }
00224 }
00225
00226
template<
typename T>
00227 T ShBaseTextureRect<T>::operator[](
const ShGeneric<2, float>& coords)
const
00228
{
00229
if (ShContext::current()->parsing()) {
00230 T t;
00231 ShVariable texVar(m_node);
00232 ShStatement stmt(t, texVar, SH_OP_TEXI, coords);
00233 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00234
return t;
00235 }
else {
00236
00237 T t;
00238
return t;
00239 }
00240 }
00241
00242
template<
typename T>
00243 T ShBaseTexture3D<T>::operator[](
const ShGeneric<3, float>& coords)
const
00244
{
00245
if (ShContext::current()->parsing()) {
00246 T t;
00247 ShVariable texVar(m_node);
00248 ShStatement stmt(t, texVar, SH_OP_TEXI, coords);
00249 ShContext::current()->parsing()->tokenizer.blockList()->addStatement(stmt);
00250
return t;
00251 }
else {
00252
00253 T t;
00254
return t;
00255 }
00256 }
00257
00258
00259
00260
template<
typename T>
00261
void ShBaseTexture1D<T>::memory(ShMemoryPtr memory)
00262 {
00263 m_node->memory(memory);
00264 }
00265
00266
template<
typename T>
00267
void ShBaseTexture2D<T>::memory(ShMemoryPtr memory)
00268 {
00269 m_node->memory(memory);
00270 }
00271
00272
template<
typename T>
00273
void ShBaseTextureRect<T>::memory(ShMemoryPtr memory)
00274 {
00275 m_node->memory(memory);
00276 }
00277
00278
template<
typename T>
00279
void ShBaseTexture3D<T>::memory(ShMemoryPtr memory)
00280 {
00281 m_node->memory(memory);
00282 }
00283
00284
template<
typename T>
00285
void ShBaseTextureCube<T>::memory(ShMemoryPtr memory,
00286 ShCubeDirection face)
00287 {
00288 m_node->memory(memory, face);
00289 }
00290
00291
00292
00293
template<
typename T>
00294 ShMemoryPtr ShBaseTexture1D<T>::memory()
00295 {
00296
return m_node->memory();
00297 }
00298
00299
template<
typename T>
00300 ShMemoryPtr ShBaseTexture2D<T>::memory()
00301 {
00302
return m_node->memory();
00303 }
00304
00305
template<
typename T>
00306 ShMemoryPtr ShBaseTextureRect<T>::memory()
00307 {
00308
return m_node->memory();
00309 }
00310
00311
template<
typename T>
00312 ShMemoryPtr ShBaseTexture3D<T>::memory()
00313 {
00314
return m_node->memory();
00315 }
00316
00317
template<
typename T>
00318 ShMemoryPtr ShBaseTextureCube<T>::memory(ShCubeDirection face)
00319 {
00320
return m_node->memory(face);
00321 }
00322
00323
00324
00325
template<
typename T>
00326 ShAttrib1f ShBaseTexture1D<T>::size()
const
00327
{
00328 ShAttrib1f t(m_node->texSizeVar().node(), ShSwizzle(m_node->texSizeVar().size()),
false);
00329
return t;
00330 }
00331
00332
template<
typename T>
00333 ShAttrib2f ShBaseTexture2D<T>::size()
const
00334
{
00335 ShAttrib2f t(m_node->texSizeVar().node(), ShSwizzle(m_node->texSizeVar().size()),
false);
00336
return t;
00337 }
00338
00339
template<
typename T>
00340 ShAttrib2f ShBaseTextureRect<T>::size()
const
00341
{
00342 ShAttrib2f t(m_node->texSizeVar().node(), ShSwizzle(m_node->texSizeVar().size()),
false);
00343
return t;
00344 }
00345
00346
template<
typename T>
00347 ShAttrib3f ShBaseTexture3D<T>::size()
const
00348
{
00349 ShAttrib3f t(m_node->texSizeVar().node(), ShSwizzle(m_node->texSizeVar().size()),
false);
00350
return t;
00351 }
00352
00353
template<
typename T>
00354 ShAttrib2f ShBaseTextureCube<T>::size()
const
00355
{
00356 ShAttrib2f t(m_node->texSizeVar().node(), ShSwizzle(m_node->texSizeVar().size()),
false);
00357
return t;
00358 }
00359
00360
00361
00362
template<
typename T>
00363
void ShBaseTexture1D<T>::size(
int width)
00364 {
00365 m_node->setTexSize(width);
00366 }
00367
00368
template<
typename T>
00369
void ShBaseTexture2D<T>::size(
int width,
int height)
00370 {
00371 m_node->setTexSize(width, height);
00372 }
00373
00374
template<
typename T>
00375
void ShBaseTextureRect<T>::size(
int width,
int height)
00376 {
00377 m_node->setTexSize(width, height);
00378 }
00379
00380
template<
typename T>
00381
void ShBaseTexture3D<T>::size(
int width,
int height,
int depth)
00382 {
00383 m_node->setTexSize(width, height, depth);
00384 }
00385
00386
template<
typename T>
00387
void ShBaseTextureCube<T>::size(
int width,
int height)
00388 {
00389 m_node->setTexSize(width, height);
00390 }
00391
00392 }
00393
00394
#endif