示例#1
0
GLvoid *gl_copy_array(const GLvoid *src,
                      GLenum from, GLsizei width, GLsizei stride,
                      GLenum to, GLsizei to_width, GLsizei skip, GLsizei count,
                      GLboolean normalize) {
    if (! src || !count)
        return NULL;

    if (! stride)
        stride = width * gl_sizeof(from);

    const char *unknown_str = "libGL: gl_copy_array -> unsupported type %s\n";
    GLvoid *dst = malloc((count - skip + 1) * to_width * gl_sizeof(to));
    GLsizei from_size = gl_sizeof(from) * width;
    GLsizei to_size = gl_sizeof(to) * to_width;

    if (to_width < width) {
        printf("Warning: gl_copy_array: %i < %i\n", to_width, width);
        return NULL;
    }

    // if stride is weird, we need to be able to arbitrarily shift src
    // so we leave it in a uintptr_t and cast after incrementing
    uintptr_t in = (uintptr_t)src;
    in += stride * skip;
    if (from == to && to_width >= width) {
        GL_TYPE_SWITCH(out, dst, to,
            for (int i = skip; i < (skip + count); i++) {
                memcpy(out, (GLvoid *)in, from_size);
                for (int j = width; j < to_width; j++) {
                    out[j] = 0;
                }
                out += to_width;
                in += stride;
            },
            default:
  uint buf_obj_t::get_num_items() const
  {
    if ( m_src_comp == 0 )
      return 0;

    uint sizeof_type = gl_sizeof ( m_src_type );

    if ( m_stride == 0 )
      return m_size / ( m_src_comp* sizeof_type );

    return m_size / m_stride;
  }
  GLvoid *buf_obj_t::get_item_comp_ptr ( const uint &itemno, const uint &compno ) const
  {

    if ( m_src_ptr == NULL )
    {
      throw std::underflow_error("src_ptr == NULL");
    }

    uint type_size = gl_sizeof ( m_src_type );

    GLbyte * ret_ptr = ( GLbyte * ) m_src_ptr;

    if ( m_stride == 0 )
      ret_ptr += type_size * m_src_comp * itemno;
    else
      ret_ptr += m_stride  * itemno;

    ret_ptr += compno * type_size;

    return ( GLvoid* ) ret_ptr;
  }
示例#4
0
文件: gl.c 项目: rzr/glshim
void glInterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer) {
    uintptr_t ptr = (uintptr_t)pointer;
    // element lengths
    GLsizei tex, color, normal, vert;
    // element formats
    GLenum tf, cf, nf, vf;
    tf = cf = nf = vf = GL_FLOAT;

    switch (format) {
        GL_V2F: vert = 2; break;
        GL_V3F: vert = 3; break;
        GL_C4UB_V2F:
            color = 4; cf = GL_UNSIGNED_BYTE;
            vert = 2;
            break;
        GL_C4UB_V3F:
            color = 4; cf = GL_UNSIGNED_BYTE;
            vert = 3;
            break;
        GL_C3F_V3F:
            color = 3;
            vert = 4;
            break;
        GL_N3F_V3F:
            normal = 3;
            vert = 3;
            break;
        GL_C4F_N3F_V3F:
            color = 4;
            normal = 3;
            vert = 3;
            break;
        GL_T2F_V3F:
            tex = 2;
            vert = 3;
            break;
        GL_T4F_V4F:
            tex = 4;
            vert = 4;
            break;
        GL_T2F_C4UB_V3F:
            tex = 2;
            color = 4; cf = GL_UNSIGNED_BYTE;
            vert = 3;
            break;
        GL_T2F_C3F_V3F:
            tex = 2;
            color = 3;
            vert = 3;
            break;
        GL_T2F_N3F_V3F:
            tex = 2;
            normal = 3;
            vert = 3;
            break;
        GL_T2F_C4F_N3F_V3F:
            tex = 2;
            color = 4;
            normal = 3;
            vert = 3;
            break;
        GL_T4F_C4F_N3F_V4F:
            tex = 4;
            color = 4;
            normal = 4;
            vert = 4;
            break;
    }
    if (! stride)
        stride = tex * gl_sizeof(tf) +
                 color * gl_sizeof(cf) +
                 normal * gl_sizeof(nf) +
                 vert * gl_sizeof(vf);
    if (tex) {
        glTexCoordPointer(tex, tf, stride, (GLvoid *)ptr);
        ptr += tex * gl_sizeof(tf);
    }
    if (color) {
        glColorPointer(color, cf, stride, (GLvoid *)ptr);
        ptr += color * gl_sizeof(cf);
    }
    if (normal) {
        glNormalPointer(nf, stride, (GLvoid *)ptr);
        ptr += normal * gl_sizeof(nf);
    }
    if (vert)
        glVertexPointer(vert, vf, stride, (GLvoid *)ptr);
}