Add more structure constructor tests.
[piglit/hramrach.git] / tests / glean / codedid.h
blobb7bbc0665fdf7d3f6e6e25d92578707d48efbd51
1 // BEGIN_COPYRIGHT -*- glean -*-
2 //
3 // Copyright (C) 2000 Allen Akin All Rights Reserved.
4 //
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
12 // conditions:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the
16 // Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
26 //
27 // END_COPYRIGHT
31 // codedid.h: tool to map integer IDs into colors, and vice-versa
33 // A note on principles of operation: The OpenGL spec normally allows
34 // a reasonable amount of slop when converting user-specified colors
35 // to a hardware-dependent representation in the framebuffer. One
36 // exception to this lenience is when lighting is disabled and the
37 // color is specified as an unsigned byte, short, or int. In this
38 // case the conversion from user-supplied color to hardware-determined
39 // color must be exact, up to the number of bits in the framebuffer or
40 // in the value supplied by the user (whichever is smaller). This is
41 // intended to allow object identification numbers to be encoded as
42 // colors, so that applications can implement object selection by
43 // drawing objects and reading back the image to determine the object
44 // ID of the closest visible object. glean uses this property in a
45 // number of cases, for example, where it needs to draw a large number
46 // of primitives and verify that all of them were actually drawn. See
47 // the OpenGL spec, version 1.2.1, section 2.13.9 (page 55) for the
48 // description of this convertibility requirement.
50 #ifndef __codedid_h__
51 #define __codedid_h__
53 using namespace std;
55 #include <vector>
56 #include "glwrap.h"
58 namespace GLEAN {
60 class Image; // forward reference
62 class RGBCodedID {
63 int rBits, gBits, bBits; // number of signif. bits in channels
64 int nsRBits, nsGBits, nsBBits; // non-significant bits in each
65 int rMask, gMask, bMask; // masks for significant bits in each
66 public:
67 RGBCodedID(int r, int g, int b);
68 ~RGBCodedID();
70 // Return the maximum ID number that the caller can use:
71 int maxID() const;
73 // Map an ID number to an RGB triple:
74 void toRGB(int id, GLubyte& r, GLubyte& g, GLubyte& b) const;
76 // Map an RGB triple to the equivalent ID number:
77 int toID(GLubyte r, GLubyte g, GLubyte b) const;
79 // Histogram an UNSIGNED_BYTE RGB image:
80 void histogram(Image& img, vector<int>& hist) const;
82 // Are all of a range of IDs present in an RGB image?
83 bool allPresent(Image& img, int first, int last) const;
85 }; // RGBCodedID
87 // XXX Might want an IndexCodedID class for use with color index drawing
88 // surfaces, even though such a class would be trivial.
90 } // namespace GLEAN
92 #endif // __codedid_h__