blob: 656a0d3b21e2d0466aabc02682259f1bc1068740 [file] [log] [blame]
[email protected]d37231fa2010-04-09 21:16:021// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5a6db6c2010-04-22 18:32:065#ifndef APP_GFX_GL_GL_CONTEXT_H_
6#define APP_GFX_GL_GL_CONTEXT_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]d37231fa2010-04-09 21:16:028
[email protected]5a6db6c2010-04-22 18:32:069#include "base/logging.h"
[email protected]4bedba72010-04-20 22:08:5410#include "build/build_config.h"
[email protected]d37231fa2010-04-09 21:16:0211#include "gfx/native_widget_types.h"
12#include "gfx/size.h"
[email protected]d37231fa2010-04-09 21:16:0213
[email protected]5a6db6c2010-04-22 18:32:0614namespace gfx {
[email protected]d37231fa2010-04-09 21:16:0215
[email protected]d37231fa2010-04-09 21:16:0216// Encapsulates an OpenGL context, hiding platform specific management.
17class GLContext {
18 public:
[email protected]5a6db6c2010-04-22 18:32:0619 GLContext() {}
20 virtual ~GLContext() {}
[email protected]d37231fa2010-04-09 21:16:0221
22 // Destroys the GL context.
23 virtual void Destroy() = 0;
24
25 // Makes the GL context current on the current thread.
26 virtual bool MakeCurrent() = 0;
27
[email protected]7d9ce4f2010-04-14 18:39:4028 // Returns true if this context is current.
29 virtual bool IsCurrent() = 0;
30
[email protected]d37231fa2010-04-09 21:16:0231 // Returns true if this context is offscreen.
32 virtual bool IsOffscreen() = 0;
33
34 // Swaps front and back buffers. This has no effect for off-screen
35 // contexts.
36 virtual void SwapBuffers() = 0;
37
38 // Get the size of the back buffer.
39 virtual gfx::Size GetSize() = 0;
40
41 // Get the underlying platform specific GL context "handle".
[email protected]4bedba72010-04-20 22:08:5442 virtual void* GetHandle() = 0;
43
[email protected]876f6fee2010-08-02 23:10:3244 // Returns whether the current context supports the named extension. The
45 // context must be current.
46 virtual bool HasExtension(const char* name);
47
[email protected]30aa5c1a2010-07-14 20:47:0448 static bool InitializeOneOff();
49
[email protected]4bedba72010-04-20 22:08:5450#if !defined(OS_MACOSX)
51 // Create a GL context that renders directly to a view.
52 static GLContext* CreateViewGLContext(gfx::PluginWindowHandle window,
53 bool multisampled);
54#endif
55
56 // Create a GL context used for offscreen rendering. It is initially backed by
57 // a 1x1 pbuffer. Use it to create an FBO to do useful rendering.
[email protected]dc57aa982010-06-15 21:54:0258 // |share_context|, if non-NULL, is a context which the internally created
59 // OpenGL context shares textures and other resources.
[email protected]b9363b22010-06-09 22:06:1560 static GLContext* CreateOffscreenGLContext(GLContext* shared_context);
[email protected]d37231fa2010-04-09 21:16:0261
[email protected]2f2d7042010-04-14 21:45:5862 protected:
63 bool InitializeCommon();
64
[email protected]d37231fa2010-04-09 21:16:0265 private:
66 DISALLOW_COPY_AND_ASSIGN(GLContext);
67};
68
[email protected]5a6db6c2010-04-22 18:32:0669} // namespace gfx
[email protected]d37231fa2010-04-09 21:16:0270
[email protected]5a6db6c2010-04-22 18:32:0671#endif // APP_GFX_GL_GL_CONTEXT_H_