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