public override void UpdatePassIterationUniforms(Graphics.GpuProgramParameters parms) { if (parms.HasPassIterationNumber) { int index = parms.PassIterationNumberIndex; foreach (var currentUniform in glUniformReferences) { if (index == currentUniform.ConstantDef.PhysicalIndex) { unsafe { GL.Uniform1(currentUniform.Location, 1, parms.GetFloatPointer(index).Pointer.ToFloatPointer()); GLES2Config.GlCheckError(this); //There will only be one multipass entry return; } } } } }
public void DrawBatch20(SpriteSortMode sortMode) { // nothing to do if (_batchItemList.Count == 0) { return; } // sort the batch items switch (sortMode) { case SpriteSortMode.Texture: _batchItemList.Sort(CompareTexture); break; case SpriteSortMode.FrontToBack: _batchItemList.Sort(CompareDepth); break; case SpriteSortMode.BackToFront: _batchItemList.Sort(CompareReverseDepth); break; } // make sure an old draw isn't still going on. // cross fingers, commenting this out!! //GL20.Flush(); GL20.EnableVertexAttribArray(attributePosition); GL20.EnableVertexAttribArray(attributeTexCoord); int size = VertexPosition2ColorTexture.GetSize(); GL20.VertexAttribPointer(attributePosition, 2, All20.Float, false, size, _vertexHandle.AddrOfPinnedObject()); GL20.VertexAttribPointer(attributeTexCoord, 2, All20.Float, false, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2 + sizeof(uint)))); // GL11.VertexPointer(2,All11.Float,size,_vertexHandle.AddrOfPinnedObject() ); // GL11.ColorPointer(4, All11.UnsignedByte,size,(IntPtr)((uint)_vertexHandle.AddrOfPinnedObject()+(uint)(sizeof(float)*2))); // GL11.TexCoordPointer(2, All11.Float,size,(IntPtr)((uint)_vertexHandle.AddrOfPinnedObject()+(uint)(sizeof(float)*2+sizeof(uint))) ); // setup the vertexArray array int startIndex = 0; int index = 0; int texID = -1; Color lastTint = new Color(0.0f, 0.0f, 0.0f, 0.0f); // make sure the vertexArray has enough space if (_batchItemList.Count * 4 > _vertexArray.Length) { ExpandVertexArray(_batchItemList.Count); } foreach (SpriteBatchItem item in _batchItemList) { //Tint Color Vector4 vtint = item.Tint.ToVector4(); vtint /= 255; // GL20.VertexAttrib4(attributeTint,vtint.X, vtint.Y, vtint.Z, vtint.W); // if the texture changed, we need to flush and bind the new texture if (item.TextureID != texID || item.Tint != lastTint) { FlushVertexArray20(startIndex, index); startIndex = index; texID = item.TextureID; lastTint = item.Tint; GL20.ActiveTexture(All20.Texture0); GL20.BindTexture(All20.Texture2D, texID); GL20.Uniform1(texID, 0); GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W); } // store the SpriteBatchItem data in our vertexArray _vertexArray[index++] = item.vertexTL; _vertexArray[index++] = item.vertexTR; _vertexArray[index++] = item.vertexBL; _vertexArray[index++] = item.vertexBR; _freeBatchItemQueue.Enqueue(item); } // flush the remaining vertexArray data FlushVertexArray20(startIndex, index); _batchItemList.Clear(); }
public override void UpdateUniforms(Graphics.GpuProgramParameters parms, int mask, Graphics.GpuProgramType fromProgType) { foreach (var currentUniform in glUniformReferences) { //Only pull values from buffer it's supposed to be in (vertex or fragment) //This method will be called twice, once for vertex program params, //and once for fragment program params. if (fromProgType == currentUniform.SourceProgType) { var def = currentUniform.ConstantDef; if (((int)def.Variability & mask) != 0) { int glArraySize = def.ArraySize; switch (def.ConstantType) { case GpuProgramParameters.GpuConstantType.Float1: unsafe { GL.Uniform1(currentUniform.Location, glArraySize, parms.GetFloatPointer(def.PhysicalIndex).Pointer.ToFloatPointer()); GLES2Config.GlCheckError(this); } break; case GpuProgramParameters.GpuConstantType.Float2: unsafe { GL.Uniform2(currentUniform.Location, glArraySize, parms.GetFloatPointer(def.PhysicalIndex).Pointer.ToFloatPointer()); GLES2Config.GlCheckError(this); } break; case GpuProgramParameters.GpuConstantType.Float3: unsafe { GL.Uniform3(currentUniform.Location, glArraySize, parms.GetFloatPointer(def.PhysicalIndex).Pointer.ToFloatPointer()); } break; case GpuProgramParameters.GpuConstantType.Float4: unsafe { GL.Uniform4(currentUniform.Location, glArraySize, parms.GetFloatPointer(def.PhysicalIndex).Pointer.ToFloatPointer()); GLES2Config.GlCheckError(this); } break; case GpuProgramParameters.GpuConstantType.Matrix_2X2: unsafe { GL.UniformMatrix2(currentUniform.Location, glArraySize, false, parms.GetFloatPointer(def.PhysicalIndex).Pointer.ToFloatPointer()); GLES2Config.GlCheckError(this); } break; case GpuProgramParameters.GpuConstantType.Matrix_3X3: unsafe { GL.UniformMatrix3(currentUniform.Location, glArraySize, false, parms.GetFloatPointer(def.PhysicalIndex).Pointer.ToFloatPointer()); GLES2Config.GlCheckError(this); } break; case GpuProgramParameters.GpuConstantType.Matrix_4X4: unsafe { GL.UniformMatrix4(currentUniform.Location, glArraySize, false, parms.GetFloatPointer(def.PhysicalIndex).Pointer.ToFloatPointer()); GLES2Config.GlCheckError(this); } break; case GpuProgramParameters.GpuConstantType.Int1: unsafe { GL.Uniform1(currentUniform.Location, glArraySize, parms.GetIntPointer(def.PhysicalIndex).Pointer.ToIntPointer()); GLES2Config.GlCheckError(this); } break; case GpuProgramParameters.GpuConstantType.Int2: unsafe { GL.Uniform2(currentUniform.Location, glArraySize, parms.GetIntPointer(def.PhysicalIndex).Pointer.ToIntPointer()); GLES2Config.GlCheckError(this); } break; case GpuProgramParameters.GpuConstantType.Int3: unsafe { GL.Uniform3(currentUniform.Location, glArraySize, parms.GetIntPointer(def.PhysicalIndex).Pointer.ToIntPointer()); GLES2Config.GlCheckError(this); } break; case GpuProgramParameters.GpuConstantType.Int4: unsafe { GL.Uniform4(currentUniform.Location, glArraySize, parms.GetIntPointer(def.PhysicalIndex).Pointer.ToIntPointer()); GLES2Config.GlCheckError(this); } break; case GpuProgramParameters.GpuConstantType.Sampler1D: case GpuProgramParameters.GpuConstantType.Sampler1DShadow: case GpuProgramParameters.GpuConstantType.Sampler2D: case GpuProgramParameters.GpuConstantType.Sampler2DShadow: case GpuProgramParameters.GpuConstantType.Sampler3D: case GpuProgramParameters.GpuConstantType.SamplerCube: //samplers handled like 1-elemnt ints unsafe { GL.Uniform1(currentUniform.Location, 1, parms.GetIntPointer(def.PhysicalIndex).Pointer.ToIntPointer()); GLES2Config.GlCheckError(this); } break; } } } } }
public void DrawBatchGL20(SpriteSortMode sortMode) { // nothing to do if (_batchItemList.Count == 0) { return; } // sort the batch items switch (sortMode) { case SpriteSortMode.Texture: //_batchItemList.Sort( CompareTexture ); throw new NotSupportedException(); case SpriteSortMode.FrontToBack: //_batchItemList.Sort ( CompareDepth ); throw new NotSupportedException(); case SpriteSortMode.BackToFront: //_batchItemList.Sort ( CompareReverseDepth ); throw new NotSupportedException(); } GL20.EnableVertexAttribArray(attributePosition); GL20.EnableVertexAttribArray(attributeTexCoord); // make sure the vertexArray has enough space if (_batchItemList.Count * 4 > _index.Length) { ExpandIndexArray(_batchItemList.Count); } LinkVertexArray(); int size = VertexPosition2ColorTexture.GetSize(); GL20.VertexAttribPointer(attributePosition, 2, ALL20.Float, false, size, _vertexHandle.AddrOfPinnedObject()); GL20.VertexAttribPointer(attributeTexCoord, 2, ALL20.Float, false, size, (IntPtr)((uint)_vertexHandle.AddrOfPinnedObject() + (uint)(sizeof(float) * 2 + sizeof(uint)))); // setup the vertexArray array int startIndex = 0; int index = 0; int texID = -1; Color lastTint = new Color(0.0f, 0.0f, 0.0f, 0.0f); foreach (SpriteBatchItem item in _batchItemList) { //Tint Color Vector4 vtint = item.Tint.ToVector4(); //vtint /= 255; //GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W); // if the texture changed, we need to flush and bind the new texture if (item.TextureID != texID || item.Tint != lastTint) { FlushVertexArrayGL20(startIndex, index); startIndex = index; texID = item.TextureID; lastTint = item.Tint; GL20.ActiveTexture(ALL20.Texture0); GL20.BindTexture(ALL20.Texture2D, texID); GL20.Uniform1(texID, 0); GL20.VertexAttrib4(attributeTint, vtint.X, vtint.Y, vtint.Z, vtint.W); } index += 4; } // flush the remaining vertexArray data FlushVertexArrayGL20(startIndex, index); _batchItemList.Clear(); _vertexArray.Clear(); }