www.pudn.com > AndreasHalm-src.zip > ChildView.h
// ChildView.h : interface of the CChildView class // #pragma once #include#include "gale.h" #include "texture.h" #include "minimesh.h" #include ".\LoadingProgress.h" // this defines where we want our general attributes // to be set. #define TEX0_S_ATTRIBUTE 11 #define TEX0_T_ATTRIBUTE 12 // the base class creates the object id when created. this // class creates the id when it is needed (lazy creation). // additionally, it scans for the word "software" in the // linker info log. this allows for changing the menu // depending on if we have hardware acceleration or not. class LazyProgramObject :public gale::ProgramObject { enum { __lazy }; void initLazy() { if (m_handle == __lazy) m_handle = createProgramObject(); } bool software; public: LazyProgramObject() :ProgramObject(__lazy) { software=false; } void attach(const gale::VertexShader& shader) const { const_cast (this)->initLazy(); __super::attach(shader); } void attach(const gale::FragmentShader& shader) const { const_cast (this)->initLazy(); __super::attach(shader); } void attach(GLhandleARB handle) const { const_cast (this)->initLazy(); ContainerObject::attach(handle); } bool link() { bool v = __super::link(); if (v) { software = (getInfoLog().find("software") != std::string::npos); } return v; } bool runsInSoftware() const { return software; } }; // this will be holding one of our vertices // used as template class for the mesh class // (see minimesh.h for more info) struct MyVertex { float v [3]; // vertex position float n [3]; // normal float t [2]; // texture coordinate float a [3]; // general attribute 1 float b [3]; // general attribute 2 void setup() const; void unsetup() const; }; // loading one vertex from a stream inline std::istream& operator >> (std::istream& is, MyVertex& v) { is >> v.v[0] >> v.v[1] >> v.v[2] >> v.n[0] >> v.n[1] >> v.n[2] >> v.t[0] >> v.t[1] >> v.a[0] >> v.a[1] >> v.a[2] >> v.b[0] >> v.b[1] >> v.b[2]; return is; } // setup the vertex array inline void MyVertex::setup() const { glVertexPointer(3,GL_FLOAT,sizeof(MyVertex),(void*)v); glEnableClientState(GL_VERTEX_ARRAY); glNormalPointer(GL_FLOAT,sizeof(MyVertex),(void*)n); glEnableClientState(GL_NORMAL_ARRAY); glTexCoordPointer(2,GL_FLOAT,sizeof(MyVertex),(void*)t); glEnableClientState(GL_TEXTURE_COORD_ARRAY); if (GLEW_ARB_shader_objects) { glVertexAttribPointerARB(TEX0_S_ATTRIBUTE,3,GL_FLOAT,GL_FALSE,sizeof(MyVertex),(void*)a); glEnableVertexAttribArrayARB(TEX0_S_ATTRIBUTE); glVertexAttribPointerARB(TEX0_T_ATTRIBUTE,3,GL_FLOAT,GL_FALSE,sizeof(MyVertex),(void*)b); glEnableVertexAttribArrayARB(TEX0_T_ATTRIBUTE); } } // disable all arrays we used inline void MyVertex::unsetup() const { glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); if (GLEW_ARB_shader_objects) { glDisableVertexAttribArrayARB(TEX0_S_ATTRIBUTE); glDisableVertexAttribArrayARB(TEX0_T_ATTRIBUTE); } } // CChildView window class CChildView : public CWnd { HDC dc; HGLRC gl_context; // flags bool auto_rotation; // image info unsigned int* data; gale::Color3f text_color; // our mesh MiniMesh cube_sides, cube_edges; // shader bool LoadGLSLProgram( LazyProgramObject& program, UINT vertexshader_id, UINT fragmentshader_id, CLoadingProgress* ); bool glsl; gale::ProgramObject* cube_program; LazyProgramObject cube_program_default; LazyProgramObject cube_program_bm2p; LazyProgramObject cube_program_bm4p; LazyProgramObject cube_program_bm8p; bool SetupCubeProgram(CLoadingProgress*); // edges TextureData edge_bm_data; Texture edge_bm; gale::ProgramObject* cube_program_edges; LazyProgramObject cube_program_edges_default; LazyProgramObject cube_program_edges_bm8p; // cube mapping bool cube_mapping; bool SetupCubeMapping(); bool OnNewImage(); void Draw(); // Construction public: CChildView(); // Attributes public: // Operations public: // Overrides protected: virtual BOOL PreCreateWindow(CREATESTRUCT& cs); // Implementation public: virtual ~CChildView(); // Generated message map functions protected: afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnDestroy(); afx_msg void OnTimer(UINT nIDEvent); afx_msg void OnPaint(); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnShaderNoBumpmapping(); afx_msg void OnUpdateShaderNoBumpmapping(CCmdUI *pCmdUI); afx_msg void OnShader2pBumpmapping(); afx_msg void OnUpdateShader2pBumpmapping(CCmdUI *pCmdUI); afx_msg void OnShader4pBumpmapping(); afx_msg void OnUpdateShader4pBumpmapping(CCmdUI *pCmdUI); afx_msg void OnShader8pBumpmapping(); afx_msg void OnUpdateShader8pBumpmapping(CCmdUI *pCmdUI); afx_msg void OnSettingsRotation(); afx_msg void OnUpdateSettingsRotation(CCmdUI *pCmdUI); afx_msg void OnEdgeShaderUseSideShader(); afx_msg void OnUpdateEdgeShaderUseSideShader(CCmdUI *pCmdUI); afx_msg void OnEdgeShaderNoBumpMapping(); afx_msg void OnUpdateEdgeShaderNoBumpMapping(CCmdUI *pCmdUI); afx_msg void OnEdgeShader8pBumpMapping(); afx_msg void OnUpdateEdgeShader8pBumpMapping(CCmdUI *pCmdUI); DECLARE_MESSAGE_MAP() };