• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _RSGUTILS_HPP
2 #define _RSGUTILS_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Random Shader Generator
5  * ----------------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "rsgDefs.hpp"
27 #include "rsgShader.hpp"
28 #include "rsgVariableValue.hpp"
29 #include "deRandom.hpp"
30 #include "rsgGeneratorState.hpp"
31 #include "deMath.h"
32 
33 #include <vector>
34 
35 namespace rsg
36 {
37 
38 void		computeUnifiedUniforms		(const Shader& vertexShader, const Shader& fragmentShader, std::vector<const ShaderInput*>& uniforms);
39 void		computeUniformValues		(de::Random& rnd, std::vector<VariableValue>& values, const std::vector<const ShaderInput*>& uniforms);
40 
41 // \todo [2011-03-26 pyry] Move to ExpressionUtils!
42 
43 bool			isUndefinedValueRange			(ConstValueRangeAccess valueRange);
44 
45 int				getConservativeValueExprDepth	(const GeneratorState& state, ConstValueRangeAccess valueRange);
46 int				getTypeConstructorDepth			(const VariableType& type);
47 
48 VariableType	computeRandomType				(GeneratorState& state, int maxScalars);
49 void			computeRandomValueRange			(GeneratorState& state, ValueRangeAccess valueRange);
50 
51 float			computeDynamicRangeWeight		(ConstValueRangeAccess valueRange);
52 
getQuantizedFloat(de::Random & rnd,float min,float max,float step)53 inline float getQuantizedFloat (de::Random& rnd, float min, float max, float step)
54 {
55 	int numSteps = (int)((max-min)/step);
56 	return min + step*rnd.getInt(0, numSteps);
57 }
58 
quantizeFloatRange(float & min,float & max)59 inline bool quantizeFloatRange (float& min, float& max)
60 {
61 	const float	subdiv = 8;
62 
63 	float newMin = deFloatCeil(min*subdiv)/subdiv;
64 	if (newMin <= max)
65 		min = newMin; // Minimum value quantized
66 	else
67 		return false;
68 
69 	float newMax = deFloatFloor(max*subdiv)/subdiv;
70 	if (min <= newMax)
71 		max = newMax;
72 	else
73 		return false;
74 
75 	return true;
76 }
77 
78 } // rsg
79 
80 #endif // _RSGUTILS_HPP
81