Jogamp
Fix Window destroyNotify() -> QUIT
[users/sgothel/jake2.git] / src / jake2 / render / opengl / JoglES1Driver.java
CommitLineData
04d63492
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;
04d63492
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
39
40/**
41 * JoglCommon
42 */
43public abstract class JoglES1Driver extends JoglGL2ES1 implements GLDriver {
44
4c41dbb4
SG
45 protected static final GLProfile glp;
46 static {
47 // exception if GLProfile is n/a is desired
48 cvar_t v = Cvar.Get("jogl_gl2es1", "0", 0);
49 if( v.value != 0f ) {
50 glp = GLProfile.getGL2ES1();
51 } else {
52 glp = GLProfile.get(GLProfile.GLES1);
53 }
54 }
04d63492
SG
55
56 protected JoglES1Driver() {
28204694 57 super();
04d63492
SG
58 }
59
60 private NEWTWin newtWin = null;
61
62 public abstract String getName();
63
5611eeb8 64 public List<MonitorMode> getModeList() {
04d63492
SG
65 if(null == newtWin) {
66 throw new RuntimeException("NEWTWin not yet initialized.");
67 }
68 return newtWin.getModeList();
69 }
70
71 public int setMode(Dimension dim, int mode, boolean fullscreen) {
72 if(null == newtWin) {
73 newtWin = new NEWTWin();
74 }
75 int res = newtWin.setMode(glp, dim, mode, fullscreen, getName());
76 if( Base.rserr_ok == res ) {
04d63492
SG
77 setGL(newtWin.window.getGL().getGL2ES1());
78 init(0, 0);
79
80 return Base.rserr_ok;
81 }
82 return res;
83 }
84
85 public void shutdown() {
86 if(null != newtWin) {
87 newtWin.shutdown();
88 }
89 }
90
91 /**
92 * @return true
93 */
94 public boolean init(int xpos, int ypos) {
95 // clear the screen
96 // first buffer
97 beginFrame(0.0f);
98 glViewport(0, 0, newtWin.window.getWidth(), newtWin.window.getHeight());
99 glClearColor(0, 0, 0, 0);
100 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
101 endFrame();
102 // second buffer
103 beginFrame(0.0f);
104 glViewport(0, 0, newtWin.window.getWidth(), newtWin.window.getHeight());
105 glClearColor(0, 0, 0, 0);
106 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
107 endFrame();
108 return true;
109 }
110
111 public void beginFrame(float camera_separation) {
0d353c8b 112 newtWin.activateGLContext();
04d63492
SG
113 }
114
115 public void endFrame() {
c15865e0 116 newtWin.endFrame();
0e0ab268 117 // deactivate();
04d63492
SG
118 }
119
120 public void appActivate(boolean activate) {
121 // do nothing
122 }
123
124 public void enableLogging(boolean enable) {
125 // do nothing
126 }
127
128 public void logNewFrame() {
129 // do nothing
130 }
131
132 /*
133 * @see jake2.client.refexport_t#updateScreen()
134 */
135 public void updateScreen(xcommand_t callback) {
136 callback.execute();
137 }
138
0d353c8b
SG
139 protected final void activateGLContext() {
140 newtWin.activateGLContext();
04d63492 141 }
0d353c8b
SG
142
143 protected final void deactivateGLContext() {
144 newtWin.activateGLContext();
0e0ab268
SG
145 }
146
04d63492
SG
147 // --------------------------------------------------------------------------
148}
http://JogAmp.org git info: FAQ, tutorial and man pages.