示例#1
0
void DiGLTextureDrv::Download(const DiPixelBox &data, uint32 level, uint32 surface)
{
    if (data.GetWidth() != mParent->GetWidth() ||
            data.GetHeight() != mParent->GetHeight())
    {
        DI_WARNING("Only download of entire buffer of the texture is supported.");
        return;
    }

    glBindTexture(mGLTextureType, mTextureID);

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

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

    GLenum glfmt = DiGLTypeMappings::GLFormatMapping[fmt];
    GLenum glType = DiGLTypeMappings::GetDataType(fmt);

    if (isCompressed)
    {
        glGetCompressedTexImageARB(faceType, level, data.data);
    }
    else
    {
        if (data.GetWidth() != data.rowPitch)
            glPixelStorei(GL_PACK_ROW_LENGTH, data.rowPitch);
        if (data.GetHeight()*data.GetWidth() != data.slicePitch)
            glPixelStorei(GL_PACK_IMAGE_HEIGHT, (data.slicePitch / data.GetWidth()));
        if (data.left > 0 || data.top > 0)
            glPixelStorei(GL_PACK_SKIP_PIXELS, data.left + data.rowPitch * data.top);
        if ((data.GetWidth()*DiPixelBox::GetNumElemBytes(data.format)) & 3) {
            // Standard alignment of 4 is not right
            glPixelStorei(GL_PACK_ALIGNMENT, 1);
        }
        // We can only get the entire texture
        glGetTexImage(faceType, level, glfmt, glType, data.data);
        // Restore defaults
        glPixelStorei(GL_PACK_ROW_LENGTH, 0);
        glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
        glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
        glPixelStorei(GL_PACK_ALIGNMENT, 4);
    }
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBTextureCompression_nglGetCompressedTexImageARBBO(JNIEnv *env, jclass clazz, jint target, jint lod, jlong pImg_buffer_offset, jlong function_pointer) {
	GLvoid *pImg_address = (GLvoid *)(intptr_t)offsetToPointer(pImg_buffer_offset);
	glGetCompressedTexImageARBPROC glGetCompressedTexImageARB = (glGetCompressedTexImageARBPROC)((intptr_t)function_pointer);
	glGetCompressedTexImageARB(target, lod, pImg_address);
}
示例#3
0
static void
LoadTextures(GLuint n, const char *files[])
{
   GLuint i;

   NumTextures = n < MAX_TEXTURES ? n : MAX_TEXTURES;

   glGenTextures(n, Textures);

   SetTexParams();

   for (i = 0; i < n; i++) {
      GLint w, h;
      glBindTexture(GL_TEXTURE_2D, Textures[i]);
#if TEST_MIPMAPS
      {
         static const GLubyte color[9][4] = {
            {255, 0, 0},
            {0, 255, 0},
            {0, 0, 255},
            {0, 255, 255},
            {255, 0, 255},
            {255, 255, 0},
            {255, 128, 255},
            {128, 128, 128},
            {64, 64, 64}
         };

         GLubyte image[256*256*4];
         int i, level;
         w = h = 256;
         for (level = 0; level <= 8; level++) {
            for (i = 0; i < w * h; i++) {
               image[i*4+0] = color[level][0];
               image[i*4+1] = color[level][1];
               image[i*4+2] = color[level][2];
               image[i*4+3] = color[level][3];
            }
            printf("Load level %d: %d x %d\n", level, w>>level, h>>level);
            glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, w>>level, h>>level, 0,
                         GL_RGBA, GL_UNSIGNED_BYTE, image);
         }
      }
#elif TEST_GEN_COMPRESSED_MIPMAPS
      {
         GLenum intFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
         int f;
         GLenum format;
         GLubyte *img = LoadRGBImage(files[i], &w, &h, &format);
         GLboolean write_compressed = GL_FALSE;
         GLboolean read_compressed = GL_FALSE;

         glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
         glTexImage2D(GL_TEXTURE_2D, 0, intFormat, w, h, 0,
                      format, GL_UNSIGNED_BYTE, img);
         glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
         free(img);

         glGetTexLevelParameteriv(GL_TEXTURE_2D, i,
                                  GL_TEXTURE_INTERNAL_FORMAT, &f);
         printf("actual internal format 0x%x\n", f);

         if (write_compressed) {
            GLint i, sz, w, h;
            int num_levels = 8;
            for (i = 0; i < num_levels; i++) {
               char name[20], *buf;
               FILE *f;
               glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w);
               glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h);
               glGetTexLevelParameteriv(GL_TEXTURE_2D, i,
                                        GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sz);
               printf("Writing level %d: %d x %d  bytes: %d\n", i, w, h, sz);
               buf = malloc(sz);
               glGetCompressedTexImageARB(GL_TEXTURE_2D, i, buf);
               sprintf(name, "comp%d", i);
               f = fopen(name, "w");
               fwrite(buf, 1, sz, f);
               fclose(f);
               free(buf);
            }
         }

         if (read_compressed) {
            GLint i, sz, w, h;
            int num_levels = 8;
            for (i = 01; i < num_levels; i++) {
               char name[20], *buf;
               FILE *f;
               glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w);
               glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h);
               glGetTexLevelParameteriv(GL_TEXTURE_2D, i,
                                        GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sz);
               buf = malloc(sz);
               sprintf(name, "comp%d", i);
               printf("Reading level %d: %d x %d  bytes: %d from %s\n",
                      i, w, h, sz, name);
               f = fopen(name, "r");
               fread(buf, 1, sz, f);
               fclose(f);
               glCompressedTexImage2DARB(GL_TEXTURE_2D, i, intFormat,
                                         w, h, 0, sz, buf);
               free(buf);
            }
         }
      }
#else
      if (!LoadRGBMipmaps2(files[i], GL_TEXTURE_2D, GL_RGB, &w, &h)) {
         printf("Error: couldn't load %s\n", files[i]);
         exit(1);
      }
#endif
      TexAspect[i] = (float) w / (float) h;
      printf("Loaded %s\n", files[i]);
   }
}