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
#include <cassert>
00028
#include "ShTextureNode.hpp"
00029
#include "ShEnvironment.hpp"
00030
#include "ShDebug.hpp"
00031
#include "ShAttrib.hpp"
00032
00033
namespace SH {
00034
00035 ShTextureNode::ShTextureNode(ShTextureDims dims,
int size,
00036
const ShTextureTraits& traits,
00037
int width,
int height,
int depth)
00038 : ShVariableNode(SH_TEXTURE, size),
00039 m_dims(dims),
00040 m_memory(new ShMemoryPtr[dims == SH_TEXTURE_CUBE ? 6 : 1]),
00041 m_traits(traits),
00042 m_width(width), m_height(height), m_depth(depth)
00043 {
00044
if (m_dims == SH_TEXTURE_1D) {
00045 ShAttrib1f v = ShAttrib1f(width);
00046 m_texSizeVar = ShVariable(v.node());
00047 }
else if (m_dims == SH_TEXTURE_3D) {
00048 ShAttrib3f v = ShAttrib3f(width, height, depth);
00049 m_texSizeVar = ShVariable(v.node());
00050 }
else {
00051 ShAttrib2f v = ShAttrib2f(width, height);
00052 m_texSizeVar = ShVariable(v.node());
00053 }
00054 }
00055
00056 ShTextureNode::~ShTextureNode()
00057 {
00058
delete [] m_memory;
00059 }
00060
00061
ShTextureDims ShTextureNode::dims()
const
00062
{
00063
return m_dims;
00064 }
00065
00066 ShMemoryPtr ShTextureNode::memory(
int n)
00067 {
00068 SH_DEBUG_ASSERT((n == 0)
00069 || (m_dims == SH_TEXTURE_CUBE && n >= 0 && n < 6));
00070
return m_memory[n];
00071 }
00072
00073 ShPointer<const ShMemory> ShTextureNode::memory(
int n)
const
00074
{
00075 SH_DEBUG_ASSERT((n == 0)
00076 || (m_dims == SH_TEXTURE_CUBE && n >= 0 && n < 6));
00077
return m_memory[n];
00078 }
00079
00080
void ShTextureNode::memory(ShMemoryPtr memory,
int n)
00081 {
00082 SH_DEBUG_ASSERT((n == 0)
00083 || (m_dims == SH_TEXTURE_CUBE && n >= 0 && n < 6));
00084 m_memory[n] = memory;
00085 }
00086
00087 ShMemoryPtr ShTextureNode::memory(ShCubeDirection dir)
00088 {
00089
return memory(static_cast<int>(dir));
00090 }
00091
00092 ShPointer<const ShMemory> ShTextureNode::memory(ShCubeDirection dir)
const
00093
{
00094
return memory(static_cast<int>(dir));
00095 }
00096
00097
void ShTextureNode::memory(ShMemoryPtr mem, ShCubeDirection dir)
00098 {
00099 memory(mem, static_cast<int>(dir));
00100 }
00101
00102
const ShTextureTraits& ShTextureNode::traits()
const
00103
{
00104
return m_traits;
00105 }
00106
00107 ShTextureTraits& ShTextureNode::traits()
00108 {
00109
return m_traits;
00110 }
00111
00112
void ShTextureNode::setTexSize(
int w)
00113 {
00114 m_width = w;
00115 ShAttrib1f s(m_texSizeVar.node(), ShSwizzle(m_texSizeVar().size()),
false);
00116 s = static_cast<float>(w);
00117 }
00118
00119
void ShTextureNode::setTexSize(
int w,
int h)
00120 {
00121 m_width = w;
00122 m_height = h;
00123 ShAttrib2f s(m_texSizeVar.node(), ShSwizzle(m_texSizeVar().size()),
false);
00124 s = ShAttrib2f(w, h);
00125 }
00126
00127
void ShTextureNode::setTexSize(
int w,
int h,
int d)
00128 {
00129 m_width = w;
00130 m_height = h;
00131 m_depth = d;
00132 ShAttrib3f s(m_texSizeVar.node(), ShSwizzle(m_texSizeVar().size()),
false);
00133 s = ShAttrib3f(w, h, d);
00134 }
00135
00136
int ShTextureNode::width()
const
00137
{
00138
return m_width;
00139 }
00140
00141
int ShTextureNode::height()
const
00142
{
00143
return m_height;
00144 }
00145
00146
int ShTextureNode::depth()
const
00147
{
00148
return m_depth;
00149 }
00150
00151
const ShVariable& ShTextureNode::texSizeVar()
const
00152
{
00153
return m_texSizeVar;
00154 }
00155
00156 }
00157