root/trunk/RBRapier/RBRapier/Renderer/Environment/FragmentTests.py

Revision 704, 4.2 kB (checked in by sholloway, 5 years ago)

*** empty log message ***

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 from RBRapier.Tools import ViewBox
30 from RBRapier.Renderer.AttributeMgr import AttributeChangeElement
31
32 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33 #~ Definitions
34 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35
36 class ScissorTest(object):
37     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38     #~ Constants / Variables / Etc.
39     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40
41     AttributeChange = AttributeChangeElement(GL.GL_SCISSOR_BIT)
42     Box = LazyProperty(ViewBox)
43
44     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45     #~ Public Methods
46     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47
48     def GLSelect(self, context):
49         rectangle = map(int, self.Box.GetRectangle())
50         GL.glScissor(*rectangle)
51         context.StateMgr.Enable(GL.GL_SCISSOR_TEST)
52
53     def GLDeselect(self, context):
54         context.StateMgr.Disable(GL.GL_SCISSOR_TEST)
55
56 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57
58 class AlphaTest(object):
59     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60     #~ Constants / Variables / Etc.
61     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62
63     AttributeChange = AttributeChangeElement(GL.GL_COLOR_BUFFER_BIT)
64     Function = GL.GL_ALWAYS
65
66     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67     #~ Public Methods
68     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69
70     def __init__(self, Function=GL.GL_ALWAYS):
71         self.Function = Function
72
73     def GLSelect(self, context):
74         GL.glAlphaFunc(self.Function)
75         context.StateMgr.Enable(GL.GL_ALPHA_TEST)
76
77     def GLDeselect(self, context):
78         context.StateMgr.Disable(GL.GL_ALPHA_TEST)
79
80 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81
82 class StencilTest(object):
83     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
84     #~ Constants / Variables / Etc.
85     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86
87     AttributeChange = AttributeChangeElement(GL.GL_STENCIL_BUFFER_BIT)
88     Function = GL.GL_ALWAYS
89     Operation = GL.GL_KEEP
90
91     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92     #~ Public Methods
93     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94
95     def __init__(self, Function=GL.GL_ALWAYS, Operation=GL.GL_KEEP):
96         self.Function = Function
97         self.Operation = Operation
98
99     def GLSelect(self, context):
100         GL.glStencilFunc(self.Function)
101         GL.glStencilOp(self.Operation)
102         context.StateMgr.Enable(GL.GL_STENCIL_TEST)
103
104     def GLDeselect(self, context):
105         context.StateMgr.Disable(GL.GL_STENCIL_TEST)
106
107 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108
109 class DepthTest(object):
110     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111     #~ Constants / Variables / Etc.
112     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113
114     AttributeChange = AttributeChangeElement(GL.GL_DEPTH_BUFFER_BIT)
115     Function = GL.GL_LESS
116
117     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118     #~ Public Methods
119     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120
121     def __init__(self, Function=GL.GL_LESS):
122         self.Function = Function
123
124     def GLSelect(self, context):
125         GL.glDepthFunc(self.Function)
126         context.StateMgr.Enable(GL.GL_DEPTH_TEST)
127
128     def GLDeselect(self, context):
129         context.StateMgr.Disable(GL.GL_DEPTH_TEST)
130
Note: See TracBrowser for help on using the browser.