public override void HardReset() { _counters = new IntBuffer(8); _tops = new ByteBuffer(8); _flags = new ByteBuffer(8); _bottoms = new ByteBuffer(8); _musicModes = new bool[3]; _bank4K = 0; _currentRandomVal = 0; _elapsedCycles = 85; _fractionalClocks = 0; base.HardReset(); }
public IntBuffer AsIntBuffer() { IntBuffer buf = new IntBuffer(); buf.buffer = new byte[this.buffer.Length]; this.buffer.CopyTo(buf.buffer, 0); buf.c = this.c; buf.capacity = this.capacity; buf.index = this.index; buf.limit = this.limit; buf.mark = this.mark; buf.offset = this.offset; buf.order = this.order; return(buf); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected void writeMappingFile() throws java.io.IOException protected internal virtual void writeMappingFile() { System.IO.Stream mappingFileWriter = new System.IO.FileStream(mappingFile, System.IO.FileMode.Create, System.IO.FileAccess.Write); sbyte[] buffer = new sbyte[4]; IntBuffer intBuffer = ByteBuffer.wrap(buffer).asIntBuffer(); int numSectors = NumSectors; for (int i = 0; i < numSectors; i++) { intBuffer.put(0, sectorMapping[i]); mappingFileWriter.Write(buffer, 0, buffer.Length); } mappingFileWriter.Close(); sectorMappingDirty = false; }
public void AddItemsOverCapacityWithOverwrite() { var capacity = 5; var cb = new IntBuffer(capacity, true); cb.Add(1); cb.Add(2); cb.Add(3); cb.Add(4); cb.Add(5); cb.Add(6); cb.Capacity.Should().Be(capacity, $"the Capacity after creating a new {nameof(IntBuffer)} should be {capacity}"); cb.Count.Should().Be(5); cb.ToArray().Should().Equal(new[] { 2, 3, 4, 5, 6 }); }
protected BufferWrapper doRead(ByteBuffer byteBuffer) { IntBuffer intBuffer = byteBuffer.asIntBuffer(); // Replace null (NaN) values in partially null coordinates with 0. Because these vector coordinate buffers // are passed directly to GL, we avoid compatability problems with some graphics drivers by removing any // NaN coordinate in the vectors. We must also detect when a vector is completely null, and enter an empty // sub-buffer in this case. This is necessary because we are eliminating the NaN signal which the data // consumer would ordinarily use to detect null coordinates. if (this.replaceNaN(intBuffer, 0) <= 0) { return(null); } return(new BufferWrapper.IntBufferWrapper(intBuffer)); }
public virtual int hleAudioGetInputLength() { if (inputDevice == null) { return(0); } if (samplesBuffer == null) { samplesBuffer = BufferUtils.createIntBuffer(1); } ALC10.alcGetInteger(inputDevice, ALC11.ALC_CAPTURE_SAMPLES, samplesBuffer); return(samplesBuffer.get(0)); }
/// <summary> /// Creates a MemoryWriter to write values to memory. /// </summary> /// <param name="address"> the address where to start writing. /// When step == 2, the address has to be 16-bit aligned ((address & 1) == 0). /// When step == 4, the address has to be 32-bit aligned ((address & 3) == 0). </param> /// <param name="Length"> the maximum number of bytes that can be written. </param> /// <param name="step"> when step == 1, write 8-bit values /// when step == 2, write 16-bit values /// when step == 4, write 32-bit values /// other value for step are not allowed. </param> /// <returns> the MemoryWriter </returns> public static IMemoryWriter getMemoryWriter(int address, int Length, int step) { address &= Memory.addressMask; if (RuntimeContext.hasMemoryInt()) { return(getFastMemoryWriter(address, step)); } if (!DebuggerMemory.Installed) { Buffer buffer = Memory.Instance.getBuffer(address, Length); if (buffer is IntBuffer) { IntBuffer intBuffer = (IntBuffer)buffer; switch (step) { case 1: return(new MemoryWriterInt8(intBuffer, address)); case 2: return(new MemoryWriterInt16(intBuffer, address)); case 4: return(new MemoryWriterInt32(intBuffer, address)); } } else if (buffer is ByteBuffer) { ByteBuffer byteBuffer = (ByteBuffer)buffer; switch (step) { case 1: return(new MemoryWriterByte8(byteBuffer, address)); case 2: return(new MemoryWriterByte16(byteBuffer, address)); case 4: return(new MemoryWriterByte32(byteBuffer, address)); } } } // Default (generic) MemoryWriter return(new MemoryWriterGeneric(address, Length, step)); }
private void Render() { while (true) { // Update HidControllerKeys CurrentButton = 0; JoystickPosition LeftJoystick; JoystickPosition RightJoystick; int LeftJoystickDX = 0; int LeftJoystickDY = 0; int RightJoystickDX = 0; int RightJoystickDY = 0; LeftJoystick = new JoystickPosition { DX = LeftJoystickDX, DY = LeftJoystickDY }; RightJoystick = new JoystickPosition { DX = RightJoystickDX, DY = RightJoystickDY }; Ns.Hid.SendControllerButtons(HidControllerID.CONTROLLER_HANDHELD, HidControllerLayouts.Main, CurrentButton, LeftJoystick, RightJoystick); // Draw ScreenTex.UploadBitmap(); Renderer.RunActions(); Renderer.BindTexture(0); Renderer.Render(); if (ScreenTex.Pixels != null) { ImageBitmap.CopyPixelsFromBuffer(IntBuffer.Wrap(ScreenTex.Pixels)); } RunOnUiThread(() => ImageView.SetImageBitmap(ImageBitmap)); } }
protected CompoundVecBuffer(CompoundVecBuffer that, int[] indices, int offset, int length) { this.count = length; this.capacity = length; this.offsets = WWBufferUtil.newIntBuffer(length, ALLOCATE_DIRECT_BUFFERS); this.lengths = WWBufferUtil.newIntBuffer(length, ALLOCATE_DIRECT_BUFFERS); for (int i = offset; i < offset + length; i++) { this.offsets.put(that.offsets.get(indices[i])); this.lengths.put(that.lengths.get(indices[i])); } this.offsets.rewind(); this.lengths.rewind(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected void readMappingFile() throws java.io.IOException protected internal virtual void readMappingFile() { System.IO.Stream mappingFileReader = new System.IO.FileStream(mappingFile, System.IO.FileMode.Open, System.IO.FileAccess.Read); int mappingSize = (int)(mappingFile.Length() / 4); sectorMapping = new int[mappingSize]; sbyte[] buffer = new sbyte[4]; IntBuffer intBuffer = ByteBuffer.wrap(buffer).asIntBuffer(); for (int i = 0; i < mappingSize; i++) { mappingFileReader.Read(buffer, 0, buffer.Length); sectorMapping[i] = intBuffer.get(0); } mappingFileReader.Close(); sectorMappingDirty = false; }
public override bool allocate() { try { byteBuffer = ByteBuffer.allocateDirect(MemoryMap.END_RAM + 1).order(ByteOrder.LITTLE_ENDIAN); intBuffer = byteBuffer.asIntBuffer(); shortBuffer = byteBuffer.asShortBuffer(); clearBuffer = ByteBuffer.allocateDirect(clearBufferSize).order(byteBuffer.order()); } catch (System.OutOfMemoryException) { // Not enough memory provided for this VM, cannot use FastMemory model Memory.Console.WriteLine("Cannot allocate DirectBufferMemory: add the option '-Xmx256m' to the Java Virtual Machine startup command to improve Performance"); Memory.Console.WriteLine("The current Java Virtual Machine has been started using '-Xmx" + (Runtime.Runtime.maxMemory() / (1024 * 1024)) + "m'"); return(false); } return(base.allocate()); }
public void CopyFullWrappedBuffer_LargerMemory() { var cb = new IntBuffer(new[] { 1, 2, 3 }, 5); cb.Remove(); cb.Remove(); cb.Remove(); // Write index should be positioned at 3 cb.Count.Should().Be(0); cb.Add(10); cb.Add(11); cb.Add(12); cb.Add(13); var target = new int[] { -1, -1, -1, -1, -1, -1 }; cb.CopyTo(new Memory <int>(target)).Should().Be(4); target.Should().Equal(new[] { 10, 11, 12, 13, -1, -1 }); }
public void CopyWrappedFullFirstPortionOnly_Memory() { var cb = new IntBuffer(new[] { 1, 2, 3 }, 5); cb.Remove(); cb.Remove(); cb.Remove(); // Write index should be positioned at 3 cb.Count.Should().Be(0); cb.Add(10); cb.Add(11); cb.Add(12); cb.Add(13); var target = new int[] { -1, -1, -1, -1, -1 }; cb.CopyTo(new Memory <int>(target).Slice(0, 2)).Should().Be(2); target.Should().Equal(new[] { 10, 11, -1, -1, -1 }); }
public void CopyWrappedSmallerFirstPortionOnly_Array() { var cb = new IntBuffer(new[] { 1, 2, 3 }, 5); cb.Remove(); cb.Remove(); cb.Remove(); // Write index should be positioned at 3 cb.Count.Should().Be(0); cb.Add(10); cb.Add(11); cb.Add(12); cb.Add(13); var target = new int[] { -1, -1, -1, -1, -1 }; cb.CopyTo(target, 0, 1); target.Should().Equal(new[] { 10, -1, -1, -1, -1 }); }
/// <summary>Set the checksum related parameters</summary> /// <param name="verifyChecksum">whether to verify checksum</param> /// <param name="sum">which type of checksum to use</param> /// <param name="maxChunkSize">maximun chunk size</param> /// <param name="checksumSize">checksum size</param> protected internal void Set(bool verifyChecksum, Checksum sum, int maxChunkSize, int checksumSize) { lock (this) { // The code makes assumptions that checksums are always 32-bit. System.Diagnostics.Debug.Assert(!verifyChecksum || sum == null || checksumSize == ChecksumSize); this.maxChunkSize = maxChunkSize; this.verifyChecksum = verifyChecksum; this.sum = sum; this.buf = new byte[maxChunkSize]; // The size of the checksum array here determines how much we can // read in a single call to readChunk this.checksum = new byte[ChunksPerRead * checksumSize]; this.checksumInts = ByteBuffer.Wrap(checksum).AsIntBuffer(); this.count = 0; this.pos = 0; } }
protected void expandCapacity(int minCapacity) { int newCapacity = 2 * this.capacity; // If the new capacity overflows the range of 32-bit integers, then use the largest 32-bit integer. if (newCapacity < 0) { newCapacity = Integer.MAX_VALUE; } // If the new capacity is still not large enough for the minimum capacity specified, then just use the minimum // capacity specified. else if (newCapacity < minCapacity) { newCapacity = minCapacity; } this.offsets = WWBufferUtil.copyOf(this.offsets, newCapacity); this.lengths = WWBufferUtil.copyOf(this.lengths, newCapacity); this.capacity = newCapacity; }
protected CompoundVecBuffer(CompoundVecBuffer that, int beginIndex, int endIndex) { int length = endIndex - beginIndex + 1; this.count = length; this.capacity = length; this.offsets = WWBufferUtil.newIntBuffer(length, ALLOCATE_DIRECT_BUFFERS); that.offsets.limit(endIndex + 1); that.offsets.position(beginIndex); this.offsets.put(that.offsets); this.offsets.rewind(); that.offsets.clear(); this.lengths = WWBufferUtil.newIntBuffer(length, ALLOCATE_DIRECT_BUFFERS); that.lengths.limit(endIndex + 1); that.lengths.position(beginIndex); this.lengths.put(that.lengths); this.lengths.rewind(); that.lengths.clear(); }
public override void HardReset() { _superChargerImage = new ByteBuffer(8192); _imageOffsets = new IntBuffer(2); _writePending = false; _distinctAccesses = 0; _writeEnabled = false; _dataHoldRegister = 0; _numberOfLoadImages = 0; _loadedImages = null; _header = new ByteBuffer(256); _powerIndicator = false; _powerRomCycle = 0; _size = 0; _elapsedCycles = 0; InitializeSettings(); base.HardReset(); }
public string TestBuffer() { IntBuffer buff = new IntBuffer(2); buff.Append(1); buff.Append(3); buff.Append(5); buff.Append(7); buff.Append(9); buff.Append(11); buff.Append(13); buff.Append(15); buff.Append(17); int a = buff[0]; int b = buff[1]; int c = buff[2]; buff[1] = 10; int d = buff[1]; return(Convert.ToString(a) + Convert.ToString(b) + Convert.ToString(c) + Convert.ToString(d)); }
public static IntBuffer getDirectBuffer(int size, IntBuffer buffer) { if (buffer == null) { return(buffer); } size = Round4(size); if (buffer.Direct) { buffer.limit((size >> 2) + buffer.position()); return(buffer); } IntBuffer directBuffer = allocateDirectBuffer(size).asIntBuffer(); directBuffer.put((IntBuffer)((IntBuffer)buffer).slice().limit(size >> 2)); directBuffer.rewind(); return(directBuffer); }
public override void multiDrawArrays(int primitive, IntBuffer first, IntBuffer count) { base.multiDrawArrays(primitive, first, count); re.checkAndLogErrors("multiDrawArrays"); }
static public void SyncObject(Serializer ser, object obj) { BindingFlags defaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; MemberInfo[] members = obj.GetType().GetMembers(defaultFlags); Bit refBit; Boolean refBool; Byte refByte; ByteBuffer refByteBuffer; Int16 refInt16; Int32 refInt32; IntBuffer refIntBuffer; Int32 refPointX; Int32 refPointY; SByte refSByte; UInt16 refUInt16; UInt32 refUInt32; Int32 refRectHeight; Int32 refRectWidth; foreach (MemberInfo member in members) { object currentValue = null; bool fail = false; FieldInfo fieldInfo = null; PropertyInfo propInfo = null; Type valueType = null; if (member.MemberType == MemberTypes.Field) { fieldInfo = member.ReflectedType.GetField(member.Name, defaultFlags); valueType = fieldInfo.FieldType; currentValue = fieldInfo.GetValue(obj); } else { fail = true; } if (!fail) { if (valueType.IsArray) { } if (currentValue != null) { switch (valueType.Name) { case "Bit": refBit = (Bit)currentValue; ser.Sync(member.Name, ref refBit); currentValue = refBit; break; case "Boolean": refBool = (Boolean)currentValue; ser.Sync(member.Name, ref refBool); currentValue = refBool; break; case "Boolean[]": { bool[] tmp = (bool[])currentValue; ser.Sync(member.Name, ref tmp, false); currentValue = tmp; } break; case "Byte": refByte = (Byte)currentValue; ser.Sync(member.Name, ref refByte); currentValue = refByte; break; case "Byte[]": refByteBuffer = new ByteBuffer((byte[])currentValue); ser.Sync(member.Name, ref refByteBuffer); currentValue = refByteBuffer.Arr; break; case "ByteBuffer": refByteBuffer = (ByteBuffer)currentValue; ser.Sync(member.Name, ref refByteBuffer); currentValue = refByteBuffer; break; case "Func`1": break; case "Int16": refInt16 = (Int16)currentValue; ser.Sync(member.Name, ref refInt16); currentValue = refInt16; break; case "Int32": refInt32 = (Int32)currentValue; ser.Sync(member.Name, ref refInt32); currentValue = refInt32; break; case "Int32[]": refIntBuffer = new IntBuffer((int[])currentValue); ser.Sync(member.Name, ref refIntBuffer); currentValue = refIntBuffer.Arr; break; case "IntBuffer": refIntBuffer = (IntBuffer)currentValue; ser.Sync(member.Name, ref refIntBuffer); currentValue = refIntBuffer; break; case "Point": refPointX = ((Point)currentValue).X; refPointY = ((Point)currentValue).Y; ser.Sync(member.Name + "_X", ref refPointX); ser.Sync(member.Name + "_Y", ref refPointY); currentValue = new Point(refPointX, refPointY); break; case "Rectangle": refPointX = ((Rectangle)currentValue).X; refPointY = ((Rectangle)currentValue).Y; refRectWidth = ((Rectangle)currentValue).Width; refRectHeight = ((Rectangle)currentValue).Height; ser.Sync(member.Name + "_X", ref refPointX); ser.Sync(member.Name + "_Y", ref refPointY); ser.Sync(member.Name + "_Height", ref refRectHeight); ser.Sync(member.Name + "_Width", ref refRectWidth); currentValue = new Rectangle(refPointX, refPointY, refRectWidth, refRectHeight); break; case "SByte": refSByte = (SByte)currentValue; ser.Sync(member.Name, ref refSByte); currentValue = refSByte; break; case "String": { var refString = (String)currentValue; var refVal = new ByteBuffer(encoding.GetBytes(refString)); ser.Sync(member.Name, ref refVal); currentValue = encoding.GetString(refVal.Arr); } break; case "UInt16": refUInt16 = (UInt16)currentValue; ser.Sync(member.Name, ref refUInt16); currentValue = refUInt16; break; case "UInt32": refUInt32 = (UInt32)currentValue; ser.Sync(member.Name, ref refUInt32); currentValue = refUInt32; break; default: { Type t = currentValue.GetType(); if (t.IsEnum) { refInt32 = (Int32)currentValue; ser.Sync(member.Name, ref refInt32); currentValue = refInt32; } else if (t.IsValueType) { fail = true; } else if (t.IsClass) { fail = true; foreach (var method in t.GetMethods()) { if (method.Name == "SyncState") { ser.BeginSection(fieldInfo.Name); method.Invoke(currentValue, new object[] { (Serializer)ser }); ser.EndSection(); fail = false; break; } } } else { fail = true; } } break; } } if (member.MemberType == MemberTypes.Property) { if (propInfo.CanWrite && !fail) { MethodInfo setMethod = propInfo.GetSetMethod(); setMethod.Invoke(obj, new object[] { currentValue }); } } if (member.MemberType == MemberTypes.Field) { fieldInfo.SetValue(obj, currentValue); } } } }
static public void SyncObject(Serializer ser, object obj) { BindingFlags defaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; MemberInfo[] members = obj.GetType().GetMembers(defaultFlags); Bit refBit; Boolean refBool; Byte refByte; ByteBuffer refByteBuffer; Int16 refInt16; Int32 refInt32; IntBuffer refIntBuffer; Int32 refPointX; Int32 refPointY; SByte refSByte; UInt16 refUInt16; UInt32 refUInt32; Int32 refRectHeight; Int32 refRectWidth; foreach (MemberInfo member in members) { object currentValue = null; bool fail = false; FieldInfo fieldInfo = null; PropertyInfo propInfo = null; Type valueType = null; if (member.MemberType == MemberTypes.Field) { fieldInfo = member.ReflectedType.GetField(member.Name, defaultFlags); valueType = fieldInfo.FieldType; currentValue = fieldInfo.GetValue(obj); } else { fail = true; } if (!fail) { if (valueType.IsArray) { } if (currentValue != null) { switch (valueType.Name) { case "Bit": refBit = (Bit)currentValue; ser.Sync(member.Name, ref refBit); currentValue = refBit; break; case "Boolean": refBool = (Boolean)currentValue; ser.Sync(member.Name, ref refBool); currentValue = refBool; break; case "Byte": refByte = (Byte)currentValue; ser.Sync(member.Name, ref refByte); currentValue = refByte; break; case "Byte[]": refByteBuffer = new ByteBuffer((byte[])currentValue); ser.Sync(member.Name, ref refByteBuffer); currentValue = refByteBuffer.Arr; break; case "ByteBuffer": refByteBuffer = (ByteBuffer)currentValue; ser.Sync(member.Name, ref refByteBuffer); currentValue = refByteBuffer; break; case "Int16": refInt16 = (Int16)currentValue; ser.Sync(member.Name, ref refInt16); currentValue = refInt16; break; case "Int32": refInt32 = (Int32)currentValue; ser.Sync(member.Name, ref refInt32); currentValue = refInt32; break; case "Int32[]": refIntBuffer = new IntBuffer((int[])currentValue); ser.Sync(member.Name, ref refIntBuffer); currentValue = refIntBuffer.Arr; break; case "IntBuffer": refIntBuffer = (IntBuffer)currentValue; ser.Sync(member.Name, ref refIntBuffer); currentValue = refIntBuffer; break; case "Point": refPointX = ((Point)currentValue).X; refPointY = ((Point)currentValue).Y; ser.Sync(member.Name + "_X", ref refPointX); ser.Sync(member.Name + "_Y", ref refPointY); currentValue = new Point(refPointX, refPointY); break; case "Rectangle": refPointX = ((Rectangle)currentValue).X; refPointY = ((Rectangle)currentValue).Y; refRectWidth = ((Rectangle)currentValue).Width; refRectHeight = ((Rectangle)currentValue).Height; ser.Sync(member.Name + "_X", ref refPointX); ser.Sync(member.Name + "_Y", ref refPointY); ser.Sync(member.Name + "_Height", ref refRectHeight); ser.Sync(member.Name + "_Width", ref refRectWidth); currentValue = new Rectangle(refPointX, refPointY, refRectWidth, refRectHeight); break; case "SByte": refSByte = (SByte)currentValue; ser.Sync(member.Name, ref refSByte); currentValue = refSByte; break; case "UInt16": refUInt16 = (UInt16)currentValue; ser.Sync(member.Name, ref refUInt16); currentValue = refUInt16; break; case "UInt32": refUInt32 = (UInt32)currentValue; ser.Sync(member.Name, ref refUInt32); currentValue = refUInt32; break; default: fail = true; break; } } if (member.MemberType == MemberTypes.Property) { if (propInfo.CanWrite && !fail) { MethodInfo setMethod = propInfo.GetSetMethod(); setMethod.Invoke(obj, new object[] { currentValue }); } } if (member.MemberType == MemberTypes.Field) { fieldInfo.SetValue(obj, currentValue); } } } }
/** * Creates and initializes OpenGL resources needed for rendering the model. * * @param context Context for loading the shader and below-named model and texture assets. * @param objAssetName Name of the OBJ file containing the model geometry. * @param diffuseTextureAssetName Name of the PNG file containing the diffuse texture map. */ public void CreateOnGlThread(Context context, string objAssetName, string diffuseTextureAssetName) { // Read the texture. var textureBitmap = BitmapFactory.DecodeStream(context.Assets.Open(diffuseTextureAssetName)); GLES20.GlActiveTexture(GLES20.GlTexture0); GLES20.GlGenTextures(mTextures.Length, mTextures, 0); GLES20.GlBindTexture(GLES20.GlTexture2d, mTextures[0]); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlLinearMipmapLinear); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlLinear); GLUtils.TexImage2D(GLES20.GlTexture2d, 0, textureBitmap, 0); GLES20.GlGenerateMipmap(GLES20.GlTexture2d); GLES20.GlBindTexture(GLES20.GlTexture2d, 0); textureBitmap.Recycle(); ShaderUtil.CheckGLError(TAG, "Texture loading"); // Read the obj file. var objInputStream = context.Assets.Open(objAssetName); var obj = ObjReader.Read(objInputStream); // Prepare the Obj so that its structure is suitable for // rendering with OpenGL: // 1. Triangulate it // 2. Make sure that texture coordinates are not ambiguous // 3. Make sure that normals are not ambiguous // 4. Convert it to single-indexed data obj = ObjUtils.ConvertToRenderable(obj); // OpenGL does not use Java arrays. ByteBuffers are used instead to provide data in a format // that OpenGL understands. // Obtain the data from the OBJ, as direct buffers: IntBuffer wideIndices = ObjData.GetFaceVertexIndices(obj, 3); FloatBuffer vertices = ObjData.GetVertices(obj); FloatBuffer texCoords = ObjData.GetTexCoords(obj, 2); FloatBuffer normals = ObjData.GetNormals(obj); // Convert int indices to shorts for GL ES 2.0 compatibility ShortBuffer indices = ByteBuffer.AllocateDirect(2 * wideIndices.Limit()) .Order(ByteOrder.NativeOrder()).AsShortBuffer(); while (wideIndices.HasRemaining) { indices.Put((short)wideIndices.Get()); } indices.Rewind(); var buffers = new int[2]; GLES20.GlGenBuffers(2, buffers, 0); mVertexBufferId = buffers[0]; mIndexBufferId = buffers[1]; // Load vertex buffer mVerticesBaseAddress = 0; mTexCoordsBaseAddress = mVerticesBaseAddress + 4 * vertices.Limit(); mNormalsBaseAddress = mTexCoordsBaseAddress + 4 * texCoords.Limit(); int totalBytes = mNormalsBaseAddress + 4 * normals.Limit(); GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVertexBufferId); GLES20.GlBufferData(GLES20.GlArrayBuffer, totalBytes, null, GLES20.GlStaticDraw); GLES20.GlBufferSubData( GLES20.GlArrayBuffer, mVerticesBaseAddress, 4 * vertices.Limit(), vertices); GLES20.GlBufferSubData( GLES20.GlArrayBuffer, mTexCoordsBaseAddress, 4 * texCoords.Limit(), texCoords); GLES20.GlBufferSubData( GLES20.GlArrayBuffer, mNormalsBaseAddress, 4 * normals.Limit(), normals); GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0); // Load index buffer GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, mIndexBufferId); mIndexCount = indices.Limit(); GLES20.GlBufferData( GLES20.GlElementArrayBuffer, 2 * mIndexCount, indices, GLES20.GlStaticDraw); GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, 0); ShaderUtil.CheckGLError(TAG, "OBJ buffer load"); int vertexShader = ShaderUtil.LoadGLShader(TAG, context, GLES20.GlVertexShader, Resource.Raw.object_vertex); int fragmentShader = ShaderUtil.LoadGLShader(TAG, context, GLES20.GlFragmentShader, Resource.Raw.object_fragment); mProgram = GLES20.GlCreateProgram(); GLES20.GlAttachShader(mProgram, vertexShader); GLES20.GlAttachShader(mProgram, fragmentShader); GLES20.GlLinkProgram(mProgram); GLES20.GlUseProgram(mProgram); ShaderUtil.CheckGLError(TAG, "Program creation"); mModelViewUniform = GLES20.GlGetUniformLocation(mProgram, "u_ModelView"); mModelViewProjectionUniform = GLES20.GlGetUniformLocation(mProgram, "u_ModelViewProjection"); mPositionAttribute = GLES20.GlGetAttribLocation(mProgram, "a_Position"); mNormalAttribute = GLES20.GlGetAttribLocation(mProgram, "a_Normal"); mTexCoordAttribute = GLES20.GlGetAttribLocation(mProgram, "a_TexCoord"); mTextureUniform = GLES20.GlGetUniformLocation(mProgram, "u_Texture"); mLightingParametersUniform = GLES20.GlGetUniformLocation(mProgram, "u_LightingParameters"); mMaterialParametersUniform = GLES20.GlGetUniformLocation(mProgram, "u_MaterialParameters"); ShaderUtil.CheckGLError(TAG, "Program parameters"); Android.Opengl.Matrix.SetIdentityM(mModelMatrix, 0); }
/** * Allocates a new direct {@link java.nio.IntBuffer} of the specified size, in chars. * * @param size the new IntBuffer's size. * @param allocateDirect true to allocate and return a direct buffer, false to allocate and return a non-direct * buffer. * * @return the new buffer. * * @throws ArgumentException if size is negative. */ public static IntBuffer newIntBuffer(int size, bool allocateDirect) { if (size < 0) { String message = Logging.getMessage("generic.SizeOutOfRange", size); Logging.logger().severe(message); throw new ArgumentException(message); } return(allocateDirect ? newDirectByteBuffer(SIZEOF_INT * size).asIntBuffer() : IntBuffer.allocate(size)); }
public static void SyncObject(Serializer ser, object obj) { const BindingFlags defaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; var objType = obj.GetType(); var members = objType.GetMembers(defaultFlags); foreach (var member in members) { if (member.GetCustomAttributes(true).Any(a => a is DoNotSave)) { continue; } var name = member.Name; var nameAttribute = member.GetCustomAttributes(true).FirstOrDefault(a => a is SaveWithName); if (nameAttribute != null) { name = ((SaveWithName) nameAttribute).Name; } object currentValue = null; var fail = false; var fieldInfo = member as FieldInfo; Type valueType = null; if ((member.MemberType == MemberTypes.Field) && member.ReflectedType != null) { valueType = fieldInfo.FieldType; currentValue = fieldInfo.GetValue(obj); } if (currentValue != null) { ByteBuffer refByteBuffer; int refInt32; IntBuffer refIntBuffer; int refPointX; int refPointY; switch (valueType.Name) { case "Action`1": case "Action`2": break; case "Bit": var refBit = (Bit)currentValue; ser.Sync(name, ref refBit); currentValue = refBit; break; case "Boolean": var refBool = (bool)currentValue; ser.Sync(name, ref refBool); currentValue = refBool; break; case "Boolean[]": { var tmp = (bool[])currentValue; ser.Sync(name, ref tmp, false); currentValue = tmp; } break; case "Byte": var refByte = (byte)currentValue; ser.Sync(name, ref refByte); currentValue = refByte; break; case "Byte[]": refByteBuffer = new ByteBuffer((byte[])currentValue); ser.Sync(name, ref refByteBuffer); currentValue = refByteBuffer.Arr.Select(d => d).ToArray(); refByteBuffer.Dispose(); break; case "ByteBuffer": refByteBuffer = (ByteBuffer)currentValue; ser.Sync(name, ref refByteBuffer); currentValue = refByteBuffer; break; case "Func`1": case "Func`2": break; case "Int16": var refInt16 = (short)currentValue; ser.Sync(name, ref refInt16); currentValue = refInt16; break; case "Int32": refInt32 = (int)currentValue; ser.Sync(name, ref refInt32); currentValue = refInt32; break; case "Int32[]": refIntBuffer = new IntBuffer((int[])currentValue); ser.Sync(name, ref refIntBuffer); currentValue = refIntBuffer.Arr.Select(d => d).ToArray(); refIntBuffer.Dispose(); break; case "IntBuffer": refIntBuffer = (IntBuffer)currentValue; ser.Sync(name, ref refIntBuffer); currentValue = refIntBuffer; break; case "Point": refPointX = ((Point)currentValue).X; refPointY = ((Point)currentValue).Y; ser.Sync(name + "_X", ref refPointX); ser.Sync(name + "_Y", ref refPointY); currentValue = new Point(refPointX, refPointY); break; case "Rectangle": refPointX = ((Rectangle)currentValue).X; refPointY = ((Rectangle)currentValue).Y; var refRectWidth = ((Rectangle)currentValue).Width; var refRectHeight = ((Rectangle)currentValue).Height; ser.Sync(name + "_X", ref refPointX); ser.Sync(name + "_Y", ref refPointY); ser.Sync(name + "_Height", ref refRectHeight); ser.Sync(name + "_Width", ref refRectWidth); currentValue = new Rectangle(refPointX, refPointY, refRectWidth, refRectHeight); break; case "SByte": var refSByte = (sbyte)currentValue; ser.Sync(name, ref refSByte); currentValue = refSByte; break; case "String": var refString = (string)currentValue; var refVal = new ByteBuffer(Encoding.GetBytes(refString)); ser.Sync(name, ref refVal); currentValue = Encoding.GetString(refVal.Arr); refVal.Dispose(); break; case "UInt16": var refUInt16 = (ushort)currentValue; ser.Sync(name, ref refUInt16); currentValue = refUInt16; break; case "UInt32": var refUInt32 = (uint)currentValue; ser.Sync(name, ref refUInt32); currentValue = refUInt32; break; default: var t = currentValue.GetType(); if (t.IsEnum) { refInt32 = (int)currentValue; ser.Sync(name, ref refInt32); currentValue = refInt32; } else if (t.IsArray) { var currentValueArray = (Array) currentValue; for (var i = 0; i < currentValueArray.Length; i++) { ser.BeginSection(string.Format("{0}_{1}", name, i)); SyncObject(ser, currentValueArray.GetValue(i)); ser.EndSection(); } } else if (t.IsValueType) { fail = true; } else if (t.IsClass) { fail = true; foreach (var method in t.GetMethods().Where(method => method.Name == "SyncState")) { ser.BeginSection(fieldInfo.Name); method.Invoke(currentValue, new object[] { ser }); ser.EndSection(); fail = false; break; } } else { fail = true; } break; } } if (!fail) { if (member.MemberType == MemberTypes.Property) { var propInfo = member as PropertyInfo; if (propInfo.CanWrite) { var setMethod = propInfo.GetSetMethod(); if (setMethod != null) { setMethod.Invoke(obj, new[] { currentValue }); } } } else if (member.MemberType == MemberTypes.Field) { fieldInfo.SetValue(obj, currentValue); } } } }
public void compress(int[] @in, IntWrapper inpos, int inlength, int[] @out, IntWrapper outpos) { if (inlength == 0) { return; } int initoffset = 0; ByteBuffer buf = ByteBuffer.allocateDirect(inlength * 8); buf.order(ByteOrder.LITTLE_ENDIAN); for (int k = inpos.get(); k < inpos.get() + inlength; ++k) { long val = (@in[k] - initoffset) & 0xFFFFFFFFL; // To be consistent with unsigned integers in C/C++ initoffset = @in[k]; if (val < (1 << 7)) { buf.put((sbyte)(val | (1 << 7))); } else if (val < (1 << 14)) { buf.put((sbyte)extract7bits(0, val)); buf.put((sbyte)(extract7bitsmaskless(1, (val)) | (1 << 7))); } else if (val < (1 << 21)) { buf.put((sbyte)extract7bits(0, val)); buf.put((sbyte)extract7bits(1, val)); buf.put((sbyte)(extract7bitsmaskless(2, (val)) | (1 << 7))); } else if (val < (1 << 28)) { buf.put((sbyte)extract7bits(0, val)); buf.put((sbyte)extract7bits(1, val)); buf.put((sbyte)extract7bits(2, val)); buf.put((sbyte)(extract7bitsmaskless(3, (val)) | (1 << 7))); } else { buf.put((sbyte)extract7bits(0, val)); buf.put((sbyte)extract7bits(1, val)); buf.put((sbyte)extract7bits(2, val)); buf.put((sbyte)extract7bits(3, val)); buf.put((sbyte)(extract7bitsmaskless(4, (val)) | (1 << 7))); } } while (buf.position() % 4 != 0) { buf.put((sbyte)0); } int length = buf.position(); buf.flip(); IntBuffer ibuf = buf.asIntBuffer(); ibuf.get(@out, outpos.get(), length / 4); outpos.add(length / 4); inpos.add(inlength); }
public virtual void multiDrawElements(int primitive, IntBuffer first, IntBuffer count, int indexType, long indicesOffset) { }
void SetBank(IntBuffer target, int offset, int size, int value) { value &= ~(size-1); for (int i = 0; i < size; i++) { int index = i+offset; target[index] = value; value++; } }
public override void multiDrawElements(int primitive, IntBuffer first, IntBuffer count, int indexType, long indicesOffset) { base.multiDrawElements(primitive, first, count, indexType, indicesOffset); re.checkAndLogErrors("multiDrawElements"); }
public override IntBuffer put(IntBuffer prm1) { return(default(IntBuffer)); }
public void Sync(string name, ref IntBuffer byteBuf) { SyncBuffer(name, 4, byteBuf.Len, byteBuf.Ptr); }
public MemoryReaderInt32(IntBuffer buffer, int address) { this.buffer = buffer; this.address = address; }
public void compress(int[] inBuf, IntWrapper inPos, int inLen, int[] outBuf, IntWrapper outPos) { if (inLen == 0) { return; } ByteBuffer byteBuf = ByteBuffer.allocateDirect(inLen * 5 + 3); DeltaZigzagEncoding.Encoder ctx = new DeltaZigzagEncoding.Encoder(0); // Delta+Zigzag+VariableByte encoding. int ip = inPos.get(); int inPosLast = ip + inLen; for (; ip < inPosLast; ++ip) { // Filter with delta+zigzag encoding. int n = ctx.encodeInt(inBuf[ip]); // Variable byte encoding. //PORT NOTE: The following IF statements are ported from a switch. Fall through switches are not allowed in C# int zeros = Integer.numberOfLeadingZeros(n); if (zeros < 4) { byteBuf.put((sbyte)(((int)((uint)n >> 28) & 0x7F) | 0x80)); } if (zeros < 11) { byteBuf.put((sbyte)(((int)((uint)n >> 21) & 0x7F) | 0x80)); } if (zeros < 18) { byteBuf.put((sbyte)(((int)((uint)n >> 14) & 0x7F) | 0x80)); } if (zeros < 25) { byteBuf.put((sbyte)(((int)((uint)n >> 7) & 0x7F) | 0x80)); } byteBuf.put((sbyte)((uint)n & 0x7F)); } // Padding buffer to considerable as IntBuffer. for (int i = (4 - (byteBuf.position() % 4)) % 4; i > 0; --i) { unchecked { byteBuf.put((sbyte)(0x80)); } } int outLen = byteBuf.position() / 4; byteBuf.flip(); IntBuffer intBuf = byteBuf.asIntBuffer(); /* * Console.WriteLine(String.format( * "inLen=%d pos=%d limit=%d outLen=%d outBuf.len=%d", inLen, * intBuf.position(), intBuf.limit(), outLen, outBuf.Length)); */ intBuf.get(outBuf, outPos.get(), outLen); inPos.add(inLen); outPos.add(outLen); }