00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef OST_VERTEX_ARRAY_HH
00020 #define OST_VERTEX_ARRAY_HH
00021
00022
00023
00024
00025
00026
00027
00028 #include <vector>
00029 #include <cassert>
00030 #include <iostream>
00031 #include <cmath>
00032
00033 #include <ost/log.hh>
00034 #include <ost/geom/geom.hh>
00035
00036
00037 #include "color.hh"
00038 #include "material.hh"
00039 #include "gfx_prim.hh"
00040 #include "povray_fw.hh"
00041
00042 namespace ost { namespace gfx {
00043
00044 typedef unsigned int VertexID;
00045 typedef unsigned int LineID;
00046 typedef unsigned int TriID;
00047 typedef unsigned int QuadID;
00048 class DLLEXPORT_OST_GFX IndexedVertexArray {
00049 public:
00050 struct Entry {
00051 Entry();
00052 Entry(const geom::Vec3& vv, const geom::Vec3& nn, const Color& cc);
00053 float c[4];
00054 float n[3];
00055 float v[3];
00056 };
00057
00058 struct NormalizerVertexEntry {
00059 geom::Vec3 pos;
00060 TriID tri_list[50];
00061 uint tri_count;
00062 float weight;
00063 };
00064
00065 struct NormalizerTriEntry {
00066 TriID tid;
00067 VertexID id0,id1,id2;
00068 geom::Vec3 norm;
00069 float weight;
00070 };
00071
00072 typedef std::vector<Entry> EntryList;
00073 typedef std::vector<VertexID> IndexList;
00074 typedef std::vector<NormalizerVertexEntry> NVEntryList;
00075 typedef std::vector<NormalizerTriEntry> NTEntryList;
00076
00077 IndexedVertexArray();
00078 ~IndexedVertexArray();
00079
00080 IndexedVertexArray(const IndexedVertexArray& va);
00081 IndexedVertexArray& operator=(const IndexedVertexArray& va);
00082
00083 static unsigned int GetFormat();
00084
00085 void Cleanup();
00086
00087
00088
00089
00090
00091
00092 void SetMode(int m);
00093 int GetMode() const;
00094
00095
00096 void SetPolyMode(int m);
00097
00098 void SetLighting(bool f);
00099 void SetTwoSided(bool f);
00100 void SetCullFace(bool f);
00101 void SetColorMaterial(bool f);
00102 void SetLineWidth(float lw);
00103 void SetAALines(bool f);
00104 void SetPointSize(float ps);
00105 void SetLineHalo(float lh);
00106
00107 void SetOutlineMode(int m);
00108 void SetOutlineWidth(float f);
00109 void SetOutlineMaterial(const Material& m);
00110 void SetOutlineExpandFactor(float f);
00111 void SetOutlineExpandColor(const Color& c);
00112
00113
00114 VertexID Add(const geom::Vec3& vert, const geom::Vec3& norm, const Color& col);
00115
00116 unsigned int GetVertexCount() const;
00117 void DumpVertices() const;
00118
00119
00120 LineID AddLine(VertexID id0, VertexID id1);
00121
00122
00123 TriID AddTri(VertexID id0, VertexID id1, VertexID id2);
00124
00125
00126 TriID AddTriN(VertexID id0, VertexID id1, VertexID id2);
00127
00128
00129 QuadID AddQuad(VertexID id0, VertexID id1, VertexID id2, VertexID id3);
00130
00131
00132 void AddSphere(const SpherePrim& prim, unsigned int detail);
00133
00134
00135 void AddIcoSphere(const SpherePrim& prim, unsigned int detail);
00136
00137 void AddCylinder(const CylinderPrim& prim, unsigned int detail);
00138
00139 geom::Vec3 GetVert(VertexID id) const;
00140 void SetVert(VertexID id, const geom::Vec3& vert);
00141
00142 geom::Vec3 GetNormal(VertexID id) const;
00143 void SetNormal(VertexID id, const geom::Vec3& norm);
00144
00145 Color GetColor(VertexID id) const;
00146 void SetColor(VertexID id, const Color& col);
00147
00148
00149 void RenderGL();
00150
00151
00152 void RenderPov(PovState& pov, const std::string& name);
00153
00154
00155 void Clear();
00156 void FlagRefresh();
00157
00158 void CalcNormals(float smoothf);
00159 void DrawNormals(bool f);
00160
00161
00162 void CalcFullNormals();
00163
00164 void SmoothNormals(float smoothf);
00165
00166 void NPatch();
00167
00168 void SmoothVertices(float smoothf);
00169
00170 void UseAmbient(bool f);
00171
00172 const EntryList& GetEntries() const {return entry_list_;}
00173 const IndexList& GetQuadIndices() const {return quad_index_list_;}
00174 const IndexList& GetTriIndices() const {return tri_index_list_;}
00175 const IndexList& GetLineIndices() const {return line_index_list_;}
00176
00177 Color GetAmbientColor(VertexID id) const;
00178 void SetAmbientColor(VertexID id, const Color& col);
00179
00180 private:
00181 bool initialized_;
00182
00183 EntryList entry_list_;
00184 IndexList quad_index_list_;
00185 IndexList tri_index_list_;
00186 IndexList line_index_list_;
00187 NTEntryList ntentry_list_;
00188
00189 bool dirty_;
00190
00191 int mode_;
00192 int poly_mode_;
00193 bool lighting_;
00194 bool cull_face_;
00195 bool two_sided_;
00196 bool color_mat_;
00197 float line_width_;
00198 bool aalines_flag_;
00199 float point_size_;
00200 float line_halo_;
00201
00202 int outline_mode_;
00203 float outline_width_;
00204 Material outline_mat_;
00205 bool outline_mat_update_;
00206 unsigned int outline_mat_dlist_;
00207 float outline_exp_factor_;
00208 Color outline_exp_color_;
00209
00210 bool draw_normals_;
00211
00212 unsigned int buffer_id_[7];
00213
00214 bool use_ambient_;
00215 bool ambient_dirty_;
00216 std::vector<float> ambient_data_;
00217
00218 void copy(const IndexedVertexArray& va);
00219 bool prep_buff();
00220 void draw_ltq(bool use_buff);
00221 void draw_p(bool use_buff);
00222 void draw_aalines();
00223 void draw_line_halo(bool use_buff);
00224 void recalc_ambient_occlusion();
00225 };
00226
00227 }}
00228
00229 #endif