public void Draw(Shader shader) { shader.Use(); for (int i = 0; i < this.textures.Length; ++i) { MeshTexture meshTex = this.textures[i]; meshTex.tex.Use(TextureUnit.Texture0 + i); shader.SetUniform1(meshTex.shaderTexFieldName, i); } GL.BindVertexArray(VAO); GL.DrawElements(PrimitiveType.Triangles, indices.Length * sizeof(uint), DrawElementsType.UnsignedInt, 0); GL.BindVertexArray(0); }
MeshTexture[] loadMaterialTextures(Material mat, TextureType type, string typeName) { MeshTexture[] textures = new MeshTexture[mat.GetMaterialTextureCount(type)]; for (int i = 0; i < mat.GetMaterialTextureCount(type); i++) { TextureSlot textureSlot; mat.GetMaterialTexture(type, i, out textureSlot); string path = Path.Combine(directory, textureSlot.FilePath); Texture texture = Texture.GetTextureFromCache(path); if (texture == null) { texture = new Texture(path, OpenTK.Graphics.OpenGL4.TextureUnit.Texture0); Texture.AddTextureToCache(path, texture); } MeshTexture meshTexture = new MeshTexture(); meshTexture.tex = texture; meshTexture.shaderTexFieldName = typeName; textures[i] = meshTexture; } return(textures); }