~ubuntu-branches/ubuntu/trusty/libavg/trusty-proposed

« back to all changes in this revision

Viewing changes to src/graphics/OGLImagingContext.cpp

  • Committer: Package Import Robot
  • Author(s): OXullo Intersecans
  • Date: 2011-12-06 22:44:56 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20111206224456-qc7250z3ya1vi8s9
Tags: 1.7.0-0ubuntu1
* New upstream release (LP: #899183)
* Remove patches 0002-libav-0.7.patch, 0003-fglrx-segfault-on-startup.patch
  now merged to upstream
* Remove unnecessary .la files
* Update debian/watch file
* Fix debian/copyright dep-5 compliancy
* Update standards to version 3.9.2
* Add man pages for avg_checktouch, avg_checkvsync, avg_showsvg
* Minor debian/rules enhancement
* Add librsvg2-dev, libgdk-pixbuf2.0-dev to Build-Depends
* Proper transition to dh_python2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
2
//  libavg - Media Playback Engine. 
3
 
//  Copyright (C) 2003-2008 Ulrich von Zadow
 
3
//  Copyright (C) 2003-2011 Ulrich von Zadow
4
4
//
5
5
//  This library is free software; you can redistribute it and/or
6
6
//  modify it under the terms of the GNU Lesser General Public
45
45
 
46
46
using namespace std;
47
47
 
48
 
#ifdef _WIN32
49
 
LONG WINAPI imagingWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
50
 
51
 
    return DefWindowProc(hwnd, msg, wParam, lParam); 
52
 
53
 
 
54
 
void registerWindowClass()
55
 
{
56
 
  static char * pClassName;
57
 
  if (pClassName) {
58
 
      return;
59
 
  }
60
 
  pClassName = "GLUT";
61
 
 
62
 
  HINSTANCE hInstance = GetModuleHandle(NULL);
63
 
  WNDCLASS  wc;
64
 
  memset(&wc, 0, sizeof(WNDCLASS));
65
 
  wc.style = CS_OWNDC;
66
 
  wc.lpfnWndProc = (WNDPROC)imagingWindowProc;
67
 
  wc.hInstance = hInstance;
68
 
  wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
69
 
  wc.hCursor = LoadCursor(hInstance, IDC_ARROW);
70
 
  wc.hbrBackground = NULL;
71
 
  wc.lpszMenuName = NULL;
72
 
  wc.lpszClassName = pClassName;
73
 
  
74
 
  BOOL bOK = RegisterClass(&wc);
75
 
  AVG_ASSERT(bOK);
76
 
}
77
 
#endif
78
 
 
79
 
#ifdef linux
80
 
static bool s_bX11Error;
81
 
static int (*s_DefaultErrorHandler) (Display *, XErrorEvent *);
82
 
 
83
 
int X11ErrorHandler(Display * pDisplay, XErrorEvent * pErrEvent)
84
 
{
85
 
    cerr << "X11 error creating offscreen context: " << (int)(pErrEvent->request_code)
86
 
            << ", " << (int)(pErrEvent->minor_code) << endl;
87
 
    s_bX11Error = true;
88
 
    return 0;
89
 
}
90
 
#endif
91
 
 
92
48
OGLImagingContext::OGLImagingContext()
 
49
    : GLContext()
93
50
{
94
 
#ifdef __APPLE__
95
 
    GLint attributes[] = {AGL_RGBA, AGL_ALL_RENDERERS,AGL_NONE};
96
 
    AGLPixelFormat format;
97
 
    format = aglChoosePixelFormat(NULL, 0, attributes);
98
 
    AVG_ASSERT(format);
99
 
 
100
 
    m_Context = aglCreateContext(format, NULL);
101
 
    AVG_ASSERT(m_Context);
102
 
    aglDestroyPixelFormat(format);
103
 
 
104
 
    bool bOk = aglSetCurrentContext(m_Context);
105
 
    AVG_ASSERT (bOk);
106
 
#else
107
 
#ifdef linux
108
 
    Display *dpy;
109
 
    dpy = XOpenDisplay(0);
110
 
    if (!dpy) {
111
 
        throw Exception(AVG_ERR_VIDEO_GENERAL, "No X windows display available.");
112
 
    }
113
 
    XVisualInfo *vi;
114
 
    static int attributes[] = {GLX_RGBA,
115
 
            GLX_RED_SIZE, 1,
116
 
            GLX_GREEN_SIZE, 1,
117
 
            GLX_BLUE_SIZE, 1,
118
 
            0};
119
 
    vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributes);
120
 
    m_Context = glXCreateContext(dpy, vi, 0, GL_TRUE);
121
 
    AVG_ASSERT(m_Context);
122
 
    Pixmap pmp = XCreatePixmap(dpy, RootWindow(dpy, vi->screen),
123
 
            8, 8, vi->depth);
124
 
    GLXPixmap pixmap = glXCreateGLXPixmap(dpy, vi, pmp);
125
 
    
126
 
    s_bX11Error = false;
127
 
    s_DefaultErrorHandler = XSetErrorHandler(X11ErrorHandler);
128
 
    glXMakeCurrent(dpy, pixmap, m_Context);
129
 
    XSetErrorHandler(s_DefaultErrorHandler);
130
 
    
131
 
    if (s_bX11Error) {
132
 
        throw Exception(AVG_ERR_VIDEO_GENERAL, "X error creating OpenGL context.");
133
 
    }
134
 
#else
135
 
#ifdef _WIN32
136
 
    registerWindowClass();
137
 
    m_hwnd = CreateWindow("GLUT", "GLUT",
138
 
            WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
139
 
            0, 0, 500, 300, 0, 0, GetModuleHandle(NULL), 0);
140
 
    winOGLErrorCheck(m_hDC != 0, "CreateWindow");
141
 
    
142
 
    m_hDC = GetDC(m_hwnd);
143
 
    winOGLErrorCheck(m_hDC != 0, "GetDC");
144
 
 
145
 
    PIXELFORMATDESCRIPTOR pfd;
146
 
    ZeroMemory(&pfd, sizeof(pfd));
147
 
    pfd.nSize = sizeof(pfd);
148
 
    pfd.nVersion = 1;
149
 
    pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
150
 
    pfd.iPixelType = PFD_TYPE_RGBA;
151
 
    pfd.cColorBits = 32;
152
 
    pfd.cDepthBits = 32;
153
 
    pfd.iLayerType = PFD_MAIN_PLANE;
154
 
    
155
 
    int iFormat = ChoosePixelFormat(m_hDC, &pfd);
156
 
    winOGLErrorCheck(iFormat != 0, "ChoosePixelFormat");
157
 
    SetPixelFormat(m_hDC, iFormat, &pfd);
158
 
    m_Context = wglCreateContext(m_hDC);
159
 
    winOGLErrorCheck(m_Context != 0, "wglCreateContext");
160
 
 
161
 
    BOOL bOK = wglMakeCurrent(m_hDC, m_Context);
162
 
    winOGLErrorCheck(bOK, "wglMakeCurrent");
163
 
#endif
164
 
#endif
165
 
#endif
166
 
    glproc::init();
 
51
    init();
167
52
 
168
53
    if (!isSupported()) {
169
54
        throw Exception(AVG_ERR_VIDEO_GENERAL, 
175
60
 
176
61
OGLImagingContext::~OGLImagingContext()
177
62
{
178
 
    ShaderRegistry::kill();
179
 
    GPUFilter::glContextGone();
180
 
#ifdef __APPLE__
181
 
    if (m_Context) {
182
 
        aglSetCurrentContext(0);
183
 
        aglDestroyContext(m_Context);
184
 
        m_Context = 0;
185
 
    }
186
 
#endif
187
 
#ifdef _WIN32
188
 
    if (m_Context) {
189
 
        wglDeleteContext(m_Context);
190
 
        DeleteDC(m_hDC);
191
 
        DestroyWindow(m_hwnd);
192
 
    }
193
 
#endif
194
 
}
195
 
 
196
 
void OGLImagingContext::activate()
197
 
{
198
 
#ifdef __APPLE__
199
 
    bool bOk = aglSetCurrentContext(m_Context);
200
 
    AVG_ASSERT(bOk);
201
 
#elif defined _WIN32
202
 
    BOOL bOk = wglMakeCurrent(m_hDC, m_Context);
203
 
    AVG_ASSERT(bOk);
204
 
#endif
205
 
    // TODO: X version
206
63
}
207
64
 
208
65
bool OGLImagingContext::isSupported()