MercuryOGL.h

Go to the documentation of this file.
00001 #ifndef MERCURYOGL_H
00002 #define MERCURYOGL_H
00003 
00004 #include "MercuryWindow.h"
00005 
00006 #if defined (WIN32)
00007 #include "Win32Window.h"
00008 #include <GL/glaux.h>
00009 #endif
00010 
00011 #include "MercuryDisplay.h"
00012 #include "MercuryMesh.h"
00013 
00014 #include <GL/gl.h>
00015 
00016 class MercuryOGLGLSLangObject
00017 {
00018 public:
00019     int id;
00020     int primaryTexture;
00021 };
00022 
00023 class MercuryTexture;
00024 
00025 class MercuryOGLFBOObject
00026 {
00027 public:
00028     unsigned int colorID;
00029     unsigned int depthID;
00030 };
00031 
00032 class MercuryOGLFBOCubeObject
00033 {
00034 public:
00035     unsigned int colorID[6];
00036     unsigned int depthID[6];
00037 };
00038 
00039 
00040 
00042 class MercuryOGL : public MercuryDisplay
00043 {
00044     public:
00045         MercuryOGL();
00046         virtual ~MercuryOGL();
00047         virtual bool MakeWindow(const char* title, int width, int height, int bits, bool fullscreenflag);
00048         virtual bool Init(const MString& name, unsigned int width, unsigned int height, unsigned short bpp, bool fullscreen);
00049         virtual bool BeginFrame();
00050         virtual bool EndFrame();
00051         virtual void DrawParticleField(const MercuryParticleField* field);
00052         virtual void DrawMesh(const MercuryMesh& mesh);
00053         virtual void DrawSprite(const MercuryMesh& sprite);
00054         virtual void GenerateVBO(MercuryMesh& mesh);
00055         virtual void DestroyVBO(MercuryMesh& mesh);
00056 
00057         virtual void SetMaterial(const MercuryMaterial* material);
00058         virtual void RendererInfo();
00059 
00060         virtual void ClearZBuffer() { glClear(GL_DEPTH_BUFFER_BIT); }
00061         virtual void ClearFrameBuffer() { glClear(GL_COLOR_BUFFER_BIT); }
00062 
00063         //The following functions are used in managers      
00064         virtual void DeleteTextures(int n, unsigned int* textureNames);
00065 
00066         virtual void UpdateTextureData(MercuryTexture* texture, unsigned int& ID) {};
00067         virtual void CreateCache(RawImageData* data, unsigned int& ID);
00068         virtual void CreateCache(RawImageData* data, unsigned int& ID, bool isMipmap);
00069 
00070         virtual void Viewport(int x, int y, int width, int height) { MercuryDisplay::Viewport(x, y, width, height); glViewport(x, y, width, height); }
00071 
00072         virtual void EnableTextures(MercuryMaterial* material);
00073         virtual void EnableShaders(MercuryMaterial* material);
00074 
00075 
00076         virtual void ErrorCheck();
00077 
00078         virtual void ReadFrameBuffer(RawImageData& image);
00079 
00080         virtual void SendMatrixData(const MercuryMatrix& m);
00081         virtual void SendProjectionMatrixData();
00082 
00083         virtual void StencilOp(STENCILOPS fail, STENCILOPS zfail, STENCILOPS zpass);
00084         virtual void CullBackface(bool toggle);
00085         virtual void StencilFunc(TFUNCT func, int ref, unsigned int zref);
00086 
00087         virtual int CompileShader(MString vertStr, MString fragStr);
00088         virtual void DestroyShaderProgram(int shaderID);
00089 
00090         virtual void DefineClippingPlanes(const MVector<MQuaternion>& planes);
00091 
00092         virtual void RenderTranslucentObject();
00093         virtual void RenderText(const MercuryText& text);
00094         virtual MercuryGLState SetStates(MercuryGLState states);
00095 
00096     private:
00097         void BindShader(int shaderID);
00098         void ProcessTexture(MercuryTexture* texture);
00099         int ConvertDrawType(DRAWTYPES drawtype);
00100         virtual void ProcessLightsInternal( const MercuryLight* light[3], unsigned int count );
00101         void CompileShader(unsigned int shaderDesc);
00102         int ConvertStencilOp(STENCILOPS op) const;
00103         int ConvertTestFunction(TFUNCT funct) const;
00104         void SetUniformVariables(MercuryMaterial* material);
00105         void TestCapabilities();
00106         void LoadImageData(RawImageData* data, bool isMipmap);
00107 
00108         //pixelshader description to glslang object mapping
00109         map <int, MercuryOGLGLSLangObject> m_shaderObjMap;
00110 
00111         unsigned int m_arrayDrawType;
00112         int m_shaderProgramID;
00113         int m_NumEnabledLights;
00114         GLuint m_pixelFormat;
00115         bool active;
00116 
00117         bool isLockRendering;
00118 
00119         bool isRenderingToDynamicTexture;
00120         map <int, MercuryOGLFBOObject> m_fboMap;
00121 
00122         bool isRenderingToDynamicCubeMap;
00123         map <int, MercuryOGLFBOCubeObject> m_fboCubeMap;
00124 
00125         MercuryTexture* m_pCurRenderTex;
00126 };
00127 
00128 #endif
00129 
00130 /* 
00131  * Copyright (c) 2005-2006, Joshua Allen
00132  * All rights reserved.
00133  *
00134  * Redistribution and use in source and binary forms, with or
00135  * without modification, are permitted provided that the following
00136  * conditions are met:
00137  *  -   Redistributions of source code must retain the above
00138  *      copyright notice, this list of conditions and the following disclaimer.
00139  *  -   Redistributions in binary form must reproduce the above copyright
00140  *      notice, this list of conditions and the following disclaimer in
00141  *      the documentation and/or other materials provided with the distribution.
00142  *  -   Neither the name of the Mercury Engine nor the names of its
00143  *      contributors may be used to endorse or promote products derived from
00144  *      this software without specific prior written permission.
00145  *
00146  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00147  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00148  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00149  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00150  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00151  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00152  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00153  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00154  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00155  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00156  */

Hosted by SourceForge.net Logo