1 | /****************************************************************************** |
---|
2 | * SAGE - Scalable Adaptive Graphics Environment |
---|
3 | * |
---|
4 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
5 | * University of Illinois at Chicago |
---|
6 | * |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above |
---|
15 | * copyright notice, this list of conditions and the following disclaimer |
---|
16 | * in the documentation and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the University of Illinois at Chicago nor |
---|
18 | * the names of its contributors may be used to endorse or promote |
---|
19 | * products derived from this software without specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
25 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | * |
---|
33 | * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/ |
---|
34 | * |
---|
35 | *****************************************************************************/ |
---|
36 | #include "sail.h" |
---|
37 | |
---|
38 | #include <stdio.h> |
---|
39 | #include <stdlib.h> |
---|
40 | #include <string.h> |
---|
41 | #include <math.h> |
---|
42 | #include <assert.h> |
---|
43 | |
---|
44 | #include <CoreFoundation/CoreFoundation.h> |
---|
45 | #include <ApplicationServices/ApplicationServices.h> |
---|
46 | #include <OpenGL/OpenGL.h> |
---|
47 | #include <OpenGL/gl.h> |
---|
48 | #include <OpenGL/glext.h> |
---|
49 | #include <Carbon/Carbon.h> |
---|
50 | |
---|
51 | #include <sys/time.h> |
---|
52 | |
---|
53 | #include "libdxt.h" |
---|
54 | |
---|
55 | // #define WW 1920 |
---|
56 | // #define HH 1200 |
---|
57 | |
---|
58 | #define WW 1440 |
---|
59 | #define HH 900 |
---|
60 | |
---|
61 | //#define WW 1024 |
---|
62 | //#define HH 768 |
---|
63 | |
---|
64 | |
---|
65 | // headers for SAGE |
---|
66 | #include "misc.h" |
---|
67 | int winWidth, winHeight; |
---|
68 | GLubyte *rgbBuffer = 0; |
---|
69 | GLubyte *dxtBuffer = 0; |
---|
70 | sail sageInf; // sail object |
---|
71 | |
---|
72 | int capture(char* m_pFrameRGB,int x,int y,int cx,int cy) |
---|
73 | { |
---|
74 | CGLContextObj glContextObj = 0; |
---|
75 | CGLPixelFormatObj pixelFormatObj ; |
---|
76 | GLint numPixelFormats ; |
---|
77 | CGDirectDisplayID displayId=CGMainDisplayID(); |
---|
78 | CGOpenGLDisplayMask displayMask = |
---|
79 | CGDisplayIDToOpenGLDisplayMask(displayId); |
---|
80 | |
---|
81 | CGLPixelFormatAttribute attribs[] = |
---|
82 | { |
---|
83 | (CGLPixelFormatAttribute)kCGLPFAFullScreen, |
---|
84 | (CGLPixelFormatAttribute)kCGLPFADisplayMask, |
---|
85 | (CGLPixelFormatAttribute)displayMask, |
---|
86 | (CGLPixelFormatAttribute)0 |
---|
87 | }; |
---|
88 | CGLChoosePixelFormat( attribs, &pixelFormatObj, &numPixelFormats ); |
---|
89 | CGLCreateContext( pixelFormatObj, NULL, &glContextObj ) ; |
---|
90 | CGLDestroyPixelFormat( pixelFormatObj ) ; |
---|
91 | CGLSetCurrentContext( glContextObj ) ; |
---|
92 | CGLSetFullScreen( glContextObj ) ;///UUUUUUUUUUnbelievable |
---|
93 | |
---|
94 | glReadBuffer(GL_FRONT); |
---|
95 | glReadPixels(x,y,cx,cy,GL_RGBA,GL_UNSIGNED_BYTE,m_pFrameRGB); |
---|
96 | |
---|
97 | CGLSetCurrentContext( NULL ); |
---|
98 | CGLClearDrawable( glContextObj ); |
---|
99 | CGLDestroyContext( glContextObj ); |
---|
100 | return true; |
---|
101 | } |
---|
102 | |
---|
103 | int |
---|
104 | main(int argc, char **argv) |
---|
105 | { |
---|
106 | int ret; |
---|
107 | bool done; |
---|
108 | double rate, fps; |
---|
109 | double t1, t2; |
---|
110 | |
---|
111 | // Initialize some timing functions and else (DXT) |
---|
112 | aInitialize(); |
---|
113 | |
---|
114 | |
---|
115 | sageRect ishareImageMap; |
---|
116 | ishareImageMap.left = 0.0; |
---|
117 | ishareImageMap.right = 1.0; |
---|
118 | ishareImageMap.bottom = 0.0; |
---|
119 | ishareImageMap.top = 1.0; |
---|
120 | |
---|
121 | sailConfig scfg; |
---|
122 | scfg.init("ishare.conf"); |
---|
123 | scfg.setAppName("ishare"); |
---|
124 | scfg.rank = 0; |
---|
125 | |
---|
126 | scfg.resX = WW; |
---|
127 | scfg.resY = HH; |
---|
128 | scfg.winWidth = WW; |
---|
129 | scfg.winHeight = HH; |
---|
130 | scfg.imageMap = ishareImageMap; |
---|
131 | scfg.pixFmt = PIXFMT_DXT; // PIXFMT_888; |
---|
132 | scfg.rowOrd = BOTTOM_TO_TOP; |
---|
133 | scfg.master = true; |
---|
134 | |
---|
135 | sageInf.init(scfg); |
---|
136 | |
---|
137 | std::cout << "sail initialized " << std::endl; |
---|
138 | |
---|
139 | dxtBuffer = (GLubyte *)sageInf.getBuffer(); |
---|
140 | rgbBuffer = (byte*)memalign(16, WW*HH*4); |
---|
141 | memset(rgbBuffer, 0, WW*HH*4); |
---|
142 | |
---|
143 | rate = 15.0; |
---|
144 | |
---|
145 | done = false; |
---|
146 | while (not done) |
---|
147 | { |
---|
148 | t1 = sage::getTime(); |
---|
149 | |
---|
150 | ret = capture((char*)rgbBuffer,0,0,WW,HH); |
---|
151 | |
---|
152 | CompressDXT(rgbBuffer, dxtBuffer, WW, HH, FORMAT_DXT1, 2); |
---|
153 | |
---|
154 | sageInf.swapBuffer(); |
---|
155 | |
---|
156 | sageMessage msg; |
---|
157 | if (sageInf.checkMsg(msg, false) > 0) { |
---|
158 | switch (msg.getCode()) { |
---|
159 | case APP_QUIT: |
---|
160 | done = true; |
---|
161 | break; |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | dxtBuffer = (GLubyte *)sageInf.getBuffer(); |
---|
166 | |
---|
167 | t2 = sage::getTime(); |
---|
168 | fps = (1000000.0/(t2-t1)); |
---|
169 | if (fps > rate) { |
---|
170 | sage::usleep( (1000000.0/rate) - (t2-t1) ); |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | } |
---|