root/trunk/RBRapier/RBRapier/Renderer/Appearance/Blending.py

Revision 702, 5.5 kB (checked in by sholloway, 5 years ago)

Added GL prefix to Execute/Select/Deselect

Line 
1 #!/usr/bin/env python
2 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 ##~ License
4 ##~
5 ##- The RuneBlade Foundation library is intended to ease some
6 ##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.)
7 ##- applications, while providing the flexibility to modularly change the
8 ##- architecture. Enjoy.
9 ##~
10 ##~ Copyright (C) 2002  TechGame Networks, LLC.
11 ##~
12 ##~ This library is free software; you can redistribute it and/or
13 ##~ modify it under the terms of the BSD style License as found in the
14 ##~ LICENSE file included with this distribution.
15 ##~
16 ##~ TechGame Networks, LLC can be reached at:
17 ##~ 3578 E. Hartsel Drive #211
18 ##~ Colorado Springs, Colorado, USA, 80920
19 ##~
20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21
22 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 #~ Imports
24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
26 from OpenGL import GL
27
28 from RBFoundation.Objects.Properties import LazyProperty
29
30 from RBRapier.Renderer.AttributeMgr import AttributeChangeElement
31 from RBRapier.Tools import Vector
32
33 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34 #~ Definitions
35 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
37 class Blend(object):
38     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39     #~ Constants / Variables / Etc.
40     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41
42     AttributeChange = AttributeChangeElement(GL.GL_COLOR_BUFFER_BIT)
43     SourceFactor = GL.GL_SRC_ALPHA
44     DestinationFactor = GL.GL_ONE_MINUS_SRC_ALPHA
45
46     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47     #~ Public Methods
48     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49
50     def __init__(self, SourceFactor=GL.GL_SRC_ALPHA, DestinationFactor=GL.GL_ONE_MINUS_SRC_ALPHA):
51         self.SourceFactor = SourceFactor
52         self.DestinationFactor = DestinationFactor
53
54     def GLSelect(self, context):
55         context.StateMgr.Enable(GL.GL_BLEND)
56         GL.glBlendFunc(self.SourceFactor, self.DestinationFactor)
57
58     def GLDeselect(self, context):
59         context.StateMgr.Disable(GL.GL_BLEND)
60
61 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62
63 class BlendSeperateAlpha(Blend):
64     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65     #~ Constants / Variables / Etc.
66     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67
68     SourceAlphaFactor = None
69     DestinationAlphaFactor = None
70
71     class _Extensions(object):
72         def __init__(self):
73             from OpenGL.GL.EXT import blend_func_separate
74             self.blend_func_separate = blend_func_separate.glInitBlendFuncSeparateEXT() and blend_func_separate or None
75     _extensions = LazyProperty(_Extensions)
76
77     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78     #~ Public Methods
79     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80
81     def __init__(self, SourceFactor=GL.GL_SRC_ALPHA, SourceAlphaFactor=None, DestinationFactor=GL.GL_ONE_MINUS_SRC_ALPHA, DestinationAlphaFactor=None):
82         self.SourceFactor = SourceFactor
83         self.SourceAlphaFactor = SourceAlphaFactor
84         self.DestinationFactor = DestinationFactor
85         self.DestinationAlphaFactor = DestinationAlphaFactor
86
87     def GLSelect(self, context):
88         SourceAlphaFactor = self.SourceAlphaFactor
89         if SourceAlphaFactor is None: SourceAlphaFactor = self.SourceFactor
90         DestinationAlphaFactor = self.DestinationAlphaFactor
91         if DestinationAlphaFactor is None: DestinationAlphaFactor = self.DestinationFactor
92
93         context.StateMgr.Enable(GL.GL_BLEND)
94         ex = self._extensions.blend_func_separate
95         ex.glBlendFuncSeparateEXT(self.SourceFactor, SourceAlphaFactor, self.DestinationFactor, DestinationAlphaFactor)
96
97 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98
99 class BlendConstant(object):
100     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101     #~ Title
102     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103
104     AttributeChange = AttributeChangeElement(GL.GL_COLOR_BUFFER_BIT)
105     Constant = Vector.ColorVectorProperty('BlendConstant', (1., 1., 1., 1.))
106
107     class _Extensions(object):
108         def __init__(self):
109             from OpenGL.GL.EXT import blend_color
110             self.blend_color = blend_color.glInitBlendColorEXT() and blend_color or None
111     _extensions = LazyProperty(_Extensions)
112
113     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114     #~ Public Methods
115     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116
117     def __init__(self, constant=None):
118         if constant is not None:
119             self.Constant = constant
120
121     def GLSelect(self, context):
122         ex = self._extensions.blend_color
123         ex.glBlendColorEXT(*self.Constant.tolist())
124
125 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
126
127 class BlendEquation(object):
128     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129     #~ Constants / Variables / Etc.
130     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131
132     AttributeChange = AttributeChangeElement(GL.GL_COLOR_BUFFER_BIT)
133     Equation = None
134
135     class _Extensions(object):
136         def __init__(self):
137             from OpenGL.GL.EXT import blend_minmax
138             self.blend_minmax = blend_minmax.glInitBlendMinmaxEXT() and blend_minmax or None
139     _extensions = LazyProperty(_Extensions)
140
141     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142     #~ Public Methods
143     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
144
145     def __init__(self, Equation):
146         self.Equation = Equation
147
148     def GLSelect(self, context):
149         ex = self._extensions.blend_minmax
150         ex.glBlendEquationEXT(self.Equation)
151
Note: See TracBrowser for help on using the browser.