<commit_before>/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.backends.gwt;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.HasArrayBufferView;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.util.HashMap;
import java.util.Map;

import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.google.gwt.core.client.GWT;
import com.google.gwt.typedarrays.client.Float32ArrayNative;
import com.google.gwt.typedarrays.client.Int16ArrayNative;
import com.google.gwt.typedarrays.client.Int32ArrayNative;
import com.google.gwt.typedarrays.client.Uint8ArrayNative;
import com.google.gwt.typedarrays.shared.Float32Array;
import com.google.gwt.typedarrays.shared.Int16Array;
import com.google.gwt.typedarrays.shared.Int32Array;
import com.google.gwt.typedarrays.shared.Uint8Array;
import com.google.gwt.webgl.client.WebGLActiveInfo;
import com.google.gwt.webgl.client.WebGLBuffer;
import com.google.gwt.webgl.client.WebGLFramebuffer;
import com.google.gwt.webgl.client.WebGLProgram;
import com.google.gwt.webgl.client.WebGLRenderbuffer;
import com.google.gwt.webgl.client.WebGLRenderingContext;
import com.google.gwt.webgl.client.WebGLShader;
import com.google.gwt.webgl.client.WebGLTexture;
import com.google.gwt.webgl.client.WebGLUniformLocation;

public class GwtGL20 implements GL20 {
	final Map<Integer, WebGLProgram> programs = new HashMap<Integer, WebGLProgram>();
	int nextProgramId = 1;
	final Map<Integer, WebGLShader> shaders = new HashMap<Integer, WebGLShader>();
	int nextShaderId = 1;
	final Map<Integer, WebGLBuffer> buffers = new HashMap<Integer, WebGLBuffer>();
	int nextBufferId = 1;
	final Map<Integer, WebGLFramebuffer> frameBuffers = new HashMap<Integer, WebGLFramebuffer>();
	int nextFrameBufferId = 1;
	final Map<Integer, WebGLRenderbuffer> renderBuffers = new HashMap<Integer, WebGLRenderbuffer>();
	int nextRenderBufferId = 1;
	final Map<Integer, WebGLTexture> textures = new HashMap<Integer, WebGLTexture>();
	int nextTextureId = 1;
	final Map<Integer, Map<Integer, WebGLUniformLocation>> uniforms = new HashMap<Integer, Map<Integer, WebGLUniformLocation>>();
	int nextUniformId = 1;
	int currProgram = 0;

	Float32Array floatBuffer = Float32ArrayNative.create(2000 * 20);
	Int32Array intBuffer = Int32ArrayNative.create(2000 * 6);
	Int16Array shortBuffer = Int16ArrayNative.create(2000 * 6);
	float[] floatArray = new float[16000];

	final WebGLRenderingContext gl;

	protected GwtGL20 (WebGLRenderingContext gl) {
		;
		this.gl = gl;
		this.gl.pixelStorei(WebGLRenderingContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
	}

	private void ensureCapacity (FloatBuffer buffer) {
		if (buffer.remaining() > floatBuffer.length()) {
			floatBuffer = Float32ArrayNative.create(buffer.remaining());
		}
	}

	private void ensureCapacity (ShortBuffer buffer) {
		if (buffer.remaining() > shortBuffer.length()) {
			shortBuffer = Int16ArrayNative.create(buffer.remaining());
		}
	}
	
	private void ensureCapacity (IntBuffer buffer) {
		if (buffer.remaining() > intBuffer.length()) {
			intBuffer = Int32ArrayNative.create(buffer.remaining());
		}
	}

	public Float32Array copy (FloatBuffer buffer) {
		if (GWT.isProdMode()) {
			return ((Float32Array)((HasArrayBufferView)buffer).getTypedArray()).subarray(buffer.position(), buffer.remaining());
		} else {
			ensureCapacity(buffer);
			for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) {
				floatBuffer.set(j, buffer.get(i));
			}
			return floatBuffer.subarray(0, buffer.remaining());
		}
	}

	public Int16Array copy (ShortBuffer buffer) {
		if (GWT.isProdMode()) {
			return ((Int16Array)((HasArrayBufferView)buffer).getTypedArray()).subarray(buffer.position(), buffer.remaining());
		} else {
			ensureCapacity(buffer);
			for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) {<commit_msg>Use the typed array factory methods<commit_after>/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.backends.gwt;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.HasArrayBufferView;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.util.HashMap;
import java.util.Map;

import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.google.gwt.core.client.GWT;
import com.google.gwt.typedarrays.client.Uint8ArrayNative;
import com.google.gwt.typedarrays.shared.Float32Array;
import com.google.gwt.typedarrays.shared.Int16Array;
import com.google.gwt.typedarrays.shared.Int32Array;
import com.google.gwt.typedarrays.shared.TypedArrays;
import com.google.gwt.typedarrays.shared.Uint8Array;
import com.google.gwt.webgl.client.WebGLActiveInfo;
import com.google.gwt.webgl.client.WebGLBuffer;
import com.google.gwt.webgl.client.WebGLFramebuffer;
import com.google.gwt.webgl.client.WebGLProgram;
import com.google.gwt.webgl.client.WebGLRenderbuffer;
import com.google.gwt.webgl.client.WebGLRenderingContext;
import com.google.gwt.webgl.client.WebGLShader;
import com.google.gwt.webgl.client.WebGLTexture;
import com.google.gwt.webgl.client.WebGLUniformLocation;

public class GwtGL20 implements GL20 {
	final Map<Integer, WebGLProgram> programs = new HashMap<Integer, WebGLProgram>();
	int nextProgramId = 1;
	final Map<Integer, WebGLShader> shaders = new HashMap<Integer, WebGLShader>();
	int nextShaderId = 1;
	final Map<Integer, WebGLBuffer> buffers = new HashMap<Integer, WebGLBuffer>();
	int nextBufferId = 1;
	final Map<Integer, WebGLFramebuffer> frameBuffers = new HashMap<Integer, WebGLFramebuffer>();
	int nextFrameBufferId = 1;
	final Map<Integer, WebGLRenderbuffer> renderBuffers = new HashMap<Integer, WebGLRenderbuffer>();
	int nextRenderBufferId = 1;
	final Map<Integer, WebGLTexture> textures = new HashMap<Integer, WebGLTexture>();
	int nextTextureId = 1;
	final Map<Integer, Map<Integer, WebGLUniformLocation>> uniforms = new HashMap<Integer, Map<Integer, WebGLUniformLocation>>();
	int nextUniformId = 1;
	int currProgram = 0;

	Float32Array floatBuffer = TypedArrays.createFloat32Array(2000 * 20);
	Int32Array intBuffer = TypedArrays.createInt32Array(2000 * 6);
	Int16Array shortBuffer = TypedArrays.createInt16Array(2000 * 6);
	float[] floatArray = new float[16000];

	final WebGLRenderingContext gl;

	protected GwtGL20 (WebGLRenderingContext gl) {
		;
		this.gl = gl;
		this.gl.pixelStorei(WebGLRenderingContext.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
	}

	private void ensureCapacity (FloatBuffer buffer) {
		if (buffer.remaining() > floatBuffer.length()) {
			floatBuffer = TypedArrays.createFloat32Array(buffer.remaining());
		}
	}

	private void ensureCapacity (ShortBuffer buffer) {
		if (buffer.remaining() > shortBuffer.length()) {
			shortBuffer = TypedArrays.createInt16Array(buffer.remaining());
		}
	}
	
	private void ensureCapacity (IntBuffer buffer) {
		if (buffer.remaining() > intBuffer.length()) {
			intBuffer = TypedArrays.createInt32Array(buffer.remaining());
		}
	}

	public Float32Array copy (FloatBuffer buffer) {
		if (GWT.isProdMode()) {
			return ((Float32Array)((HasArrayBufferView)buffer).getTypedArray()).subarray(buffer.position(), buffer.remaining());
		} else {
			ensureCapacity(buffer);
			for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) {
				floatBuffer.set(j, buffer.get(i));
			}
			return floatBuffer.subarray(0, buffer.remaining());
		}
	}

	public Int16Array copy (ShortBuffer buffer) {
		if (GWT.isProdMode()) {
			return ((Int16Array)((HasArrayBufferView)buffer).getTypedArray()).subarray(buffer.position(), buffer.remaining());
		} else {
			ensureCapacity(buffer);
			for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) {
{'fraction_non_alphanumeric': 0.14651386955124773, 'fraction_numerical': 0.0188497376030845, 'mean_word_length': 5.566807313642757, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7251400', 'n_tokens_mistral': 3095, 'n_tokens_neox': 2861, 'n_words': 665}