OSDN Git Service

f468244aa67d51ed1dafcee81d83e0a1d20710bf
[android-x86/external-swiftshader.git] / src / Radiance / libRAD / Fence.cpp
1 // SwiftShader Software Renderer\r
2 //\r
3 // Copyright(c) 2005-2012 TransGaming Inc.\r
4 //\r
5 // All rights reserved. No part of this software may be copied, distributed, transmitted,\r
6 // transcribed, stored in a retrieval system, translated into any human or computer\r
7 // language by any means, or disclosed to third parties without the explicit written\r
8 // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express\r
9 // or implied, including but not limited to any patent rights, are granted to you.\r
10 //\r
11 \r
12 // Fence.cpp: Implements the Fence class, which supports the GL_NV_fence extension.\r
13 \r
14 #include "Fence.h"\r
15 \r
16 #include "main.h"\r
17 #include "Common/Thread.hpp"\r
18 \r
19 namespace rad\r
20 {\r
21 \r
22 Fence::Fence()\r
23\r
24     mQuery = false;\r
25     mCondition = GL_NONE;\r
26     mStatus = GL_FALSE;\r
27 }\r
28 \r
29 Fence::~Fence()\r
30 {\r
31     mQuery = false;\r
32 }\r
33 \r
34 GLboolean Fence::isFence()\r
35 {\r
36     // GL_NV_fence spec:\r
37     // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an existing fence.\r
38     return mQuery;\r
39 }\r
40 \r
41 void Fence::setFence(GLenum condition)\r
42 {\r
43     mQuery = true;\r
44     mCondition = condition;\r
45     mStatus = GL_FALSE;\r
46 }\r
47 \r
48 GLboolean Fence::testFence()\r
49 {\r
50     if(!mQuery)\r
51     {\r
52         return error(GL_INVALID_OPERATION, GL_TRUE);\r
53     }\r
54 \r
55         UNIMPLEMENTED();\r
56     mStatus = GL_TRUE;\r
57 \r
58     return mStatus;\r
59 }\r
60 \r
61 void Fence::finishFence()\r
62 {\r
63     if(!mQuery)\r
64     {\r
65         return error(GL_INVALID_OPERATION);\r
66     }\r
67 \r
68     while(!testFence())\r
69     {\r
70         sw::Thread::yield();\r
71     }\r
72 }\r
73 \r
74 void Fence::getFenceiv(GLenum pname, GLint *params)\r
75 {\r
76     if(!mQuery)\r
77     {\r
78         return error(GL_INVALID_OPERATION);\r
79     }\r
80 \r
81     switch (pname)\r
82     {\r
83     case GL_FENCE_STATUS_NV:\r
84                 {\r
85                         // GL_NV_fence spec:\r
86                         // Once the status of a fence has been finished (via FinishFenceNV) or tested and the returned status is TRUE (via either TestFenceNV\r
87                         // or GetFenceivNV querying the FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.\r
88                         if(mStatus)\r
89                         {\r
90                                 params[0] = GL_TRUE;\r
91                                 return;\r
92                         }\r
93             \r
94                         mStatus = testFence();\r
95 \r
96                         params[0] = mStatus;            \r
97                         break;\r
98                 }\r
99     case GL_FENCE_CONDITION_NV:\r
100         params[0] = mCondition;\r
101         break;\r
102     default:\r
103         return error(GL_INVALID_ENUM);\r
104         break;\r
105     }\r
106 }\r
107 \r
108 }\r