00001 #ifndef _OPENGL_CONTEXT_H_
00002 #define _OPENGL_CONTEXT_H_
00003
00004
00005 #include <vector>
00006 using namespace std;
00007
00008
00009 #include <qstring.h>
00010 #include <qrect.h>
00011
00012
00013 #include "util-x11.h"
00014
00015 class OpenGLVideo;
00016 class PrivateContext;
00017
00018 typedef enum
00019 {
00020 kGLExtRect = 0x01,
00021 kGLExtFragProg = 0x02,
00022 kGLExtFBufObj = 0x04,
00023 kGLXPBuffer = 0x08,
00024 } GLFeatures;
00025
00026 #ifdef USING_OPENGL
00027
00028 class OpenGLContext
00029 {
00030 public:
00031 OpenGLContext();
00032 ~OpenGLContext();
00033
00034 bool Create(Display *display, Window window, uint screen_num,
00035 const QSize &display_visible_size, bool visible);
00036 void Hide(void);
00037 void Show(void);
00038
00039 bool MakeCurrent(bool current);
00040 void SwapBuffers(void);
00041 void Flush(void);
00042
00043 uint GetMaxTexSize(void) const { return m_max_tex_size; }
00044 uint GetScreenNum(void) const { return m_screen_num; }
00045
00046 uint CreateTexture(void);
00047 bool SetupTexture(const QSize &size, uint tex, int filt);
00048 void SetupTextureFilters(uint tex, int filt);
00049 void DeleteTexture(uint tex);
00050 int GetTextureType(void) const;
00051 void EnableTextures(void);
00052
00053 bool CreateFragmentProgram(const QString &program, uint &prog);
00054 void DeleteFragmentProgram(uint prog);
00055 void BindFragmentProgram(uint fp);
00056 void InitFragmentParams(uint fp, float a, float b, float c, float d);
00057
00058 bool CreateFrameBuffer(uint &fb, uint tex, const QSize &size);
00059 void DeleteFrameBuffer(uint fb);
00060 void BindFramebuffer(uint fb);
00061
00062 bool IsFeatureSupported(GLFeatures feature) const
00063 { return m_ext_supported & feature; }
00064
00065 static bool IsGLXSupported(Display *display, uint major, uint minor);
00066
00067 private:
00068 bool IsGLXSupported(uint major, uint minor) const
00069 {
00070 return (m_major_ver > major) ||
00071 ((m_major_ver == major) && (m_minor_ver >= minor));
00072 }
00073
00074 void DeleteTextures(void);
00075 void DeletePrograms(void);
00076 void DeleteFrameBuffers(void);
00077
00078 PrivateContext *m_priv;
00079
00080 Display *m_display;
00081 uint m_screen_num;
00082 uint m_major_ver;
00083 uint m_minor_ver;
00084 QString m_extensions;
00085 uint m_ext_supported;
00086 bool m_visible;
00087 uint m_max_tex_size;
00088 };
00089
00090 #else // if !USING_OPENGL
00091
00092 class OpenGLContext
00093 {
00094 public:
00095 OpenGLContext() { }
00096 ~OpenGLContext() { }
00097
00098 bool Create(Display*, Window, uint, const QSize&, bool) { return false; }
00099
00100 bool MakeCurrent(bool) { return false; }
00101 void SwapBuffers(void) { }
00102 void Flush(void) { }
00103
00104 uint GetMaxTexSize(void) const { return 0; }
00105 uint GetScreenNum(void) const { return 0; }
00106
00107 uint CreateTexture(void) { return 0; }
00108 bool SetupTexture(const QSize&, uint, int) { return false; }
00109 void SetupTextureFilters(uint, int) { }
00110 void DeleteTexture(uint) { }
00111 int GetTextureType(void) const { return 0; }
00112 void EnableTextures(void) { }
00113
00114 bool CreateFragmentProgram(const QString&, uint&) { return false; }
00115 void DeleteFragmentProgram(uint) { }
00116 void BindFragmentProgram(uint) { }
00117 void InitFragmentParams(uint, float, float, float, float) { }
00118
00119 bool CreateFrameBuffer(uint&, uint, const QSize&) { return false; }
00120 void DeleteFrameBuffer(uint);
00121 void BindFramebuffer(uint);
00122
00123 bool IsFeatureSupported(GLFeatures) const { return false; }
00124
00125 static bool IsGLXSupported(Display*, uint, uint) { return false; }
00126 };
00127
00128 #endif
00129
00130 #endif // _OPENGL_CONTEXT_H_