Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# DOpenGL.hpp

Go to the documentation of this file.

    00001 ///////////////////////////////////////////////////////////////////////////////
    00002 /// @file DOpenGL.hpp
    00003 ///
    00004 /// @brief Class for OpenGL driver
    00005 ///
    00006 /// @author JesusFreak
    00007 ///
    00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
    00009 /// contents of this file is subject to the Destiny3D Member License which
    00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
    00011 ///
    00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
    00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
    00014 /// for any particular purpose.
    00015 ///
    00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.///
    00017 /// <hr>
    00018 ///                                 Change History
    00019 /// <hr>
    00020 ///
    00021 /// @date Feb 2002
    00022 /// @author JesusFreak
    00023 /// @remarks Creation
    00024 ///
    00025 ///////////////////////////////////////////////////////////////////////////////
    00026
    00027 #ifndef DOPENGL_HPP
    00028 #define DOPENGL_HPP
    00029
    00030 #define DEDRIVER_DLL_EXPORTS
    00031 #define USING_DESTINY3D
    00032
    00033 // Include the driver headers we need
    00034 #include <windows.h>
    00035 #include "deDriver_priv.hpp"
    00036 #include "deShader_priv.hpp"
    00037 #include <gl\gl.h>
    00038 #include "glext.h"
    00039 #include "glh_genext.h"
    00040 #include "deHash.hpp"
    00041
    00042 // OpenGL Extensions we use
    00043 extern PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElementsEXT;
    00044
    00045 // The OpenGL class
    00046 class deOpenGL : public deDriver
    00047 {
    00048         // Constructor/Destructor
    00049 public:
    00050         deOpenGL(long ID);
    00051         ~deOpenGL();
    00052
    00053         long Release();
    00054
    00055         // Public member functions
    00056 public:
    00057         deBoolean Init(HWND WindowHandle);
    00058
    00059         //adapter and mode counts for adapters
    00060         const deDriverCaps* GetCaps(long Adapter) const;
    00061         long GetAdapterCount() const;
    00062         long GetModeCount(long Adapter) const;
    00063         deBoolean WindowedAllowed(long Adapter) const;
    00064
    00065         //display settings
    00066         deBoolean SetDisplay(deDisplay *Display);
    00067         deBoolean Reset(deDisplay *Display);
    00068         deBoolean GetCurrentDisplay(long Adapter, deDisplay * Display) const;
    00069         deBoolean GetDisplayMode(long Adapter, long Mode, deDisplay *Display) const;
    00070         deBoolean ValidFormat(long Adapter, Resource ResourceType, BPP BPPType, ZPP ZPPType, BPP FrontBuffer, long ExtraFlag=0) const;
    00071
    00072         //vertex buffer functions
    00073         deBoolean AddVertexBuffer(IdeVertexBuffer *Vertex);
    00074         deBoolean RemoveVertexBuffer(IdeVertexBuffer *Vertex);
    00075         deBoolean UpdateVertexBuffer(IdeVertexBuffer *Vertex);
    00076
    00077         // Shader functions
    00078         deBoolean AddShader(IdeShader * Shader);
    00079         deBoolean RemoveShader(IdeShader * Shader);
    00080         deBoolean SetShader(IdeShader * Shader);
    00081 /*
    00082         deBoolean DisassembleShader(IdeShader * Shader,deString * Code);
    00083         deBoolean DisassembleShaderArgument(DWORD Argument,deString * Code);
    00084         void DisassembleShaderIndexAndOffset(DWORD IndexBase,DWORD Argument,deString * Code);
    00085         deBoolean DisassembleShaderInstruction(IdeShader::deShaderInstruction * Instruction,deString * Code);
    00086 */
    00087
    00088         //frame functions
    00089         deBoolean BeginFrame();
    00090         deBoolean EndFrame();
    00091         deBoolean ClearFrame(deARGB Color, deBoolean ClearTarget, deBoolean ClearZBuffer, deBoolean ClearStencil);
    00092         deBoolean Render(IdeVertexBuffer *VBuffer, long IndexOffset, IdeVertexBuffer *IndexOverride = NULL);
    00093
    00094         //viewport/FOV functions
    00095         deBoolean SetViewport(long X, long Y, long Width, long Height, deFloat MinZ, deFloat MaxZ);
    00096         deBoolean SetDepthRange(deFloat MinZ, deFloat MaxZ);
    00097         deBoolean SetFOVClipping(deFloat FOV, deFloat Aspect, deFloat ClipNear, deFloat ClipFar);
    00098         deBoolean SetOrthoClipping(deFloat Width, deFloat Height, deFloat ClipNear, deFloat ClipFar, deBoolean Invert = deFALSE);
    00099         deBoolean SetFOVClippingSubRect(deFloat FOVY, deFloat Aspect, deFloat ClipNear, deFloat ClipFar, deRect SubRect);
    00100         deBoolean SetFOVClippingSubRectFloat(deFloat FOVY, deFloat Aspect, deFloat ClipNear, deFloat ClipFar, deFloatRect SubRect);
    00101         deBoolean SetOrthoClippingSubRect(deFloat Width, deFloat Height, deFloat ClipNear, deFloat ClipFar, deBoolean Invert, deRect SubRect);
    00102         deBoolean SetOrthoClippingSubRectFloat(deFloat Width, deFloat Height, deFloat ClipNear, deFloat ClipFar, deBoolean Invert, deFloatRect SubRect);
    00103
    00104         //camera translation functions
    00105         deBoolean SetCameraTransform(deTransformInfo *M);
    00106         deBoolean SetCameraTransform(deVertex *Eye, deVertex *At, deVertex *Up);
    00107         deBoolean SetCameraTranslation(deVertex *Translation);
    00108         deBoolean SetCameraRotation(deVertex *Rotation);
    00109         deBoolean ResetCameraIdentity();
    00110
    00111         //world translation functions
    00112         deBoolean SetWorldTransform(deTransformInfo * M);
    00113         deBoolean SetWorldTransform(deVertex *Eye, deVertex *At, deVertex *Up);
    00114         deBoolean SetWorldTranslation(deVertex *Translation);
    00115         deBoolean SetWorldRotation(deVertex *Rotation);
    00116         deBoolean ResetWorldIdentity();
    00117
    00118         deBoolean SetTextureTransform(long StageNum, deTransformInfo * Mat);
    00119
    00120         //texture functions
    00121         deBoolean AddBitmap(IdeBitmap *Bitmap);
    00122         deBoolean AddBitmapProxy(IdeBitmapProxy *BitmapProxy);
    00123         deBoolean RemoveBitmap(IdeBitmap *Bitmap);
    00124
    00125         //render-to-texture functions
    00126         deBoolean RenderTo(IdeBitmap *pBitmap, long CubeMapFace = 0);
    00127         deBoolean ScreenShot(IdeBitmap * &pBitmap, deBoolean GrabWindow = deTRUE);
    00128         deBoolean GetVideoTexture(IdeBitmap* pBitmap, long CubeMapFace = 0);
    00129
    00130         //render states
    00131         unsigned long GetRenderState(RenderState State);
    00132         deBoolean SetRenderState(const IdeRenderState *State);
    00133         deBoolean SetRenderState(RenderState State, unsigned long Value);
    00134         deBoolean EnableLight(long LightID, deBoolean Enable);
    00135         deBoolean DisableAllLights();
    00136
    00137         //driver info
    00138         deDriverInfo *deOpenGL::GetInfo() const;
    00139         IdeDriver::Types GetType() const;
    00140
    00141         void InvalidateRenderStates(deBoolean Valid);
    00142         // Private member variables
    00143 private:
    00144         HGLRC                   RC; // Rendering Context
    00145         HDC                     DC;
    00146
    00147         typedef struct VertexBufferEntry
    00148         {
    00149             long                        ID;             //ID to verify the structure
    00150             //long                      UniqueID;       //For the display list
    00151             unsigned long               VertexBuffer;   //the vertex Buffer ID
    00152             long                        EntrySize[IdeVertexBuffer::BUFFER_COUNT-1];     //size of each entry
    00153             void                        *Buffers[IdeVertexBuffer::BUFFER_COUNT-1];      //the actual buffers to render
    00154             void                        *IndexBuffer;
    00155             GLenum                      IndexType;
    00156             GLenum                      RenderType;     //type of rendering to do
    00157             long                        PointCount;     //number of points
    00158             long                        TriCount;       //number of tris
    00159             long                        IndexCount;     //number of index entries
    00160             long                        PointStart;
    00161             long                        IndexStart;
    00162             deBoolean                   Dynamic;
    00163             deBoolean                   SubBuffer; // Remove if we don't need it
    00164         } VertexBufferEntry;
    00165
    00166         typedef struct TextureEntry
    00167         {
    00168             long                ID;         //ID to verify the struct
    00169             GLuint              Texture;
    00170         } TextureEntry;
    00171
    00172         // Private member functions
    00173 private:
    00174         void Present();
    00175         void Shutdown();
    00176
    00177         deBoolean EnumerateDisplayModes(); // To seperate platform specific code
    00178
    00179         deBoolean SetTextureState(IdeRenderTexture *State);
    00180         deBoolean SetLightState(IdeRenderLight *State);
    00181         deBoolean SetMaterialState(IdeRenderMaterial *State);
    00182
    00183         deBoolean FillBufferInfo(VertexBufferEntry *BufferEntry, IdeVertexBuffer *Vertex, IdeVertexBuffer::BufferType BufferType, deBoolean WipeBuffer);
    00184         deBoolean ProcessVertexBuffer(IdeVertexBuffer *Vertex, VertexBufferEntry *VertexBufferInfo, long BufferFlags);
    00185         void SetVertexBuffer(VertexBufferEntry * VertexBufferInfo);
    00186
    00187         // To get information about BPP Type's and to convert them between Destiny,OpenGL and Window's types
    00188         deBoolean ToGLBPP(IdeDriver::BPP BPPType,GLint * InternalFormat,GLenum * Format,GLenum * Type) const;
    00189         unsigned char GetBPP(IdeDriver::BPP BPPType);
    00190         IdeDriver::BPP GetDestinyBPP(long BPP) const;
    00191
    00192         GLenum GetOGLTextureWrappingMode(IdeRenderTexture::TextureAddress Address);
    00193
    00194         // Private member variables
    00195 private:
    00196         deTHashInt <IdeVertexBuffer*>       m_VBufferList;
    00197         deTHashInt <IdeBitmap*>             m_TexturesList;
    00198         deDisplay                           **m_Modes;
    00199         deBoolean                           RenderStatesValid;
    00200         GLenum                              AlphaFunction;
    00201         GLclampf                            AlphaRef;
    00202         GLenum                              SrcBlendFactor;
    00203         GLenum                              DestBlendFactor;
    00204         GLenum                              MirroredTextureWrapFlag;
    00205         deBoolean                           NVVertexProgramExt;
    00206         int                                 m_AdapterCount;
    00207         deBoolean                           *m_WindowPossible;
    00208         int                                 *m_ModeCount;
    00209         deDriverCaps                        *m_Caps;
    00210 };
    00211
    00212 extern "C"
    00213 {
    00214     //include the all important APIs so that we can be used
    00215 #ifdef _DEBUG
    00216     __declspec(dllexport) deBoolean IsDestiny3DDriverDebug();
    00217 #else
    00218     __declspec(dllexport) deBoolean IsDestiny3DDriver();
    00219 #endif
    00220     __declspec(dllexport) IdeDriver *GetDriverInstance(long ID);
    00221     __declspec(dllexport) const deDriverInfo *GetDriverInfo(long StructSize);
    00222 };
    00223
    00224 #endif