bump product version to 6.4.0.3
[LibreOffice.git] / vcl / inc / opengl / RenderState.hxx
blob3a89344e2e0e124f17646bad06afb0636d5d899a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #ifndef INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H
12 #define INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H
14 #include <opengl/TextureState.hxx>
16 template<GLenum ENUM_TYPE, typename TYPE>
17 class GenericCapabilityState
19 protected:
20 bool mbTest;
22 GenericCapabilityState()
23 : mbTest(false)
27 static bool readState()
29 return glIsEnabled(ENUM_TYPE);
32 public:
33 void sync()
35 mbTest = readState();
38 void enable()
40 if (!mbTest)
42 glEnable(ENUM_TYPE);
43 CHECK_GL_ERROR();
44 mbTest = true;
46 else
48 VCL_GL_INFO(TYPE::className() << ": enable called but already enabled");
50 #ifdef DBG_UTIL
51 checkState();
52 #endif
55 void disable()
57 if (mbTest)
59 glDisable(ENUM_TYPE);
60 CHECK_GL_ERROR();
61 mbTest = false;
63 else
65 VCL_GL_INFO(TYPE::className() << ": disable called but already disabled");
67 #ifdef DBG_UTIL
68 checkState();
69 #endif
72 #ifdef DBG_UTIL
73 void checkState()
75 bool bRealState = readState();
76 if (mbTest != bRealState)
78 VCL_GL_INFO(TYPE::className() << " mismatch! "
79 << "Expected: " << (mbTest ? "enabled" : "disabled")
80 << " but is: " << (bRealState ? "enabled" : "disabled"));
83 #endif
86 class ScissorState : public GenericCapabilityState<GL_SCISSOR_TEST, ScissorState>
88 private:
89 int mX;
90 int mY;
91 int mWidth;
92 int mHeight;
94 public:
95 static std::string className() { return std::string("ScissorState"); }
97 ScissorState()
98 : mX(0)
99 , mY(0)
100 , mWidth(0)
101 , mHeight(0)
104 void set(int x, int y, int width, int height)
106 if (x != mX || y != mY || width != mWidth || height != mHeight)
108 glScissor(x, y, width, height);
109 CHECK_GL_ERROR();
111 mX = x;
112 mY = y;
113 mWidth = width;
114 mHeight = height;
119 class StencilState : public GenericCapabilityState<GL_STENCIL_TEST, StencilState>
121 public:
122 static std::string className() { return std::string("StencilState"); }
125 class BlendState : public GenericCapabilityState<GL_BLEND, BlendState>
127 GLenum mnSourceMode;
128 GLenum mnDestinationMode;
129 public:
130 BlendState()
131 : mnSourceMode(GL_ZERO)
132 , mnDestinationMode(GL_ZERO)
135 static std::string className() { return std::string("BlendState"); }
137 void func(GLenum nSource, GLenum nDestination)
139 if (mnSourceMode != nSource || mnDestinationMode != nDestination)
141 glBlendFunc(nSource, nDestination);
142 CHECK_GL_ERROR();
143 mnSourceMode = nSource;
144 mnDestinationMode = nDestination;
149 class RenderState
151 TextureState maTexture;
152 ScissorState maScissor;
153 StencilState maStencil;
154 BlendState maBlend;
156 tools::Rectangle maCurrentViewport;
158 public:
159 RenderState()
162 void viewport(tools::Rectangle aViewPort)
164 if (aViewPort != maCurrentViewport)
166 glViewport(aViewPort.Left(), aViewPort.Top(), aViewPort.GetWidth(), aViewPort.GetHeight());
167 CHECK_GL_ERROR();
168 maCurrentViewport = aViewPort;
172 TextureState& texture() { return maTexture; }
173 ScissorState& scissor() { return maScissor; }
174 StencilState& stencil() { return maStencil; }
175 BlendState& blend() { return maBlend; }
177 void sync()
179 VCL_GL_INFO("RenderState::sync");
180 maScissor.sync();
181 maStencil.sync();
182 maBlend.sync();
186 #endif // INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */