1 /*
2  * Copyright (c) 2002-2008 LWJGL Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of 'LWJGL' nor the names of
17  *   its contributors may be used to endorse or promote products derived
18  *   from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 package org.lwjgl.opengl;
33 
34 import java.nio.Buffer;
35 import java.util.Arrays;
36 
37 import static org.lwjgl.opengl.GL11.*;
38 import static org.lwjgl.opengl.GL13.*;
39 import static org.lwjgl.opengl.GL20.*;
40 
41 class BaseReferences {
42 
43 	int elementArrayBuffer;
44 	int arrayBuffer;
45 	final Buffer[] glVertexAttribPointer_buffer;
46 	final Buffer[] glTexCoordPointer_buffer;
47 	int glClientActiveTexture;
48 
49 	int vertexArrayObject;
50 
51 	int pixelPackBuffer;
52 	int pixelUnpackBuffer;
53 
54 	int indirectBuffer;
55 
BaseReferences(ContextCapabilities caps)56 	BaseReferences(ContextCapabilities caps) {
57 		int max_vertex_attribs;
58 		if ( caps.OpenGL20 || caps.GL_ARB_vertex_shader )
59 			max_vertex_attribs = glGetInteger(GL_MAX_VERTEX_ATTRIBS);
60 		else
61 			max_vertex_attribs = 0;
62 		glVertexAttribPointer_buffer = new Buffer[max_vertex_attribs];
63 
64 		int max_texture_units;
65 		if ( caps.OpenGL20 )
66 			max_texture_units = glGetInteger(GL_MAX_TEXTURE_IMAGE_UNITS);
67 		else if ( caps.OpenGL13 || caps.GL_ARB_multitexture )
68 			max_texture_units = glGetInteger(GL_MAX_TEXTURE_UNITS);
69 		else
70 			max_texture_units = 1;
71 		glTexCoordPointer_buffer = new Buffer[max_texture_units];
72 	}
73 
clear()74 	void clear() {
75 		this.elementArrayBuffer = 0;
76 		this.arrayBuffer = 0;
77 		this.glClientActiveTexture = 0;
78 		Arrays.fill(glVertexAttribPointer_buffer, null);
79 		Arrays.fill(glTexCoordPointer_buffer, null);
80 
81 		this.vertexArrayObject = 0;
82 
83 		this.pixelPackBuffer = 0;
84 		this.pixelUnpackBuffer = 0;
85 
86 		this.indirectBuffer = 0;
87 	}
88 
copy(BaseReferences references, int mask)89 	void copy(BaseReferences references, int mask) {
90 		if ( (mask & GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {
91 			this.elementArrayBuffer = references.elementArrayBuffer;
92 			this.arrayBuffer = references.arrayBuffer;
93 			this.glClientActiveTexture = references.glClientActiveTexture;
94 			System.arraycopy(references.glVertexAttribPointer_buffer, 0, glVertexAttribPointer_buffer, 0, glVertexAttribPointer_buffer.length);
95 			System.arraycopy(references.glTexCoordPointer_buffer, 0, glTexCoordPointer_buffer, 0, glTexCoordPointer_buffer.length);
96 
97 			this.vertexArrayObject = references.vertexArrayObject;
98 
99 			this.indirectBuffer = references.indirectBuffer;
100 		}
101 
102 		if ( (mask & GL_CLIENT_PIXEL_STORE_BIT) != 0 ) {
103 			this.pixelPackBuffer = references.pixelPackBuffer;
104 			this.pixelUnpackBuffer = references.pixelUnpackBuffer;
105 		}
106 	}
107 }
108