コード例 #1
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBTextureCompression_nglCompressedTexSubImage2DARBBO(JNIEnv *env, jclass clazz, jint target, jint level, jint xoffset, jint yoffset, jint width, jint height, jint format, jint imageSize, jlong pData_buffer_offset, jlong function_pointer) {
	const GLvoid *pData_address = (const GLvoid *)(intptr_t)offsetToPointer(pData_buffer_offset);
	glCompressedTexSubImage2DARBPROC glCompressedTexSubImage2DARB = (glCompressedTexSubImage2DARBPROC)((intptr_t)function_pointer);
	glCompressedTexSubImage2DARB(target, level, xoffset, yoffset, width, height, format, imageSize, pData_address);
}
コード例 #2
0
ファイル: GLTexture.cpp プロジェクト: zxy2845986/Demi3D
void DiGLTextureDrv::Upload(const DiPixelBox &src, const DiBox &dst, uint32 level, uint32 surface)
{
    glBindTexture(mGLTextureType, mTextureID);

    DiPixelFormat fmt = mParent->GetFormat();
    bool isCompressed = DiPixelBox::IsCompressedFormat(fmt);

    unsigned dataType = DiGLTypeMappings::GetDataType(mGLFormat);

    GLenum faceType = GL_TEXTURE_2D;
    if (mGLTextureType == GL_TEXTURE_CUBE_MAP)
        faceType = GL_TEXTURE_CUBE_MAP_POSITIVE_X + surface;

    if (isCompressed)
    {
        if (!src.IsConsecutive())
        {
            DI_WARNING("Compressed images should be consective.");
            return;
        }

        size_t size = src.GetConsecutiveSize();
        switch (mGLTextureType)
        {
        case GL_TEXTURE_2D:
        case GL_TEXTURE_CUBE_MAP:
            if (dst.left == 0 && dst.top == 0)
            {
                glCompressedTexImage2DARB(faceType, level,
                                          mGLFormat,
                                          dst.GetWidth(),
                                          dst.GetHeight(),
                                          0,
                                          size,
                                          src.data);
            }
            else
            {
                glCompressedTexSubImage2DARB(faceType, level,
                                             dst.left, dst.top,
                                             dst.GetWidth(), dst.GetHeight(),
                                             mGLFormat, size,
                                             src.data);
            }
            break;
        }
    }
    else
    {
        if (src.GetWidth() != src.rowPitch)
            glPixelStorei(GL_UNPACK_ROW_LENGTH, src.rowPitch);

        if (src.GetWidth() > 0 && src.GetHeight()*src.GetWidth() != src.slicePitch)
            glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, (src.slicePitch / src.GetWidth()));

        if (src.left > 0 || src.top > 0)
            glPixelStorei(GL_UNPACK_SKIP_PIXELS, src.left + src.rowPitch * src.top);

        if ((src.GetWidth() * DiPixelBox::GetNumElemBytes(src.format)) & 3)
        {
            // Standard alignment of 4 is not right
            glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        }

        glGetError();

        switch (mGLTextureType)
        {
        case GL_TEXTURE_2D:
        case GL_TEXTURE_CUBE_MAP:
            if (dst.left == 0 && dst.top == 0)
            {
                glTexImage2D(faceType, level, mGLFormat, dst.GetWidth(), dst.GetHeight(),
                             0, mGLOriginFormat, dataType, src.data);
            }
            else
            {
                glTexSubImage2D(faceType, level,
                                dst.left, dst.top,
                                dst.GetWidth(), dst.GetHeight(),
                                mGLOriginFormat, dataType, src.data);
            }
            break;
        }

        GLenum glErr = glGetError();
        if (glErr != GL_NO_ERROR)
            DI_WARNING("Uploading texture (surface %d, level %d): %s", surface, level, (const char*)gluErrorString(glErr));
    }

    // restore
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    if (GLEW_VERSION_1_2)
        glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
}