00001 #include <eagle/GL/EagleGL.hpp>
00002 #include <vector/MultiArray.hpp>
00003 #include <field/Cell.hpp>
00004 #include <memcore/Chunk.hpp>
00005
00006 #ifndef __FIBER_GL_HPP
00007 #define __FIBER_GL_HPP
00008
00009
00010 template <>
00011 class glType<Fiber::TriangleCell>
00012 {
00013 public:
00014 enum a { type = glType<Fiber::TriangleCell::value_type>::type };
00015 enum b { utype = glType<Fiber::TriangleCell::value_type>::type };
00016 enum c { components = 3 };
00017 };
00018
00019
00020 namespace GL
00021 {
00022 using namespace Eagle;
00023 using namespace Fiber;
00024
00025 template <class T, int N>
00026 inline void VertexPointer(const ElementIterator<FixedArray<T,N> >&P)
00027 {
00028 ::glVertexPointer(N, glType<T>::type, 0, P.ptr() );
00029 }
00030
00031 template <class T, int N>
00032 inline void ColorPointer(const ElementIterator<FixedArray<T,N> >&P)
00033 {
00034 ::glColorPointer(N, glType<T>::type, 0, P.ptr() );
00035 }
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 inline void VertexPointer(const ElementIterator<point3>&P)
00046 {
00047 ::glVertexPointer(3, glType<point3::value_type>::type, 0, P.ptr() );
00048 }
00049
00050 inline void NormalPointer(const ElementIterator<bivector3>&P)
00051 {
00052 ::glNormalPointer(glType<bivector3::value_type>::type, 0, P.ptr() );
00053 }
00054
00055 inline void ColorPointer(const ElementIterator<bivector3>&P)
00056 {
00057 ::glColorPointer(3, glType<bivector3::value_type>::type, 0, P.ptr() );
00058 }
00059
00060 template <typename T>
00061 inline void IndexPointer(const ElementIterator<T>&P)
00062 {
00063 ::glIndexPointer(glType<T>::type, 0, P.ptr() );
00064 }
00065
00066 template <class T>
00067 inline void DrawElements(GLenum mode, const ElementIterator<T>&P)
00068 {
00069 ::glDrawElements( mode, P.count(), glType<T>::type, P.ptr() );
00070 }
00071
00072 template <class T>
00073 inline void DrawPoints(const ElementIterator<T>&P)
00074 {
00075 ::glDrawElements( GL_POINTS, P.count(), glType<T>::type, P.ptr() );
00076 }
00077
00078 template <class T>
00079 inline void DrawLine(const ElementIterator<T>&P)
00080 {
00081 ::glDrawElements( GL_LINE_STRIP, P.count(), glType<T>::type, P.ptr() );
00082 }
00083
00084
00085 template <class T>
00086 inline void DrawElements(const ElementIterator<FixedArray<T,2> >&P)
00087 {
00088 ::glDrawElements( GL_LINES, 2*P.count(), glType<T>::type, P.ptr() );
00089 }
00090
00091 template <class T>
00092 inline void DrawElements(const ElementIterator<FixedArray<T,3> >&P)
00093 {
00094 ::glDrawElements( GL_TRIANGLES, 3*P.count(), glType<T>::type, P.ptr() );
00095 }
00096
00097 template <class T>
00098 inline void DrawElements(const ElementIterator<FixedArray<T,4> >&P)
00099 {
00100 ::glDrawElements( GL_QUADS, 4*P.count(), glType<T>::type, P.ptr() );
00101 }
00102
00103 inline void DrawElements(const ElementIterator<TriangleCell>&P)
00104 {
00105 size_t A = TriangleCell::SIZE, B = P.count(),
00106 C = A*B;
00107
00108 ::glDrawElements( GL_TRIANGLES, C,
00109 glType<TriangleCell::value_type>::type, P.ptr() );
00110 }
00111
00112 inline void DrawElements(const std::vector<TriangleCell>&P)
00113 {
00114 size_t A = TriangleCell::SIZE, B = P.size(),
00115 C = A*B;
00116
00117 ::glDrawElements( GL_TRIANGLES, C,
00118 glType<TriangleCell::value_type>::type, &*P.begin() );
00119 }
00120
00121 inline void DrawElements(const MemCore::Chunk<TriangleCell>&P)
00122 {
00123 DrawElements(P.std_vector() );
00124 }
00125
00126
00127
00142 template <class Type>
00143 inline bool TexImage(const MultiArray<2, Type>&TextureArray,
00144 GLenum format = glType<Type>::format,
00145 GLint internalformat = glType<Type>::components,
00146 GLint level = 0, GLint border = 0 )
00147 {
00148 if (TextureArray.multiplicity()>1 && TextureArray.isSeparatedCompound() )
00149 return false;
00150
00151
00152 if (!TextureArray.ptr())
00153 return false;
00154
00155 TexImage2D(TextureArray.ptr(),
00156 TextureArray.Size()[0],
00157 TextureArray.Size()[1],
00158 format,
00159 internalformat,
00160 level, border );
00161
00162 return true;
00163 }
00164
00165
00166
00167 template <class Type>
00168 inline bool TexImage(const MultiArray<1, Type>&TextureArray,
00169 GLenum format = glType<Type>::format,
00170 GLint internalformat = GL_RGB,
00171 GLint level = 0, GLint border = 0 )
00172 {
00173 if (TextureArray.multiplicity()>1 && TextureArray.isSeparatedCompound() )
00174 return false;
00175
00176 const Type*Data = TextureArray.ptr();
00177 if (!Data)
00178 return false;
00179
00180 TexImage1D(Data,
00181 TextureArray.Size()[0],
00182 format,
00183 internalformat,
00184 level, border );
00185
00186 return true;
00187 }
00188
00189
00190
00191 }
00192
00193 #endif // __FIBER_GL_HPP
00194