Jogamp
Fix Window destroyNotify() -> QUIT
[users/sgothel/jake2.git] / src / jake2 / render / opengl / JoglES2Driver.java
CommitLineData
f5612e7d
SG
1/*
2 * JoglDriver.java
3 * Copyright (C) 2004
4 *
5 */
6/*
7Copyright (C) 1997-2001 Id Software, Inc.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 */
25
26package jake2.render.opengl;
27
0d353c8b
SG
28import java.util.List;
29
4c41dbb4
SG
30import jake2.game.cvar_t;
31import jake2.qcommon.Cvar;
f5612e7d
SG
32import jake2.qcommon.xcommand_t;
33import jake2.render.Base;
34
35import javax.media.nativewindow.util.Dimension;
36import javax.media.opengl.*;
37
5611eeb8 38import com.jogamp.newt.MonitorMode;
04d63492
SG
39import com.jogamp.opengl.util.glsl.fixedfunc.FixedFuncUtil;
40import com.jogamp.opengl.util.glsl.fixedfunc.ShaderSelectionMode;
f5612e7d
SG
41
42/**
43 * JoglCommon
44 */
04d63492 45public abstract class JoglES2Driver extends JoglGL2ES1 implements GLDriver {
f5612e7d 46
4c41dbb4
SG
47 protected static final GLProfile glp;
48 static {
49 // exception if GLProfile is n/a is desired
50 cvar_t v = Cvar.Get("jogl_gl2es2", "0", 0);
51 if( v.value != 0f ) {
52 glp = GLProfile.getGL2ES2();
53 } else {
54 glp = GLProfile.get(GLProfile.GLES2);
55 }
56 }
04d63492
SG
57
58 // protected static final ShaderSelectionMode shaderSelectionMode = ShaderSelectionMode.AUTO;
2cbb6243 59 protected static final ShaderSelectionMode shaderSelectionMode = ShaderSelectionMode.COLOR_TEXTURE2;
04d63492 60
f5612e7d 61 protected JoglES2Driver() {
28204694 62 super();
f5612e7d
SG
63 }
64
65 private NEWTWin newtWin = null;
66
04d63492
SG
67 public abstract String getName();
68
5611eeb8 69 public List<MonitorMode> getModeList() {
f5612e7d
SG
70 if(null == newtWin) {
71 throw new RuntimeException("NEWTWin not yet initialized.");
72 }
73 return newtWin.getModeList();
74 }
75
76 public int setMode(Dimension dim, int mode, boolean fullscreen) {
77 if(null == newtWin) {
78 newtWin = new NEWTWin();
79 }
04d63492 80 int res = newtWin.setMode(glp, dim, mode, fullscreen, getName());
f5612e7d 81 if( Base.rserr_ok == res ) {
04d63492 82 setGL( FixedFuncUtil.wrapFixedFuncEmul(newtWin.window.getGL(), shaderSelectionMode, null, true, false) );
f5612e7d
SG
83 init(0, 0);
84
85 return Base.rserr_ok;
86 }
87 return res;
88 }
89
90 public void shutdown() {
91 if(null != newtWin) {
92 newtWin.shutdown();
93 }
94 }
95
96 /**
97 * @return true
98 */
99 public boolean init(int xpos, int ypos) {
100 // clear the screen
101 // first buffer
102 beginFrame(0.0f);
103 glViewport(0, 0, newtWin.window.getWidth(), newtWin.window.getHeight());
104 glClearColor(0, 0, 0, 0);
105 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
106 endFrame();
107 // second buffer
108 beginFrame(0.0f);
109 glViewport(0, 0, newtWin.window.getWidth(), newtWin.window.getHeight());
110 glClearColor(0, 0, 0, 0);
111 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
112 endFrame();
113 return true;
114 }
115
116 public void beginFrame(float camera_separation) {
0d353c8b 117 activateGLContext();
f5612e7d
SG
118 }
119
120 public void endFrame() {
c15865e0 121 newtWin.endFrame();
0e0ab268 122 // deactivate();
f5612e7d
SG
123 }
124
125 public void appActivate(boolean activate) {
126 // do nothing
127 }
128
129 public void enableLogging(boolean enable) {
130 // do nothing
131 }
132
133 public void logNewFrame() {
134 // do nothing
135 }
136
137 /*
138 * @see jake2.client.refexport_t#updateScreen()
139 */
140 public void updateScreen(xcommand_t callback) {
141 callback.execute();
142 }
0e0ab268 143
0d353c8b
SG
144 protected final void activateGLContext() {
145 newtWin.activateGLContext();
0e0ab268 146 }
f5612e7d 147
0d353c8b
SG
148 protected final void deactivateGLContext() {
149 newtWin.activateGLContext();
150 }
151
f5612e7d
SG
152 // --------------------------------------------------------------------------
153}
http://JogAmp.org git info: FAQ, tutorial and man pages.