OSDN Git Service

1d28f27cb01ee2a7ce8f54af08961dfb9e739804
[nyartoolkit-and/nyartoolkit-and.git] / src.utils / jogl / jp / nyatla / nyartoolkit / jogl / utils / GLNyARRaster_RGB.java
1 /* \r
2  * PROJECT: NyARToolkit JOGL utilities.\r
3  * --------------------------------------------------------------------------------\r
4  * This work is based on the original ARToolKit developed by\r
5  *   Hirokazu Kato\r
6  *   Mark Billinghurst\r
7  *   HITLab, University of Washington, Seattle\r
8  * http://www.hitl.washington.edu/artoolkit/\r
9  *\r
10  * The NyARToolkit is Java version ARToolkit class library.\r
11  * Copyright (C)2008 R.Iizuka\r
12  *\r
13  * This program is free software; you can redistribute it and/or\r
14  * modify it under the terms of the GNU General Public License\r
15  * as published by the Free Software Foundation; either version 2\r
16  * of the License, or (at your option) any later version.\r
17  * \r
18  * This program is distributed in the hope that it will be useful,\r
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
21  * GNU General Public License for more details.\r
22  * \r
23  * You should have received a copy of the GNU General Public License\r
24  * along with this framework; if not, write to the Free Software\r
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
26  * \r
27  * For further information please contact.\r
28  *      http://nyatla.jp/nyatoolkit/\r
29  *      <airmail(at)ebony.plala.or.jp>\r
30  * \r
31  */\r
32 package jp.nyatla.nyartoolkit.jogl.utils;\r
33 \r
34 import javax.media.format.RGBFormat;\r
35 import javax.media.opengl.GL;\r
36 \r
37 import jp.nyatla.nyartoolkit.NyARException;\r
38 import jp.nyatla.nyartoolkit.jmf.utils.*;\r
39 import jp.nyatla.nyartoolkit.core.param.NyARParam;\r
40 import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
41 \r
42 \r
43 /**\r
44  * NyARRaster_RGBにOpenGL用のデータ変換機能を追加したものです。\r
45  */\r
46 public class GLNyARRaster_RGB extends JmfNyARRaster_RGB\r
47 {\r
48         private byte[] _gl_buf;\r
49 \r
50         private int _gl_flag;\r
51 \r
52         public GLNyARRaster_RGB(NyARParam i_param)\r
53         {\r
54                 super(i_param.getScreenSize());\r
55                 this._gl_flag = GL.GL_RGB;\r
56                 this._gl_buf = new byte[this._size.w * this._size.h * 3];\r
57         }\r
58 \r
59         public void setBuffer(javax.media.Buffer i_buffer, boolean i_is_reverse) throws NyARException\r
60         {\r
61                 int buffer_type=analyzeBufferType((RGBFormat) i_buffer.getFormat());;\r
62                 byte[] src_buf = (byte[]) i_buffer.getData();\r
63                 // GL用のデータを準備\r
64                 if (i_is_reverse) {\r
65                         final int length = this._size.w * 3;\r
66                         int src_idx = 0;\r
67                         int dest_idx = (this._size.h - 1) * length;                     \r
68                         for (int i = 0; i < this._size.h; i++) {\r
69                                 System.arraycopy(src_buf, src_idx, this._gl_buf, dest_idx, length);\r
70                                 src_idx += length;\r
71                                 dest_idx -= length;\r
72                         }\r
73                 } else {\r
74                         System.arraycopy(src_buf, 0, this._gl_buf, 0, src_buf.length);\r
75                 }\r
76 \r
77                 // GLのフラグ設定\r
78                 switch (buffer_type) {\r
79                 case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
80                         this._gl_flag = GL.GL_BGR;\r
81                         break;\r
82                 case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
83                         this._gl_flag = GL.GL_RGB;\r
84                         break;\r
85                 default:\r
86                         throw new NyARException();\r
87                 }\r
88                 // ref_bufをgl_bufに差し替える\r
89                 this._ref_buf = this._gl_buf;\r
90                 this._reader.changeBuffer(buffer_type, this._ref_buf);\r
91         }\r
92 \r
93         /**\r
94          * GLでそのまま描画できるRGBバッファを返す。\r
95          * \r
96          * @return\r
97          */\r
98         public byte[] getGLRgbArray()\r
99         {\r
100                 return this._ref_buf;\r
101         }\r
102 \r
103         /**\r
104          * GL用のRGBバッファのバイト並びタイプを返す。\r
105          * \r
106          * @return\r
107          */\r
108         public int getGLPixelFlag()\r
109         {\r
110                 return this._gl_flag;\r
111         }\r
112 }\r