1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
22 GenericCapabilityState()
27 static bool readState()
29 return glIsEnabled(ENUM_TYPE
);
48 VCL_GL_INFO(TYPE::className() << ": enable called but already enabled");
65 VCL_GL_INFO(TYPE::className() << ": disable called but already disabled");
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"));
86 class ScissorState
: public GenericCapabilityState
<GL_SCISSOR_TEST
, ScissorState
>
95 static std::string
className() { return std::string("ScissorState"); }
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
);
119 class StencilState
: public GenericCapabilityState
<GL_STENCIL_TEST
, StencilState
>
122 static std::string
className() { return std::string("StencilState"); }
125 class BlendState
: public GenericCapabilityState
<GL_BLEND
, BlendState
>
128 GLenum mnDestinationMode
;
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
);
143 mnSourceMode
= nSource
;
144 mnDestinationMode
= nDestination
;
151 TextureState maTexture
;
152 ScissorState maScissor
;
153 StencilState maStencil
;
156 tools::Rectangle maCurrentViewport
;
162 void viewport(tools::Rectangle aViewPort
)
164 if (aViewPort
!= maCurrentViewport
)
166 glViewport(aViewPort
.Left(), aViewPort
.Top(), aViewPort
.GetWidth(), aViewPort
.GetHeight());
168 maCurrentViewport
= aViewPort
;
172 TextureState
& texture() { return maTexture
; }
173 ScissorState
& scissor() { return maScissor
; }
174 StencilState
& stencil() { return maStencil
; }
175 BlendState
& blend() { return maBlend
; }
179 VCL_GL_INFO("RenderState::sync");
186 #endif // INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */