<commit_before>// Copyright 2014 The Gfx-rs Developers.
//
// 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.

use super::{gl, Surface, Texture, Sampler};
use super::gl::types::{GLenum, GLuint, GLint, GLfloat, GLsizei, GLvoid};
use blob::Blob;
use tex;
use attrib;

/// A token produced by the `bind_texture` that allows following up
/// with a GL-compatibility sampler settings in `bind_sampler`
pub struct BindAnchor(GLenum);

fn kind_to_gl(kind: tex::TextureKind)
              -> Result<GLenum, ()> {
    Ok(match kind {
        tex::Texture1D => gl::TEXTURE_1D,
        tex::Texture1DArray => gl::TEXTURE_1D_ARRAY,
        tex::Texture2D => gl::TEXTURE_2D,
        tex::Texture2DArray => gl::TEXTURE_2D_ARRAY,
        tex::Texture2DMultiSample(_) => gl::TEXTURE_2D_MULTISAMPLE,
        tex::Texture2DMultiSampleArray(_) => gl::TEXTURE_2D_MULTISAMPLE_ARRAY,
        tex::TextureCube => gl::TEXTURE_CUBE_MAP,
        tex::Texture3D => gl::TEXTURE_3D,
    })
}

fn format_to_gl(t: tex::Format) -> Result<GLenum, ()> {
    Ok(match t {
        // floating-point
        tex::Float(tex::R,    attrib::F16) => gl::R16F,
        tex::Float(tex::R,    attrib::F32) => gl::R32F,
        tex::Float(tex::RG,   attrib::F16) => gl::RG16F,
        tex::Float(tex::RG,   attrib::F32) => gl::RG32F,
        tex::Float(tex::RGB,  attrib::F16) => gl::RGB16F,
        tex::Float(tex::RGB,  attrib::F32) => gl::RGB32F,
        tex::Float(tex::RGBA, attrib::F16) => gl::RGBA16F,
        tex::Float(tex::RGBA, attrib::F32) => gl::RGBA32F,
        tex::Float(_, attrib::F64) => return Err(()),
        // integer
        tex::Integer(_, _, _) => unimplemented!(),
        // unsigned integer
        tex::Unsigned(tex::RGBA, 8, attrib::IntNormalized) => gl::RGBA8,
        tex::Unsigned(_, _, _) => unimplemented!(),
        // special
        tex::R3G3B2       => gl::R3_G3_B2,
        tex::RGB5A1       => gl::RGB5_A1,
        tex::RGB10A2      => gl::RGB10_A2,
        tex::RGB10A2UI    => gl::RGB10_A2UI,<commit_msg>Add support for more texture formats<commit_after>// Copyright 2014 The Gfx-rs Developers.
//
// 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.

use super::{gl, Surface, Texture, Sampler};
use super::gl::types::{GLenum, GLuint, GLint, GLfloat, GLsizei, GLvoid};
use blob::Blob;
use tex;
use attrib;

/// A token produced by the `bind_texture` that allows following up
/// with a GL-compatibility sampler settings in `bind_sampler`
pub struct BindAnchor(GLenum);

fn kind_to_gl(kind: tex::TextureKind)
              -> Result<GLenum, ()> {
    Ok(match kind {
        tex::Texture1D => gl::TEXTURE_1D,
        tex::Texture1DArray => gl::TEXTURE_1D_ARRAY,
        tex::Texture2D => gl::TEXTURE_2D,
        tex::Texture2DArray => gl::TEXTURE_2D_ARRAY,
        tex::Texture2DMultiSample(_) => gl::TEXTURE_2D_MULTISAMPLE,
        tex::Texture2DMultiSampleArray(_) => gl::TEXTURE_2D_MULTISAMPLE_ARRAY,
        tex::TextureCube => gl::TEXTURE_CUBE_MAP,
        tex::Texture3D => gl::TEXTURE_3D,
    })
}

fn format_to_gl(t: tex::Format) -> Result<GLenum, ()> {
    Ok(match t {
        // floating-point
        tex::Float(tex::R,    attrib::F16) => gl::R16F,
        tex::Float(tex::R,    attrib::F32) => gl::R32F,
        tex::Float(tex::RG,   attrib::F16) => gl::RG16F,
        tex::Float(tex::RG,   attrib::F32) => gl::RG32F,
        tex::Float(tex::RGB,  attrib::F16) => gl::RGB16F,
        tex::Float(tex::RGB,  attrib::F32) => gl::RGB32F,
        tex::Float(tex::RGBA, attrib::F16) => gl::RGBA16F,
        tex::Float(tex::RGBA, attrib::F32) => gl::RGBA32F,
        tex::Float(_, attrib::F64) => return Err(()),

        // signed normalized
        tex::Integer(tex::R, 8, attrib::IntNormalized) => gl::R8_SNORM,
        tex::Integer(tex::RG, 8, attrib::IntNormalized) => gl::RG8_SNORM,
        tex::Integer(tex::RGB, 8, attrib::IntNormalized) => gl::RGB8_SNORM,
        tex::Integer(tex::RGBA, 8, attrib::IntNormalized) => gl::RGBA8_SNORM,

        tex::Integer(tex::R, 16, attrib::IntNormalized) => gl::R16_SNORM,
        tex::Integer(tex::RG, 16, attrib::IntNormalized) => gl::RG16_SNORM,
        tex::Integer(tex::RGB, 16, attrib::IntNormalized) => gl::RGB16_SNORM,
        tex::Integer(tex::RGBA, 16, attrib::IntNormalized) => gl::RGBA16_SNORM,

        // signed integral
        tex::Integer(tex::R, 8, attrib::IntRaw) => gl::R8I,
        tex::Integer(tex::RG, 8, attrib::IntRaw) => gl::RG8I,
        tex::Integer(tex::RGB, 8, attrib::IntRaw) => gl::RGB8I,
        tex::Integer(tex::RGBA, 8, attrib::IntRaw) => gl::RGBA8I,

        tex::Integer(tex::R, 16, attrib::IntRaw) => gl::R16I,
        tex::Integer(tex::RG, 16, attrib::IntRaw) => gl::RG16I,
        tex::Integer(tex::RGB, 16, attrib::IntRaw) => gl::RGB16I,
        tex::Integer(tex::RGBA, 16, attrib::IntRaw) => gl::RGBA16I,

        tex::Integer(tex::R, 32, attrib::IntRaw) => gl::R32I,
        tex::Integer(tex::RG, 32, attrib::IntRaw) => gl::RG32I,
        tex::Integer(tex::RGB, 32, attrib::IntRaw) => gl::RGB32I,
        tex::Integer(tex::RGBA, 32, attrib::IntRaw) => gl::RGBA32I,

        tex::Integer(_, _, _) => unimplemented!(),

        // unsigned normalized
        tex::Unsigned(tex::RGBA, 2, attrib::IntNormalized) => gl::RGBA2,

        tex::Unsigned(tex::RGB, 4, attrib::IntNormalized) => gl::RGB4,
        tex::Unsigned(tex::RGBA, 4, attrib::IntNormalized) => gl::RGBA4,

        tex::Unsigned(tex::RGB, 5, attrib::IntNormalized) => gl::RGB5,
        //tex::Unsigned(tex::RGBA, 5, attrib::IntNormalized) => gl::RGBA5,

        tex::Unsigned(tex::R, 8, attrib::IntNormalized) => gl::R8,
        tex::Unsigned(tex::RG, 8, attrib::IntNormalized) => gl::RG8,
        tex::Unsigned(tex::RGB, 8, attrib::IntNormalized) => gl::RGB8,
        tex::Unsigned(tex::RGBA, 8, attrib::IntNormalized) => gl::RGBA8,

        tex::Unsigned(tex::RGB, 10, attrib::IntNormalized) => gl::RGB10,

        tex::Unsigned(tex::RGB, 12, attrib::IntNormalized) => gl::RGB12,
        tex::Unsigned(tex::RGBA, 12, attrib::IntNormalized) => gl::RGBA12,

        tex::Unsigned(tex::R, 16, attrib::IntNormalized) => gl::R16,
        tex::Unsigned(tex::RG, 16, attrib::IntNormalized) => gl::RG16,
        tex::Unsigned(tex::RGB, 16, attrib::IntNormalized) => gl::RGB16,
        tex::Unsigned(tex::RGBA, 16, attrib::IntNormalized) => gl::RGBA16,

        // unsigned integral
        tex::Unsigned(tex::R, 8, attrib::IntRaw) => gl::R8UI,
        tex::Unsigned(tex::RG, 8, attrib::IntRaw) => gl::RG8UI,
        tex::Unsigned(tex::RGB, 8, attrib::IntRaw) => gl::RGB8UI,
        tex::Unsigned(tex::RGBA, 8, attrib::IntRaw) => gl::RGBA8UI,

        tex::Unsigned(tex::R, 16, attrib::IntRaw) => gl::R16UI,
        tex::Unsigned(tex::RG, 16, attrib::IntRaw) => gl::RG16UI,
        tex::Unsigned(tex::RGB, 16, attrib::IntRaw) => gl::RGB16UI,
        tex::Unsigned(tex::RGBA, 16, attrib::IntRaw) => gl::RGBA16UI,

        tex::Unsigned(tex::R, 32, attrib::IntRaw) => gl::R32UI,
        tex::Unsigned(tex::RG, 32, attrib::IntRaw) => gl::RG32UI,
        tex::Unsigned(tex::RGB, 32, attrib::IntRaw) => gl::RGB32UI,
        tex::Unsigned(tex::RGBA, 32, attrib::IntRaw) => gl::RGBA32UI,

        tex::Unsigned(_, _, _) => unimplemented!(),
        // special
        tex::R3G3B2       => gl::R3_G3_B2,
        tex::RGB5A1       => gl::RGB5_A1,
        tex::RGB10A2      => gl::RGB10_A2,
        tex::RGB10A2UI    => gl::RGB10_A2UI,
{'fraction_non_alphanumeric': 0.17820482215325853, 'fraction_numerical': 0.036762950584865124, 'mean_word_length': 3.487948580610605, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 106, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5176530', 'n_tokens_mistral': 3150, 'n_tokens_neox': 2953, 'n_words': 595}