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
00026
00027
00028
00029
00030
00031
00036 class PG_API pgRend
00037 {
00038 friend class pgPrim;
00039
00040 public:
00041 pgDefineException(ExceptionInvalidArgument);
00042 pgDefineException(ExceptionInvalidCall);
00043 pgDefineException(ExceptionNotInitialized);
00044
00045 virtual ~pgRend();
00046
00047 bool isActive() const;
00048 void setActive(bool is_active);
00049
00050 protected:
00051 pgRend();
00052 void init(pgPrim* prim, u32 body_size, u32 data_size);
00053 void init(pgPrim* prim, u32 body_size, u32 data_size, void* rend_data);
00054
00055 pgPrim* getPrim() const;
00056
00057 template<class T> T* getRendBody()
00058 {
00059 if (!m_prim)
00060 {
00061 pgThrow(ExceptionNotInitialized);
00062 }
00063
00064 return static_cast<T*>(m_rend_body);
00065 }
00066
00067 template<class T> T* getRendData(u16 index)
00068 {
00069 if (!m_prim)
00070 {
00071 pgThrow(ExceptionNotInitialized);
00072 }
00073
00074 if (index >= getMaxDataNum())
00075 {
00076 pgThrow(ExceptionInvalidArgument);
00077 }
00078
00079 return static_cast<T*>(m_rend_data) + index;
00080 }
00081
00082 static void renderAllocBuffer(pgVec** pos_buf, pgCol** col_buf, r32** uv_buf, pgVec** normal_buf,
00083 const pgPrim* prim, bool has_pos_buf, bool has_col_buf, bool has_uv_buf, bool has_normal_buf);
00084
00085 static const pgMat& renderGetPrimWorld(const pgPrim* prim);
00086 static pgTex* renderGetPrimTextureN(const pgPrim* prim);
00087 static pgCol renderGetPrimFinalColor(const pgPrim* prim);
00088
00089 static bool renderIsTextureUVAdjustNeeded(pgTex* tex);
00090 static void renderGetTextureParam(r32* u_param_a, r32* u_param_b, r32* v_param_a, r32* v_param_b, const pgTex* tex);
00091
00092 static void renderCalcColorBuffer(pgCol* col_buf, const pgPrim* prim);
00093 static void renderCalcUVBuffer(r32* uv_buf, const pgPrim* prim);
00094
00095 static void renderSetTexture(pgTex* tex1, pgTex* tex2, pgTex* tex3, bool is_bilinear);
00096 static void renderSetVertexPointer(u32 stride, const r32* vert);
00097 static void renderSetColorPointer(u32 stride, const u8* color);
00098 static void renderSetTexCoordPointer(u32 stride, const r32* uv);
00099
00100 static void renderSetTexture(const pgPrim* prim);
00101 static void renderSetVertexPointer(const pgPrim* prim);
00102 static void renderSetColorPointer(const pgPrim* prim);
00103 static void renderSetTexCoordPointer(const pgPrim* prim);
00104
00105 static void renderDrawArrays(u8 prim_mode, u16 first, u16 count);
00106
00107 static u32 renderGetShaderUniformLocation(const pgShd* shd, u8 index);
00108 static u32 renderGetShaderAttribLocation(const pgShd* shd, u8 index);
00109 static u32 renderGetShaderTextureLocation(const pgShd* shd, u8 index);
00110 static void renderSetShader(pgShd* shd);
00111 static void renderSetUniform_s32(u32 location, s32 uniform);
00112 static void renderSetUniform_r32(u32 location, r32 uniform);
00113 static void renderSetUniform_localToScreen(const pgShd* shd);
00114 static void renderSetAttribPointer_r32(u32 location, u8 size, u32 stride, const r32* attrib);
00115 static void renderSetAttribPointer_vertex(const pgShd* shd, u32 stride, const r32* vert);
00116 static void renderSetAttribPointer_color(const pgShd* shd, u32 stride, const u8* color);
00117 static void renderSetAttribPointer_texCoord(const pgShd* shd, u32 stride, const r32* uv);
00118 static void renderSetAttribPointer_vertex(const pgShd* shd, const pgPrim* prim);
00119 static void renderSetAttribPointer_color(const pgShd* shd, const pgPrim* prim);
00120 static void renderSetAttribPointer_texCoord(const pgShd* shd, const pgPrim* prim);
00121 static void renderDisableAttribPointers(const pgShd* shd);
00122
00123 static void renderCallPrimRenderWithDestroyingBuffer(pgPrim* prim, const pgMat& view);
00124
00125 private:
00126 pgRend(const pgRend&);
00127 void operator=(const pgRend&);
00128
00129 void init2(pgPrim* prim, u32 body_size, u32 data_size, bool is_share_data, void* rend_data);
00130 void uninit();
00131
00132 u16 getMaxDataNum() const;
00133
00134 void reallocData(u16 max_data_num);
00135 void copyData(u16 dest_index, const pgPrim* src_prim, u16 src_index);
00136
00137 virtual pgID getClassID() = 0;
00138 virtual void initData(void* data, u16 data_num) = 0;
00139 virtual void render(const pgMat& view) = 0;
00140
00141 pgType<u8, bool> m_is_active;
00142 u32 m_rend_body_size;
00143 u32 m_rend_data_size;
00144 pgPrim* m_prim;
00145 void* m_rend_body;
00146 void* m_rend_data;
00147 };