OSDN Git Service

[更新]NyARToolkit/nyatlaブランチ
[nyartoolkit-and/nyartoolkit-and.git] / branches / nyatla / src.utils / jogl / jp / nyatla / nyartoolkit / jogl / utils / GLNyARRaster_RGB.java
1 /* \r
2  * PROJECT: NyARToolkit\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.jmf.utils.*;\r
38 import jp.nyatla.nyartoolkit.core.*;\r
39 import jp.nyatla.nyartoolkit.core.raster.TNyRasterType;\r
40 \r
41 /**\r
42  * NyARRaster_RGBにOpenGL用のデータ変換機能を追加したものです。\r
43  */\r
44 public class GLNyARRaster_RGB extends JmfNyARRaster_RGB\r
45 {\r
46         private byte[] _gl_buf;\r
47 \r
48         private int _gl_flag;\r
49 \r
50         public GLNyARRaster_RGB(NyARParam i_param)\r
51         {\r
52                 super(i_param.getX(), i_param.getY());\r
53                 this._gl_flag = GL.GL_RGB;\r
54                 this._gl_buf = new byte[this._size.w * this._size.h * 3];\r
55         }\r
56 \r
57         public void setBuffer(javax.media.Buffer i_buffer, boolean i_is_reverse) throws NyARException\r
58         {\r
59                 int buffer_type=analyzeBufferType((RGBFormat) i_buffer.getFormat());;\r
60                 byte[] src_buf = (byte[]) i_buffer.getData();\r
61                 // GL用のデータを準備\r
62                 if (i_is_reverse) {\r
63                         final int length = this._size.w * 3;\r
64                         int src_idx = 0;\r
65                         int dest_idx = (this._size.h - 1) * length;                     \r
66                         for (int i = 0; i < this._size.h; i++) {\r
67                                 System.arraycopy(src_buf, src_idx, this._gl_buf, dest_idx, length);\r
68                                 src_idx += length;\r
69                                 dest_idx -= length;\r
70                         }\r
71                 } else {\r
72                         System.arraycopy(src_buf, 0, this._gl_buf, 0, src_buf.length);\r
73                 }\r
74 \r
75                 // GLのフラグ設定\r
76                 switch (buffer_type) {\r
77                 case TNyRasterType.BUFFERFORMAT_BYTE1D_B8G8R8_24:\r
78                         this._gl_flag = GL.GL_BGR;\r
79                         break;\r
80                 case TNyRasterType.BUFFERFORMAT_BYTE1D_R8G8B8_24:\r
81                         this._gl_flag = GL.GL_RGB;\r
82                         break;\r
83                 default:\r
84                         throw new NyARException();\r
85                 }\r
86                 // ref_bufをgl_bufに差し替える\r
87                 this._buffer_type = buffer_type;\r
88                 this._ref_buf = this._gl_buf;\r
89                 this._reader.changeBuffer(this._buffer_type, this._ref_buf);\r
90         }\r
91 \r
92         /**\r
93          * GLでそのまま描画できるRGBバッファを返す。\r
94          * \r
95          * @return\r
96          */\r
97         public byte[] getGLRgbArray()\r
98         {\r
99                 return this._ref_buf;\r
100         }\r
101 \r
102         /**\r
103          * GL用のRGBバッファのバイト並びタイプを返す。\r
104          * \r
105          * @return\r
106          */\r
107         public int getGLPixelFlag()\r
108         {\r
109                 return this._gl_flag;\r
110         }\r
111 }\r