123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- // Copyright (c) 2012 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #ifndef UI_GL_SCOPED_BINDERS_H_
- #define UI_GL_SCOPED_BINDERS_H_
- #include "base/memory/raw_ptr.h"
- #include "ui/gl/gl_export.h"
- namespace gl {
- class GLStateRestorer;
- class GL_EXPORT ScopedFramebufferBinder {
- public:
- explicit ScopedFramebufferBinder(unsigned int fbo);
- ScopedFramebufferBinder(const ScopedFramebufferBinder&) = delete;
- ScopedFramebufferBinder& operator=(const ScopedFramebufferBinder&) = delete;
- ~ScopedFramebufferBinder();
- private:
- // Whenever possible we prefer to use the current GLContext's
- // GLStateRestorer to maximize driver compabitility.
- raw_ptr<GLStateRestorer> state_restorer_;
- // Failing that we use GL calls to save and restore state.
- int old_fbo_;
- };
- class GL_EXPORT ScopedActiveTexture {
- public:
- ScopedActiveTexture(unsigned int texture);
- ScopedActiveTexture(const ScopedActiveTexture&) = delete;
- ScopedActiveTexture& operator=(const ScopedActiveTexture&) = delete;
- ~ScopedActiveTexture();
- private:
- // Whenever possible we prefer to use the current GLContext's
- // GLStateRestorer to maximize driver compabitility.
- raw_ptr<GLStateRestorer> state_restorer_;
- // Failing that we use GL calls to save and restore state.
- int old_texture_;
- };
- class GL_EXPORT ScopedTextureBinder {
- public:
- ScopedTextureBinder(unsigned int target, unsigned int id);
- ScopedTextureBinder(const ScopedTextureBinder&) = delete;
- ScopedTextureBinder& operator=(const ScopedTextureBinder&) = delete;
- ~ScopedTextureBinder();
- private:
- // Whenever possible we prefer to use the current GLContext's
- // GLStateRestorer to maximize driver compabitility.
- raw_ptr<GLStateRestorer> state_restorer_;
- // Failing that we use GL calls to save and restore state.
- int target_;
- int old_id_;
- };
- class GL_EXPORT ScopedUseProgram {
- public:
- ScopedUseProgram(unsigned int program);
- ScopedUseProgram(const ScopedUseProgram&) = delete;
- ScopedUseProgram& operator=(const ScopedUseProgram&) = delete;
- ~ScopedUseProgram();
- private:
- // Whenever possible we prefer to use the current GLContext's
- // GLStateRestorer to maximize driver compabitility.
- raw_ptr<GLStateRestorer> state_restorer_;
- // Failing that we use GL calls to save and restore state.
- int old_program_;
- };
- class GL_EXPORT ScopedVertexAttribArray {
- public:
- ScopedVertexAttribArray(unsigned int index,
- int size,
- unsigned int type,
- char normalized,
- int stride,
- const void* pointer);
- ScopedVertexAttribArray(const ScopedVertexAttribArray&) = delete;
- ScopedVertexAttribArray& operator=(const ScopedVertexAttribArray&) = delete;
- ~ScopedVertexAttribArray();
- private:
- // Whenever possible we prefer to use the current GLContext's
- // GLStateRestorer to maximize driver compabitility.
- raw_ptr<GLStateRestorer> state_restorer_;
- // Failing that we use GL calls to save and restore state.
- int buffer_;
- int enabled_;
- int index_;
- int size_;
- int type_;
- int normalized_;
- int stride_;
- void* pointer_;
- };
- class GL_EXPORT ScopedBufferBinder {
- public:
- ScopedBufferBinder(unsigned int target, unsigned int index);
- ScopedBufferBinder(const ScopedBufferBinder&) = delete;
- ScopedBufferBinder& operator=(const ScopedBufferBinder&) = delete;
- ~ScopedBufferBinder();
- private:
- // Whenever possible we prefer to use the current GLContext's
- // GLStateRestorer to maximize driver compabitility.
- raw_ptr<GLStateRestorer> state_restorer_;
- // Failing that we use GL calls to save and restore state.
- int target_;
- int old_id_;
- };
- class GL_EXPORT ScopedViewport {
- public:
- ScopedViewport(int x, int y, int width, int height);
- ScopedViewport(const ScopedViewport&) = delete;
- ScopedViewport& operator=(const ScopedViewport&) = delete;
- ~ScopedViewport();
- private:
- int data_[4] = {};
- };
- class GL_EXPORT ScopedVertexAttribPointer {
- public:
- ScopedVertexAttribPointer(unsigned index,
- int size,
- unsigned type,
- char normalized,
- int stride,
- const void* pointer);
- ScopedVertexAttribPointer(const ScopedVertexAttribPointer&) = delete;
- ScopedVertexAttribPointer& operator=(const ScopedVertexAttribPointer&) =
- delete;
- ~ScopedVertexAttribPointer();
- };
- class GL_EXPORT ScopedColorMask {
- public:
- ScopedColorMask(char red, char green, char blue, char alpha);
- ScopedColorMask(const ScopedColorMask&) = delete;
- ScopedColorMask& operator=(const ScopedColorMask&) = delete;
- ~ScopedColorMask();
- private:
- unsigned char colors_[4] = {};
- };
- class GL_EXPORT ScopedCapability {
- public:
- ScopedCapability(unsigned capability, unsigned char enabled);
- ScopedCapability(const ScopedCapability&) = delete;
- ScopedCapability& operator=(const ScopedCapability&) = delete;
- ~ScopedCapability();
- private:
- unsigned capability_;
- unsigned char enabled_;
- };
- } // namespace gl
- #endif // UI_GL_SCOPED_BINDERS_H_
|