Path: blob/21.2-virgl/src/glx/indirect_texture_compression.c
4558 views
/*1* (C) Copyright IBM Corporation 20042* All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* on the rights to use, copy, modify, merge, publish, distribute, sub8* license, and/or sell copies of the Software, and to permit persons to whom9* the Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL18* THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,19* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR20* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE21* USE OR OTHER DEALINGS IN THE SOFTWARE.22*/2324/**25* \file glx_texture_compression.c26* Contains the routines required to implement GLX protocol for27* ARB_texture_compression and related extensions.28*29* \sa http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_compression.txt30*31* \author Ian Romanick <[email protected]>32*/3334#include "packrender.h"35#include "packsingle.h"36#include "indirect.h"3738#include <assert.h>394041void42__indirect_glGetCompressedTexImage(GLenum target, GLint level,43GLvoid * img)44{45__GLX_SINGLE_DECLARE_VARIABLES();46xGLXGetTexImageReply reply;47size_t image_bytes;4849__GLX_SINGLE_LOAD_VARIABLES();50__GLX_SINGLE_BEGIN(X_GLsop_GetCompressedTexImage, 8);51__GLX_SINGLE_PUT_LONG(0, target);52__GLX_SINGLE_PUT_LONG(4, level);53__GLX_SINGLE_READ_XREPLY();5455image_bytes = reply.width;56assert(image_bytes <= ((4 * reply.length) - 0));57assert(image_bytes >= ((4 * reply.length) - 3));5859if (image_bytes != 0) {60_XRead(dpy, (char *) img, image_bytes);61if (image_bytes < (4 * reply.length)) {62_XEatData(dpy, (4 * reply.length) - image_bytes);63}64}6566__GLX_SINGLE_END();67}686970/**71* Internal function used for \c glCompressedTexImage1D and72* \c glCompressedTexImage2D.73*/74static void75CompressedTexImage1D2D(GLenum target, GLint level,76GLenum internal_format,77GLsizei width, GLsizei height,78GLint border, GLsizei image_size,79const GLvoid * data, CARD32 rop)80{81__GLX_DECLARE_VARIABLES();8283__GLX_LOAD_VARIABLES();84if (gc->currentDpy == NULL) {85return;86}8788if ((target == GL_PROXY_TEXTURE_1D)89|| (target == GL_PROXY_TEXTURE_2D)90|| (target == GL_PROXY_TEXTURE_CUBE_MAP)) {91compsize = 0;92}93else {94compsize = image_size;95}9697cmdlen = __GLX_PAD(__GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE + compsize);98if (cmdlen <= gc->maxSmallRenderCommandSize) {99__GLX_BEGIN_VARIABLE(rop, cmdlen);100__GLX_PUT_LONG(4, target);101__GLX_PUT_LONG(8, level);102__GLX_PUT_LONG(12, internal_format);103__GLX_PUT_LONG(16, width);104__GLX_PUT_LONG(20, height);105__GLX_PUT_LONG(24, border);106__GLX_PUT_LONG(28, image_size);107if (compsize != 0) {108__GLX_PUT_CHAR_ARRAY(__GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE,109data, image_size);110}111__GLX_END(cmdlen);112}113else {114assert(compsize != 0);115116__GLX_BEGIN_VARIABLE_LARGE(rop, cmdlen + 4);117__GLX_PUT_LONG(8, target);118__GLX_PUT_LONG(12, level);119__GLX_PUT_LONG(16, internal_format);120__GLX_PUT_LONG(20, width);121__GLX_PUT_LONG(24, height);122__GLX_PUT_LONG(28, border);123__GLX_PUT_LONG(32, image_size);124__glXSendLargeCommand(gc, gc->pc,125__GLX_COMPRESSED_TEXIMAGE_CMD_HDR_SIZE + 4,126data, image_size);127}128}129130131/**132* Internal function used for \c glCompressedTexSubImage1D and133* \c glCompressedTexSubImage2D.134*/135static void136CompressedTexSubImage1D2D(GLenum target, GLint level,137GLsizei xoffset, GLsizei yoffset,138GLsizei width, GLsizei height,139GLenum format, GLsizei image_size,140const GLvoid * data, CARD32 rop)141{142__GLX_DECLARE_VARIABLES();143144__GLX_LOAD_VARIABLES();145if (gc->currentDpy == NULL) {146return;147}148149if (target == GL_PROXY_TEXTURE_3D) {150compsize = 0;151}152else {153compsize = image_size;154}155156cmdlen = __GLX_PAD(__GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE + compsize);157if (cmdlen <= gc->maxSmallRenderCommandSize) {158__GLX_BEGIN_VARIABLE(rop, cmdlen);159__GLX_PUT_LONG(4, target);160__GLX_PUT_LONG(8, level);161__GLX_PUT_LONG(12, xoffset);162__GLX_PUT_LONG(16, yoffset);163__GLX_PUT_LONG(20, width);164__GLX_PUT_LONG(24, height);165__GLX_PUT_LONG(28, format);166__GLX_PUT_LONG(32, image_size);167if (compsize != 0) {168__GLX_PUT_CHAR_ARRAY(__GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE,169data, image_size);170}171__GLX_END(cmdlen);172}173else {174assert(compsize != 0);175176__GLX_BEGIN_VARIABLE_LARGE(rop, cmdlen + 4);177__GLX_PUT_LONG(8, target);178__GLX_PUT_LONG(12, level);179__GLX_PUT_LONG(16, xoffset);180__GLX_PUT_LONG(20, yoffset);181__GLX_PUT_LONG(24, width);182__GLX_PUT_LONG(28, height);183__GLX_PUT_LONG(32, format);184__GLX_PUT_LONG(36, image_size);185__glXSendLargeCommand(gc, gc->pc,186__GLX_COMPRESSED_TEXSUBIMAGE_CMD_HDR_SIZE + 4,187data, image_size);188}189}190191192void193__indirect_glCompressedTexImage1D(GLenum target, GLint level,194GLenum internal_format, GLsizei width,195GLint border, GLsizei image_size,196const GLvoid * data)197{198CompressedTexImage1D2D(target, level, internal_format, width, 0,199border, image_size, data,200X_GLrop_CompressedTexImage1D);201}202203204void205__indirect_glCompressedTexImage2D(GLenum target, GLint level,206GLenum internal_format,207GLsizei width, GLsizei height,208GLint border, GLsizei image_size,209const GLvoid * data)210{211CompressedTexImage1D2D(target, level, internal_format, width, height,212border, image_size, data,213X_GLrop_CompressedTexImage2D);214}215216217void218__indirect_glCompressedTexImage3D(GLenum target, GLint level,219GLenum internal_format,220GLsizei width, GLsizei height,221GLsizei depth, GLint border,222GLsizei image_size, const GLvoid * data)223{224__GLX_DECLARE_VARIABLES();225226__GLX_LOAD_VARIABLES();227if (gc->currentDpy == NULL) {228return;229}230231cmdlen = __GLX_PAD(__GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE + image_size);232if (cmdlen <= gc->maxSmallRenderCommandSize) {233__GLX_BEGIN_VARIABLE(X_GLrop_CompressedTexImage3D, cmdlen);234__GLX_PUT_LONG(4, target);235__GLX_PUT_LONG(8, level);236__GLX_PUT_LONG(12, internal_format);237__GLX_PUT_LONG(16, width);238__GLX_PUT_LONG(20, height);239__GLX_PUT_LONG(24, depth);240__GLX_PUT_LONG(28, border);241__GLX_PUT_LONG(32, image_size);242if (image_size != 0) {243__GLX_PUT_CHAR_ARRAY(__GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE,244data, image_size);245}246__GLX_END(cmdlen);247}248else {249__GLX_BEGIN_VARIABLE_LARGE(X_GLrop_CompressedTexImage3D, cmdlen + 4);250__GLX_PUT_LONG(8, target);251__GLX_PUT_LONG(12, level);252__GLX_PUT_LONG(16, internal_format);253__GLX_PUT_LONG(20, width);254__GLX_PUT_LONG(24, height);255__GLX_PUT_LONG(28, depth);256__GLX_PUT_LONG(32, border);257__GLX_PUT_LONG(36, image_size);258__glXSendLargeCommand(gc, gc->pc,259__GLX_COMPRESSED_TEXIMAGE_3D_CMD_HDR_SIZE + 4,260data, image_size);261}262}263264265void266__indirect_glCompressedTexSubImage1D(GLenum target, GLint level,267GLint xoffset,268GLsizei width,269GLenum format, GLsizei image_size,270const GLvoid * data)271{272CompressedTexSubImage1D2D(target, level, xoffset, 0, width, 0,273format, image_size, data,274X_GLrop_CompressedTexSubImage1D);275}276277278void279__indirect_glCompressedTexSubImage2D(GLenum target, GLint level,280GLint xoffset, GLint yoffset,281GLsizei width, GLsizei height,282GLenum format, GLsizei image_size,283const GLvoid * data)284{285CompressedTexSubImage1D2D(target, level, xoffset, yoffset, width, height,286format, image_size, data,287X_GLrop_CompressedTexSubImage2D);288}289290291void292__indirect_glCompressedTexSubImage3D(GLenum target, GLint level,293GLint xoffset, GLint yoffset,294GLint zoffset, GLsizei width,295GLsizei height, GLsizei depth,296GLenum format, GLsizei image_size,297const GLvoid * data)298{299__GLX_DECLARE_VARIABLES();300301__GLX_LOAD_VARIABLES();302if (gc->currentDpy == NULL) {303return;304}305306cmdlen = __GLX_PAD(__GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE307+ image_size);308if (cmdlen <= gc->maxSmallRenderCommandSize) {309__GLX_BEGIN_VARIABLE(X_GLrop_CompressedTexSubImage3D, cmdlen);310__GLX_PUT_LONG(4, target);311__GLX_PUT_LONG(8, level);312__GLX_PUT_LONG(12, xoffset);313__GLX_PUT_LONG(16, yoffset);314__GLX_PUT_LONG(20, zoffset);315__GLX_PUT_LONG(24, width);316__GLX_PUT_LONG(28, height);317__GLX_PUT_LONG(32, depth);318__GLX_PUT_LONG(36, format);319__GLX_PUT_LONG(40, image_size);320if (image_size != 0) {321__GLX_PUT_CHAR_ARRAY(__GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE,322data, image_size);323}324__GLX_END(cmdlen);325}326else {327__GLX_BEGIN_VARIABLE_LARGE(X_GLrop_CompressedTexSubImage3D, cmdlen + 4);328__GLX_PUT_LONG(8, target);329__GLX_PUT_LONG(12, level);330__GLX_PUT_LONG(16, xoffset);331__GLX_PUT_LONG(20, yoffset);332__GLX_PUT_LONG(24, zoffset);333__GLX_PUT_LONG(28, width);334__GLX_PUT_LONG(32, height);335__GLX_PUT_LONG(36, depth);336__GLX_PUT_LONG(40, format);337__GLX_PUT_LONG(44, image_size);338__glXSendLargeCommand(gc, gc->pc,339__GLX_COMPRESSED_TEXSUBIMAGE_3D_CMD_HDR_SIZE + 4,340data, image_size);341}342}343344345