public static void vglLoadDDS(string filename, ref vglImageData image) { System.IO.FileStream f = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader br = new System.IO.BinaryReader(f); //DDS_FILE_HEADER file_header = { 0, }; DDS_FILE_HEADER file_header = new DDS_FILE_HEADER(); //fread(&file_header, sizeof(file_header.magic) + sizeof(file_header.std_header), 1, f); file_header = br.ReadStruct<DDS_FILE_HEADER>(); file_header.dxt10_header.format = 0; file_header.dxt10_header.array_size = 0; f.Position = Marshal.SizeOf(file_header.magic) + Marshal.SizeOf(file_header.std_header); if (file_header.magic != DDSSignal.DDS_MAGIC) { goto done_close_file; } if (file_header.std_header.ddspf.dwFourCC == DDSSignal.DDS_FOURCC_DX10) { //fread(&file_header.dxt10_header, sizeof(file_header.dxt10_header), 1, f); f.Position = Marshal.SizeOf(file_header.magic) + Marshal.SizeOf(file_header.std_header); file_header.dxt10_header = br.ReadStruct<DDS_HEADER_DXT10>(); } if (!vgl_DDSHeaderToImageDataHeader(ref file_header, ref image)) goto done_close_file; image.target = vgl_GetTargetFromDDSHeader(ref file_header); if (image.target == GL.GL_NONE) goto done_close_file; //int current_pos = ftell(f); long current_pos = f.Position; long file_size = f.Length; image.totalDataSize = (int)(file_size - current_pos); var data = new UnmanagedArray<byte>(image.totalDataSize); if (image.mip == null) { image.mip = new vglImageMipData[vermilion.MAX_TEXTURE_MIPS]; } image.mip[0].data = data.Header; //image.mip[0].data = new byte[image.totalDataSize]; //fread(image.mip[0].data, file_size - current_pos, 1, f); for (int i = 0; i < image.totalDataSize; i++) { data[i] = br.ReadByte(); } int level; IntPtr ptr = image.mip[0].data; uint width = file_header.std_header.width; uint height = file_header.std_header.height; uint depth = file_header.std_header.depth; image.sliceStride = 0; if (image.mipLevels == 0) { image.mipLevels = 1; } for (level = 0; level < image.mipLevels; ++level) { image.mip[level].data = ptr; image.mip[level].width = (int)width; image.mip[level].height = (int)height; image.mip[level].depth = (int)depth; image.mip[level].mipStride = (int)(vgl_GetDDSStride(ref file_header, (int)width) * height); image.sliceStride += image.mip[level].mipStride; ptr += image.mip[level].mipStride; width >>= 1; height >>= 1; depth >>= 1; } done_close_file: f.Close(); }
void vglUnloadImage(vglImageData image) { }
void vglLoadImage(string filename, vglImageData image) { }
uint vglLoadTexture(string filename, uint texture, vglImageData image) { }
protected override void DoInitialize() { base_prog = GL.CreateProgram(); ShaderHelper.vglAttachShaderSource(base_prog, ShaderType.VertexShader, quad_shader_vs); ShaderHelper.vglAttachShaderSource(base_prog, ShaderType.FragmentShader, quad_shader_fs); GL.GenBuffers(1, quad_vbo); GL.BindBuffer(BufferTarget.ArrayBuffer, quad_vbo[0]); var quad_data = new UnmanagedArray<vec2>(8); quad_data[0] = new vec2(1.0f, -1.0f); quad_data[1] = new vec2(-1.0f, -1.0f); quad_data[2] = new vec2(-1.0f, 1.0f); quad_data[3] = new vec2(1.0f, 1.0f); quad_data[4] = new vec2(0.0f, 0.0f); quad_data[5] = new vec2(1.0f, 0.0f); quad_data[6] = new vec2(1.0f, 1.0f); quad_data[7] = new vec2(0.0f, 1.0f); GL.BufferData(BufferTarget.ArrayBuffer, quad_data, BufferUsage.StaticDraw); GL.GenVertexArrays(1, vao); GL.BindVertexArray(vao[0]); GL.VertexAttribPointer(0, 2, GL.GL_FLOAT, false, 0, IntPtr.Zero); GL.VertexAttribPointer(1, 2, GL.GL_FLOAT, false, 0, new IntPtr(8 * sizeof(float))); GL.EnableVertexAttribArray(0); GL.EnableVertexAttribArray(1); GL.LinkProgram(base_prog); StringBuilder buf = new StringBuilder(1024); GL.GetProgramInfoLog(base_prog, 1024, IntPtr.Zero, buf); vglImageData image = new vglImageData(); tex = vgl.vglLoadTexture(@"media\test.dds", 0, ref image); GL.TexParameteri(image.target, GL.GL_TEXTURE_MIN_FILTER, (int)GL.GL_LINEAR_MIPMAP_LINEAR); vgl.vglUnloadImage(ref image); }
public static void vglUnloadImage(ref vglImageData image) { Marshal.FreeHGlobal(image.mip[0].data); }
public static uint vglLoadTexture(string filename, uint texture, ref vglImageData image) { //vglImageData local_image; int level; //if (image == 0) //image = &local_image; vglLoadImage(filename, ref image); if (texture == 0) { uint[] tmp = new uint[1]; GL.GenTextures(1, tmp); texture = tmp[0]; } GL.BindTexture(image.target, texture); if (image.mip == null) { image.mip = new vglImageMipData[vermilion.MAX_TEXTURE_MIPS]; } IntPtr ptr = image.mip[0].data; switch (image.target) { case GL.GL_TEXTURE_1D: GL.TexStorage1D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width); for (level = 0; level < image.mipLevels; ++level) { GL.TexSubImage1D(GL.GL_TEXTURE_1D, level, 0, image.mip[level].width, image.format, image.type, image.mip[level].data); } break; case GL.GL_TEXTURE_1D_ARRAY: GL.TexStorage2D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width, image.slices); for (level = 0; level < image.mipLevels; ++level) { GL.TexSubImage2D(GL.GL_TEXTURE_1D, level, 0, 0, image.mip[level].width, image.slices, image.format, image.type, image.mip[level].data); } break; case GL.GL_TEXTURE_2D: GL.TexStorage2D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width, image.mip[0].height); for (level = 0; level < image.mipLevels; ++level) { GL.TexSubImage2D(GL.GL_TEXTURE_2D, level, 0, 0, image.mip[level].width, image.mip[level].height, image.format, image.type, image.mip[level].data); } break; case GL.GL_TEXTURE_CUBE_MAP: for (level = 0; level < image.mipLevels; ++level) { ptr = image.mip[level].data; for (int face = 0; face < 6; face++) { GL.TexImage2D((uint)(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), level, image.internalFormat, image.mip[level].width, image.mip[level].height, 0, image.format, image.type, ptr + image.sliceStride * face); } } break; case GL.GL_TEXTURE_2D_ARRAY: GL.TexStorage3D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width, image.mip[0].height, image.slices); for (level = 0; level < image.mipLevels; ++level) { GL.TexSubImage3D(GL.GL_TEXTURE_2D_ARRAY, level, 0, 0, 0, image.mip[level].width, image.mip[level].height, image.slices, image.format, image.type, image.mip[level].data); } break; case GL.GL_TEXTURE_CUBE_MAP_ARRAY: GL.TexStorage3D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width, image.mip[0].height, image.slices); break; case GL.GL_TEXTURE_3D: GL.TexStorage3D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width, image.mip[0].height, image.mip[0].depth); for (level = 0; level < image.mipLevels; ++level) { GL.TexSubImage3D(GL.GL_TEXTURE_3D, level, 0, 0, 0, image.mip[level].width, image.mip[level].height, image.mip[level].depth, image.format, image.type, image.mip[level].data); } break; default: break; } int[] swizzle = new int[4]; for (int i = 0; i < 4; i++) { swizzle[i] = (int)image.swizzle[i]; } GL.TexParameteriv(image.target, GL.GL_TEXTURE_SWIZZLE_RGBA, swizzle); //if (image == &local_image) //{ //vglUnloadImage(image); //} return(texture); }
public static void vglLoadImage(string filename, ref vglImageData image) { vglLoadDDS(filename, ref image); }
protected override void DoInitialize() { skybox_prog = GL.CreateProgram(); ShaderHelper.vglAttachShaderSource(skybox_prog, ShaderType.VertexShader, skybox_shader_vs); ShaderHelper.vglAttachShaderSource(skybox_prog, ShaderType.FragmentShader, skybox_shader_fs); GL.LinkProgram(skybox_prog); object_prog = GL.CreateProgram(); ShaderHelper.vglAttachShaderSource(object_prog, ShaderType.VertexShader, object_shader_vs); ShaderHelper.vglAttachShaderSource(object_prog, ShaderType.FragmentShader, object_shader_fs); GL.LinkProgram(object_prog); GL.GenBuffers(1, cube_vbo); GL.BindBuffer(BufferTarget.ArrayBuffer, cube_vbo[0]); var cube_vertices = new UnmanagedArray<vec3>(8); cube_vertices[0] = new vec3(-1.0f, -1.0f, -1.0f); cube_vertices[1] = new vec3(-1.0f, -1.0f, 1.0f); cube_vertices[2] = new vec3(-1.0f, 1.0f, -1.0f); cube_vertices[3] = new vec3(-1.0f, 1.0f, 1.0f); cube_vertices[4] = new vec3(1.0f, -1.0f, -1.0f); cube_vertices[5] = new vec3(1.0f, -1.0f, 1.0f); cube_vertices[6] = new vec3(1.0f, 1.0f, -1.0f); cube_vertices[7] = new vec3(1.0f, 1.0f, 1.0f); var cube_indices = new UnmanagedArray<ushort>(16); // First strip cube_indices[0] = 0; cube_indices[1] = 1; cube_indices[2] = 2; cube_indices[3] = 3; cube_indices[4] = 6; cube_indices[5] = 7; cube_indices[6] = 4; cube_indices[7] = 5; // Second strip cube_indices[8] = 2; cube_indices[9] = 6; cube_indices[10] = 0; cube_indices[11] = 4; cube_indices[12] = 1; cube_indices[13] = 5; cube_indices[14] = 3; cube_indices[15] = 7; GL.BufferData(BufferTarget.ArrayBuffer, cube_vertices, BufferUsage.StaticDraw); cube_vertices.Dispose(); GL.GenVertexArrays(1, vao); GL.BindVertexArray(vao[0]); GL.VertexAttribPointer(0, 3, GL.GL_FLOAT, false, 0, IntPtr.Zero); GL.EnableVertexAttribArray(0); GL.GenBuffers(1, cube_element_buffer); GL.BindBuffer(BufferTarget.ElementArrayBuffer, cube_element_buffer[0]); GL.BufferData(BufferTarget.ElementArrayBuffer, cube_indices, BufferUsage.StaticDraw); cube_indices.Dispose(); skybox_rotate_loc = GL.GetUniformLocation(skybox_prog, "tc_rotate"); object_mat_mvp_loc = GL.GetUniformLocation(object_prog, "mat_mvp"); object_mat_mv_loc = GL.GetUniformLocation(object_prog, "mat_mv"); skyboxTexLocation = GL.GetUniformLocation(skybox_prog, "tex"); objectTexLocation = GL.GetUniformLocation(object_prog, "tex"); //tex = new Texture2D(); //System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(@"media\TantolundenCube.png"); //tex.Initialize(bmp); vglImageData data = new vglImageData(); tex = vgl.vglLoadTexture(@"media\TantolundenCube.dds", 0, ref data); uint e = GL.GetError(); vgl.vglUnloadImage(ref data); vboObject.LoadFromVBM(@"media\unit_torus.vbm", 0, 1, 2); }
public static void vglLoadDDS(string filename, ref vglImageData image) { System.IO.FileStream f = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); System.IO.BinaryReader br = new System.IO.BinaryReader(f); //DDS_FILE_HEADER file_header = { 0, }; DDS_FILE_HEADER file_header = new DDS_FILE_HEADER(); //fread(&file_header, sizeof(file_header.magic) + sizeof(file_header.std_header), 1, f); file_header = br.ReadStruct <DDS_FILE_HEADER>(); file_header.dxt10_header.format = 0; file_header.dxt10_header.array_size = 0; f.Position = Marshal.SizeOf(file_header.magic) + Marshal.SizeOf(file_header.std_header); if (file_header.magic != DDSSignal.DDS_MAGIC) { goto done_close_file; } if (file_header.std_header.ddspf.dwFourCC == DDSSignal.DDS_FOURCC_DX10) { //fread(&file_header.dxt10_header, sizeof(file_header.dxt10_header), 1, f); f.Position = Marshal.SizeOf(file_header.magic) + Marshal.SizeOf(file_header.std_header); file_header.dxt10_header = br.ReadStruct <DDS_HEADER_DXT10>(); } if (!vgl_DDSHeaderToImageDataHeader(ref file_header, ref image)) { goto done_close_file; } image.target = vgl_GetTargetFromDDSHeader(ref file_header); if (image.target == GL.GL_NONE) { goto done_close_file; } //int current_pos = ftell(f); long current_pos = f.Position; long file_size = f.Length; image.totalDataSize = (int)(file_size - current_pos); var data = new UnmanagedArray <byte>(image.totalDataSize); if (image.mip == null) { image.mip = new vglImageMipData[vermilion.MAX_TEXTURE_MIPS]; } image.mip[0].data = data.Header; //image.mip[0].data = new byte[image.totalDataSize]; //fread(image.mip[0].data, file_size - current_pos, 1, f); for (int i = 0; i < image.totalDataSize; i++) { data[i] = br.ReadByte(); } int level; IntPtr ptr = image.mip[0].data; uint width = file_header.std_header.width; uint height = file_header.std_header.height; uint depth = file_header.std_header.depth; image.sliceStride = 0; if (image.mipLevels == 0) { image.mipLevels = 1; } for (level = 0; level < image.mipLevels; ++level) { image.mip[level].data = ptr; image.mip[level].width = (int)width; image.mip[level].height = (int)height; image.mip[level].depth = (int)depth; image.mip[level].mipStride = (int)(vgl_GetDDSStride(ref file_header, (int)width) * height); image.sliceStride += image.mip[level].mipStride; ptr += image.mip[level].mipStride; width >>= 1; height >>= 1; depth >>= 1; } done_close_file: f.Close(); }
public static bool vgl_DDSHeaderToImageDataHeader(ref DDS_FILE_HEADER header, ref vglImageData image) { image.swizzle = new uint[4]; if (header.std_header.ddspf.dwFlags == DDSSignal.DDS_DDPF_FOURCC && header.std_header.ddspf.dwFourCC == DDSSignal.DDS_FOURCC_DX10) { if (header.dxt10_header.format < vermilion.NUM_DDS_FORMATS) { DDS_FORMAT_GL_INFO format = InfoTable.gl_info_table[header.dxt10_header.format]; image.format = format.format; image.type = format.type; image.internalFormat = format.internalFormat; image.swizzle[0] = format.swizzle_r; image.swizzle[1] = format.swizzle_g; image.swizzle[2] = format.swizzle_b; image.swizzle[3] = format.swizzle_a; image.mipLevels = (int)header.std_header.mip_levels; return true; } } else if (header.std_header.ddspf.dwFlags == DDSSignal.DDS_DDPF_FOURCC) { image.swizzle[0] = GL.GL_RED; image.swizzle[1] = GL.GL_GREEN; image.swizzle[2] = GL.GL_BLUE; image.swizzle[3] = GL.GL_ALPHA; image.mipLevels = (int)header.std_header.mip_levels; switch (header.std_header.ddspf.dwFourCC) { case 116: image.format = GL.GL_RGBA; image.type = GL.GL_FLOAT; image.internalFormat = GL.GL_RGBA32F; /* image.swizzle[0] = GL.GL_ALPHA; image.swizzle[1] = GL.GL_BLUE; image.swizzle[2] = GL.GL_GREEN; image.swizzle[3] = GL.GL_RED; */ return true; default: break; } } else { image.swizzle[0] = GL.GL_RED; image.swizzle[1] = GL.GL_GREEN; image.swizzle[2] = GL.GL_BLUE; image.swizzle[3] = GL.GL_ALPHA; image.mipLevels = (int)header.std_header.mip_levels; switch (header.std_header.ddspf.dwFlags) { case DDSSignal.DDS_DDPF_RGB: image.format = GL.GL_BGR; image.type = GL.GL_UNSIGNED_BYTE; image.internalFormat = GL.GL_RGB8; image.swizzle[3] = GL.GL_ONE; return true; case (DDSSignal.DDS_DDPF_RGB | DDSSignal.DDS_DDPF_ALPHA): case (DDSSignal.DDS_DDPF_RGB | DDSSignal.DDS_DDPF_ALPHAPIXELS): image.format = GL.GL_BGRA; image.type = GL.GL_UNSIGNED_BYTE; image.internalFormat = GL.GL_RGBA8; return true; case DDSSignal.DDS_DDPF_ALPHA: image.format = GL.GL_RED; image.type = GL.GL_UNSIGNED_BYTE; image.internalFormat = GL.GL_R8; image.swizzle[0] = image.swizzle[1] = image.swizzle[2] = GL.GL_ZERO; image.swizzle[3] = GL.GL_RED; return true; case DDSSignal.DDS_DDPF_LUMINANCE: image.format = GL.GL_RED; image.type = GL.GL_UNSIGNED_BYTE; image.internalFormat = GL.GL_R8; image.swizzle[0] = image.swizzle[1] = image.swizzle[2] = GL.GL_RED; image.swizzle[3] = GL.GL_ONE; return true; case (DDSSignal.DDS_DDPF_LUMINANCE | DDSSignal.DDS_DDPF_ALPHA): image.format = GL.GL_RG; image.type = GL.GL_UNSIGNED_BYTE; image.internalFormat = GL.GL_RG8; image.swizzle[0] = image.swizzle[1] = image.swizzle[2] = GL.GL_RED; image.swizzle[3] = GL.GL_GREEN; return true; default: break; } } image.format = image.type = image.internalFormat = GL.GL_NONE; image.swizzle[0] = image.swizzle[1] = image.swizzle[2] = image.swizzle[3] = GL.GL_ZERO; return false; }
public static bool vgl_DDSHeaderToImageDataHeader(ref DDS_FILE_HEADER header, ref vglImageData image) { image.swizzle = new uint[4]; if (header.std_header.ddspf.dwFlags == DDSSignal.DDS_DDPF_FOURCC && header.std_header.ddspf.dwFourCC == DDSSignal.DDS_FOURCC_DX10) { if (header.dxt10_header.format < vermilion.NUM_DDS_FORMATS) { DDS_FORMAT_GL_INFO format = InfoTable.gl_info_table[header.dxt10_header.format]; image.format = format.format; image.type = format.type; image.internalFormat = format.internalFormat; image.swizzle[0] = format.swizzle_r; image.swizzle[1] = format.swizzle_g; image.swizzle[2] = format.swizzle_b; image.swizzle[3] = format.swizzle_a; image.mipLevels = (int)header.std_header.mip_levels; return(true); } } else if (header.std_header.ddspf.dwFlags == DDSSignal.DDS_DDPF_FOURCC) { image.swizzle[0] = GL.GL_RED; image.swizzle[1] = GL.GL_GREEN; image.swizzle[2] = GL.GL_BLUE; image.swizzle[3] = GL.GL_ALPHA; image.mipLevels = (int)header.std_header.mip_levels; switch (header.std_header.ddspf.dwFourCC) { case 116: image.format = GL.GL_RGBA; image.type = GL.GL_FLOAT; image.internalFormat = GL.GL_RGBA32F; /* * image.swizzle[0] = GL.GL_ALPHA; * image.swizzle[1] = GL.GL_BLUE; * image.swizzle[2] = GL.GL_GREEN; * image.swizzle[3] = GL.GL_RED; */ return(true); default: break; } } else { image.swizzle[0] = GL.GL_RED; image.swizzle[1] = GL.GL_GREEN; image.swizzle[2] = GL.GL_BLUE; image.swizzle[3] = GL.GL_ALPHA; image.mipLevels = (int)header.std_header.mip_levels; switch (header.std_header.ddspf.dwFlags) { case DDSSignal.DDS_DDPF_RGB: image.format = GL.GL_BGR; image.type = GL.GL_UNSIGNED_BYTE; image.internalFormat = GL.GL_RGB8; image.swizzle[3] = GL.GL_ONE; return(true); case (DDSSignal.DDS_DDPF_RGB | DDSSignal.DDS_DDPF_ALPHA): case (DDSSignal.DDS_DDPF_RGB | DDSSignal.DDS_DDPF_ALPHAPIXELS): image.format = GL.GL_BGRA; image.type = GL.GL_UNSIGNED_BYTE; image.internalFormat = GL.GL_RGBA8; return(true); case DDSSignal.DDS_DDPF_ALPHA: image.format = GL.GL_RED; image.type = GL.GL_UNSIGNED_BYTE; image.internalFormat = GL.GL_R8; image.swizzle[0] = image.swizzle[1] = image.swizzle[2] = GL.GL_ZERO; image.swizzle[3] = GL.GL_RED; return(true); case DDSSignal.DDS_DDPF_LUMINANCE: image.format = GL.GL_RED; image.type = GL.GL_UNSIGNED_BYTE; image.internalFormat = GL.GL_R8; image.swizzle[0] = image.swizzle[1] = image.swizzle[2] = GL.GL_RED; image.swizzle[3] = GL.GL_ONE; return(true); case (DDSSignal.DDS_DDPF_LUMINANCE | DDSSignal.DDS_DDPF_ALPHA): image.format = GL.GL_RG; image.type = GL.GL_UNSIGNED_BYTE; image.internalFormat = GL.GL_RG8; image.swizzle[0] = image.swizzle[1] = image.swizzle[2] = GL.GL_RED; image.swizzle[3] = GL.GL_GREEN; return(true); default: break; } } image.format = image.type = image.internalFormat = GL.GL_NONE; image.swizzle[0] = image.swizzle[1] = image.swizzle[2] = image.swizzle[3] = GL.GL_ZERO; return(false); }
public static uint vglLoadTexture(string filename, uint texture, ref vglImageData image) { //vglImageData local_image; int level; //if (image == 0) //image = &local_image; vglLoadImage(filename, ref image); if (texture == 0) { uint[] tmp = new uint[1]; GL.GenTextures(1, tmp); texture = tmp[0]; } GL.BindTexture(image.target, texture); if (image.mip == null) { image.mip = new vglImageMipData[vermilion.MAX_TEXTURE_MIPS]; } IntPtr ptr = image.mip[0].data; switch (image.target) { case GL.GL_TEXTURE_1D: GL.TexStorage1D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width); for (level = 0; level < image.mipLevels; ++level) { GL.TexSubImage1D(GL.GL_TEXTURE_1D, level, 0, image.mip[level].width, image.format, image.type, image.mip[level].data); } break; case GL.GL_TEXTURE_1D_ARRAY: GL.TexStorage2D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width, image.slices); for (level = 0; level < image.mipLevels; ++level) { GL.TexSubImage2D(GL.GL_TEXTURE_1D, level, 0, 0, image.mip[level].width, image.slices, image.format, image.type, image.mip[level].data); } break; case GL.GL_TEXTURE_2D: GL.TexStorage2D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width, image.mip[0].height); for (level = 0; level < image.mipLevels; ++level) { GL.TexSubImage2D(GL.GL_TEXTURE_2D, level, 0, 0, image.mip[level].width, image.mip[level].height, image.format, image.type, image.mip[level].data); } break; case GL.GL_TEXTURE_CUBE_MAP: for (level = 0; level < image.mipLevels; ++level) { ptr = image.mip[level].data; for (int face = 0; face < 6; face++) { GL.TexImage2D((uint)(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + face), level, image.internalFormat, image.mip[level].width, image.mip[level].height, 0, image.format, image.type, ptr + image.sliceStride * face); } } break; case GL.GL_TEXTURE_2D_ARRAY: GL.TexStorage3D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width, image.mip[0].height, image.slices); for (level = 0; level < image.mipLevels; ++level) { GL.TexSubImage3D(GL.GL_TEXTURE_2D_ARRAY, level, 0, 0, 0, image.mip[level].width, image.mip[level].height, image.slices, image.format, image.type, image.mip[level].data); } break; case GL.GL_TEXTURE_CUBE_MAP_ARRAY: GL.TexStorage3D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width, image.mip[0].height, image.slices); break; case GL.GL_TEXTURE_3D: GL.TexStorage3D(image.target, image.mipLevels, image.internalFormat, image.mip[0].width, image.mip[0].height, image.mip[0].depth); for (level = 0; level < image.mipLevels; ++level) { GL.TexSubImage3D(GL.GL_TEXTURE_3D, level, 0, 0, 0, image.mip[level].width, image.mip[level].height, image.mip[level].depth, image.format, image.type, image.mip[level].data); } break; default: break; } int[] swizzle = new int[4]; for (int i = 0; i < 4;i++ ) { swizzle[i] = (int)image.swizzle[i]; } GL.TexParameteriv(image.target, GL.GL_TEXTURE_SWIZZLE_RGBA, swizzle); //if (image == &local_image) //{ //vglUnloadImage(image); //} return texture; }