ReactOS 0.4.15-dev-5669-g09dde2c
teximage.c File Reference
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "context.h"
#include "image.h"
#include "macros.h"
#include "pixel.h"
#include "span.h"
#include "teximage.h"
#include "types.h"
Include dependency graph for teximage.c:

Go to the source code of this file.

Functions

static int logbase2 (int n)
 
static GLint decode_internal_format (GLint format)
 
static GLint components_in_intformat (GLint format)
 
struct gl_texture_imagegl_alloc_texture_image (void)
 
void gl_free_texture_image (struct gl_texture_image *teximage)
 
static struct gl_texture_imageimage_to_texture (GLcontext *ctx, const struct gl_image *image, GLenum internalFormat, GLint border)
 
static struct gl_texture_imagemake_null_texture (GLcontext *ctx, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border)
 
static GLboolean texture_1d_error_check (GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLenum format, GLenum type, GLint width, GLint border)
 
static GLboolean texture_2d_error_check (GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLenum format, GLenum type, GLint width, GLint height, GLint border)
 
void gl_TexImage1D (GLcontext *ctx, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, struct gl_image *image)
 
void gl_TexImage2D (GLcontext *ctx, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, struct gl_image *image)
 
void gl_GetTexImage (GLcontext *ctx, GLenum target, GLint level, GLenum format, GLenum type, GLvoid *pixels)
 
struct gl_imagegl_unpack_texsubimage (GLcontext *ctx, GLint width, GLint height, GLenum format, GLenum type, const GLvoid *pixels)
 
void gl_TexSubImage1D (GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, struct gl_image *image)
 
void gl_TexSubImage2D (GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, struct gl_image *image)
 
static struct gl_imageread_color_image (GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLint format)
 
void gl_CopyTexImage1D (GLcontext *ctx, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border)
 
void gl_CopyTexImage2D (GLcontext *ctx, GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
 
static void copy_tex_sub_image (GLcontext *ctx, struct gl_texture_image *dest, GLint width, GLint height, GLint srcx, GLint srcy, GLint dstx, GLint dsty)
 
void gl_CopyTexSubImage1D (GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width)
 
void gl_CopyTexSubImage2D (GLcontext *ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height)
 

Function Documentation

◆ components_in_intformat()

static GLint components_in_intformat ( GLint  format)
static

Definition at line 266 of file teximage.c.

267{
268 switch (format) {
269 case GL_ALPHA:
270 case GL_ALPHA4:
271 case GL_ALPHA8:
272 case GL_ALPHA12:
273 case GL_ALPHA16:
274 return 1;
275 case 1:
276 case GL_LUMINANCE:
277 case GL_LUMINANCE4:
278 case GL_LUMINANCE8:
279 case GL_LUMINANCE12:
280 case GL_LUMINANCE16:
281 return 1;
282 case 2:
290 return 2;
291 case GL_INTENSITY:
292 case GL_INTENSITY4:
293 case GL_INTENSITY8:
294 case GL_INTENSITY12:
295 case GL_INTENSITY16:
296 return 1;
297 case 3:
298 case GL_RGB:
299 case GL_R3_G3_B2:
300 case GL_RGB4:
301 case GL_RGB5:
302 case GL_RGB8:
303 case GL_RGB10:
304 case GL_RGB12:
305 case GL_RGB16:
306 return 3;
307 case 4:
308 case GL_RGBA:
309 case GL_RGBA2:
310 case GL_RGBA4:
311 case GL_RGB5_A1:
312 case GL_RGBA8:
313 case GL_RGB10_A2:
314 case GL_RGBA12:
315 case GL_RGBA16:
316 return 4;
323 return 1;
324 default:
325 return -1; /* error */
326 }
327}
#define GL_RGBA12
Definition: gl.h:764
#define GL_R3_G3_B2
Definition: gl.h:752
#define GL_RGB10
Definition: gl.h:756
#define GL_ALPHA8
Definition: gl.h:734
#define GL_RGBA8
Definition: gl.h:762
#define GL_INTENSITY8
Definition: gl.h:749
#define GL_ALPHA12
Definition: gl.h:735
#define GL_ALPHA4
Definition: gl.h:733
#define GL_RGB16
Definition: gl.h:758
#define GL_LUMINANCE8
Definition: gl.h:738
#define GL_LUMINANCE_ALPHA
Definition: gl.h:485
#define GL_RGB5
Definition: gl.h:754
#define GL_INTENSITY
Definition: gl.h:747
#define GL_LUMINANCE4_ALPHA4
Definition: gl.h:741
#define GL_RGB5_A1
Definition: gl.h:761
#define GL_RGBA2
Definition: gl.h:759
#define GL_RGB8
Definition: gl.h:755
#define GL_LUMINANCE
Definition: gl.h:484
#define GL_LUMINANCE12_ALPHA4
Definition: gl.h:744
#define GL_RGB4
Definition: gl.h:753
#define GL_RGB
Definition: gl.h:502
#define GL_LUMINANCE12_ALPHA12
Definition: gl.h:745
#define GL_INTENSITY16
Definition: gl.h:751
#define GL_LUMINANCE16_ALPHA16
Definition: gl.h:746
#define GL_RGB10_A2
Definition: gl.h:763
#define GL_LUMINANCE12
Definition: gl.h:739
#define GL_RGBA
Definition: gl.h:503
#define GL_LUMINANCE8_ALPHA8
Definition: gl.h:743
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define GL_LUMINANCE4
Definition: gl.h:737
#define GL_INTENSITY12
Definition: gl.h:750
#define GL_RGB12
Definition: gl.h:757
#define GL_LUMINANCE6_ALPHA2
Definition: gl.h:742
#define GL_ALPHA
Definition: gl.h:483
#define GL_LUMINANCE16
Definition: gl.h:740
#define GL_RGBA16
Definition: gl.h:765
#define GL_ALPHA16
Definition: gl.h:736
#define GL_INTENSITY4
Definition: gl.h:748
#define GL_RGBA4
Definition: gl.h:760
#define GL_COLOR_INDEX12_EXT
Definition: glext.h:2965
#define GL_COLOR_INDEX4_EXT
Definition: glext.h:2963
#define GL_COLOR_INDEX8_EXT
Definition: glext.h:2964
#define GL_COLOR_INDEX1_EXT
Definition: glext.h:2961
#define GL_COLOR_INDEX2_EXT
Definition: glext.h:2962
#define GL_COLOR_INDEX16_EXT
Definition: glext.h:2966

Referenced by copy_tex_sub_image(), gl_TexSubImage1D(), gl_TexSubImage2D(), image_to_texture(), make_null_texture(), and read_color_image().

◆ copy_tex_sub_image()

static void copy_tex_sub_image ( GLcontext ctx,
struct gl_texture_image dest,
GLint  width,
GLint  height,
GLint  srcx,
GLint  srcy,
GLint  dstx,
GLint  dsty 
)
static

Definition at line 1705 of file teximage.c.

1709{
1710 GLint i, j;
1712
1713 format = dest->Format;
1715
1716 for (j=0;j<height;j++) {
1719 GLubyte *texptr;
1720
1721 gl_read_color_span( ctx, width, srcx, srcy+j, red, green, blue, alpha );
1722
1723 if (!ctx->Visual->EightBitColor) {
1724 /* scale red, green, blue, alpha values to range [0,255] */
1725 GLfloat rscale = 255.0f * ctx->Visual->InvRedScale;
1726 GLfloat gscale = 255.0f * ctx->Visual->InvGreenScale;
1727 GLfloat bscale = 255.0f * ctx->Visual->InvBlueScale;
1728 GLfloat ascale = 255.0f * ctx->Visual->InvAlphaScale;
1729 for (i=0;i<width;i++) {
1730 red[i] = (GLubyte) (GLint) (red[i] * rscale);
1731 green[i] = (GLubyte) (GLint) (green[i] * gscale);
1732 blue[i] = (GLubyte) (GLint) (blue[i] * bscale);
1733 alpha[i] = (GLubyte) (GLint) (alpha[i] * ascale);
1734 }
1735 }
1736
1737 texptr = dest->Data + ( (dsty+j) * width + dstx) * components;
1738
1739 switch (format) {
1740 case GL_ALPHA:
1741 for (i=0;i<width;i++) {
1742 *texptr++ = alpha[i];
1743 }
1744 break;
1745 case GL_LUMINANCE:
1746 for (i=0;i<width;i++) {
1747 *texptr++ = red[i];
1748 }
1749 break;
1750 case GL_LUMINANCE_ALPHA:
1751 for (i=0;i<width;i++) {
1752 *texptr++ = red[i];
1753 *texptr++ = alpha[i];
1754 }
1755 break;
1756 case GL_INTENSITY:
1757 for (i=0;i<width;i++) {
1758 *texptr++ = red[i];
1759 }
1760 break;
1761 case GL_RGB:
1762 for (i=0;i<width;i++) {
1763 *texptr++ = red[i];
1764 *texptr++ = green[i];
1765 *texptr++ = blue[i];
1766 }
1767 break;
1768 case GL_RGBA:
1769 for (i=0;i<width;i++) {
1770 *texptr++ = red[i];
1771 *texptr++ = green[i];
1772 *texptr++ = blue[i];
1773 *texptr++ = alpha[i];
1774 }
1775 break;
1776 } /*switch*/
1777 } /*for*/
1778}
#define MAX_WIDTH
Definition: config.h:130
unsigned char GLubyte
Definition: gl.h:157
float GLfloat
Definition: gl.h:161
GLclampf green
Definition: gl.h:1740
GLclampf GLclampf GLclampf alpha
Definition: gl.h:1740
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
GLclampf GLclampf blue
Definition: gl.h:1740
int GLint
Definition: gl.h:156
GLint GLint GLsizei width
Definition: gl.h:1546
GLenum GLenum GLuint components
Definition: glext.h:9620
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define red
Definition: linetest.c:67
static char * dest
Definition: rtl.c:135
void gl_read_color_span(GLcontext *ctx, GLuint n, GLint x, GLint y, GLubyte red[], GLubyte green[], GLubyte blue[], GLubyte alpha[])
Definition: span.c:850
static GLint components_in_intformat(GLint format)
Definition: teximage.c:266

Referenced by gl_CopyTexSubImage1D(), and gl_CopyTexSubImage2D().

◆ decode_internal_format()

static GLint decode_internal_format ( GLint  format)
static

Definition at line 195 of file teximage.c.

196{
197 switch (format) {
198 case GL_ALPHA:
199 case GL_ALPHA4:
200 case GL_ALPHA8:
201 case GL_ALPHA12:
202 case GL_ALPHA16:
203 return GL_ALPHA;
204 case 1:
205 case GL_LUMINANCE:
206 case GL_LUMINANCE4:
207 case GL_LUMINANCE8:
208 case GL_LUMINANCE12:
209 case GL_LUMINANCE16:
210 return GL_LUMINANCE;
211 case 2:
219 return GL_LUMINANCE_ALPHA;
220 case GL_INTENSITY:
221 case GL_INTENSITY4:
222 case GL_INTENSITY8:
223 case GL_INTENSITY12:
224 case GL_INTENSITY16:
225 return GL_INTENSITY;
226 case 3:
227 case GL_RGB:
228 case GL_R3_G3_B2:
229 case GL_RGB4:
230 case GL_RGB5:
231 case GL_RGB8:
232 case GL_RGB10:
233 case GL_RGB12:
234 case GL_RGB16:
235 return GL_RGB;
236 case 4:
237 case GL_RGBA:
238 case GL_RGBA2:
239 case GL_RGBA4:
240 case GL_RGB5_A1:
241 case GL_RGBA8:
242 case GL_RGB10_A2:
243 case GL_RGBA12:
244 case GL_RGBA16:
245 return GL_RGBA;
252 return GL_COLOR_INDEX;
253 default:
254 return -1; /* error */
255 }
256}
#define GL_COLOR_INDEX
Definition: gl.h:479

Referenced by gl_CopyTexImage1D(), gl_CopyTexImage2D(), image_to_texture(), make_null_texture(), texture_1d_error_check(), and texture_2d_error_check().

◆ gl_alloc_texture_image()

struct gl_texture_image * gl_alloc_texture_image ( void  )

Definition at line 331 of file teximage.c.

332{
333 return (struct gl_texture_image *) calloc( 1, sizeof(struct gl_texture_image) );
334}
#define calloc
Definition: rosglue.h:14

Referenced by alloc_proxy_textures(), image_to_texture(), and make_null_texture().

◆ gl_CopyTexImage1D()

void gl_CopyTexImage1D ( GLcontext ctx,
GLenum  target,
GLint  level,
GLenum  internalformat,
GLint  x,
GLint  y,
GLsizei  width,
GLint  border 
)

Definition at line 1599 of file teximage.c.

1604{
1605 GLint format;
1606 struct gl_image *teximage;
1607
1608 if (INSIDE_BEGIN_END(ctx)) {
1609 gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexImage1D" );
1610 return;
1611 }
1612 if (target!=GL_TEXTURE_1D) {
1613 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage1D(target)" );
1614 return;
1615 }
1617 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage1D(level)" );
1618 return;
1619 }
1620 if (border!=0 && border!=1) {
1621 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage1D(border)" );
1622 return;
1623 }
1625 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage1D(width)" );
1626 return;
1627 }
1629 if (format<0 || (internalformat>=1 && internalformat<=4)) {
1630 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage1D(format)" );
1631 return;
1632 }
1633
1634 teximage = read_color_image( ctx, x, y, width, 1, format );
1635 if (!teximage) {
1636 gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage1D" );
1637 return;
1638 }
1639
1641 border, GL_RGBA, GL_UNSIGNED_BYTE, teximage );
1642
1643 /* teximage was freed in gl_TexImage1D */
1644}
#define MAX_TEXTURE_SIZE
Definition: config.h:93
#define MAX_TEXTURE_LEVELS
Definition: config.h:90
void gl_error(GLcontext *ctx, GLenum error, const char *s)
Definition: context.c:1421
GLint GLint GLsizei GLsizei GLsizei GLint border
Definition: gl.h:1546
#define GL_INVALID_VALUE
Definition: gl.h:695
GLint level
Definition: gl.h:1546
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define GL_INVALID_OPERATION
Definition: gl.h:696
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
#define GL_UNSIGNED_BYTE
Definition: gl.h:178
GLint GLint internalformat
Definition: gl.h:1546
#define GL_OUT_OF_MEMORY
Definition: gl.h:699
#define GL_TEXTURE_1D
Definition: gl.h:644
#define GL_INVALID_ENUM
Definition: gl.h:694
GLenum target
Definition: glext.h:7315
#define INSIDE_BEGIN_END(CTX)
Definition: macros.h:135
static struct gl_image * read_color_image(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, GLint format)
Definition: teximage.c:1493
void gl_TexImage1D(GLcontext *ctx, GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, struct gl_image *image)
Definition: teximage.c:1049
static GLint decode_internal_format(GLint format)
Definition: teximage.c:195

Referenced by execute_list(), and init_exec_pointers().

◆ gl_CopyTexImage2D()

void gl_CopyTexImage2D ( GLcontext ctx,
GLenum  target,
GLint  level,
GLenum  internalformat,
GLint  x,
GLint  y,
GLsizei  width,
GLsizei  height,
GLint  border 
)

Definition at line 1648 of file teximage.c.

1652{
1653 GLint format;
1654 struct gl_image *teximage;
1655
1656 if (INSIDE_BEGIN_END(ctx)) {
1657 gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexImage2D" );
1658 return;
1659 }
1660 if (target!=GL_TEXTURE_2D) {
1661 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexImage2D(target)" );
1662 return;
1663 }
1665 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage2D(level)" );
1666 return;
1667 }
1668 if (border!=0 && border!=1) {
1669 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage2D(border)" );
1670 return;
1671 }
1673 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage2D(width)" );
1674 return;
1675 }
1677 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage2D(height)" );
1678 return;
1679 }
1681 if (format<0 || (internalformat>=1 && internalformat<=4)) {
1682 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexImage2D(format)" );
1683 return;
1684 }
1685
1686 teximage = read_color_image( ctx, x, y, width, height, format );
1687 if (!teximage) {
1688 gl_error( ctx, GL_OUT_OF_MEMORY, "glCopyTexImage2D" );
1689 return;
1690 }
1691
1693 border, GL_RGBA, GL_UNSIGNED_BYTE, teximage );
1694
1695 /* teximage was freed in gl_TexImage2D */
1696}
#define GL_TEXTURE_2D
Definition: gl.h:645
void gl_TexImage2D(GLcontext *ctx, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, struct gl_image *image)
Definition: teximage.c:1133

Referenced by execute_list(), and init_exec_pointers().

◆ gl_CopyTexSubImage1D()

void gl_CopyTexSubImage1D ( GLcontext ctx,
GLenum  target,
GLint  level,
GLint  xoffset,
GLint  x,
GLint  y,
GLsizei  width 
)

Definition at line 1783 of file teximage.c.

1786{
1787 struct gl_texture_image *teximage;
1788
1789 if (INSIDE_BEGIN_END(ctx)) {
1790 gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexSubImage1D" );
1791 return;
1792 }
1793 if (target!=GL_TEXTURE_1D) {
1794 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage1D(target)" );
1795 return;
1796 }
1798 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage1D(level)" );
1799 return;
1800 }
1801 if (width<0) {
1802 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage1D(width)" );
1803 return;
1804 }
1805
1806 teximage = ctx->Texture.Current1D->Image[level];
1807
1808 if (teximage) {
1809 if (xoffset < -((GLint)teximage->Border)) {
1810 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage1D(xoffset)" );
1811 return;
1812 }
1813 /* NOTE: we're adding the border here, not subtracting! */
1814 if (xoffset+width > teximage->Width+teximage->Border) {
1816 "glCopyTexSubImage1D(xoffset+width)" );
1817 return;
1818 }
1819 if (teximage->Data) {
1820 copy_tex_sub_image( ctx, teximage, width, 1, x, y, xoffset, 0);
1821 }
1822 }
1823 else {
1824 gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexSubImage1D" );
1825 }
1826}
GLint GLint xoffset
Definition: gl.h:1547
GLubyte * Data
Definition: types.h:303
GLuint Width
Definition: types.h:296
GLuint Border
Definition: types.h:295
static void copy_tex_sub_image(GLcontext *ctx, struct gl_texture_image *dest, GLint width, GLint height, GLint srcx, GLint srcy, GLint dstx, GLint dsty)
Definition: teximage.c:1705

Referenced by execute_list(), and init_exec_pointers().

◆ gl_CopyTexSubImage2D()

void gl_CopyTexSubImage2D ( GLcontext ctx,
GLenum  target,
GLint  level,
GLint  xoffset,
GLint  yoffset,
GLint  x,
GLint  y,
GLsizei  width,
GLsizei  height 
)

Definition at line 1830 of file teximage.c.

1834{
1835 struct gl_texture_image *teximage;
1836
1837 if (INSIDE_BEGIN_END(ctx)) {
1838 gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D" );
1839 return;
1840 }
1841 if (target!=GL_TEXTURE_2D) {
1842 gl_error( ctx, GL_INVALID_ENUM, "glCopyTexSubImage2D(target)" );
1843 return;
1844 }
1846 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage2D(level)" );
1847 return;
1848 }
1849 if (width<0) {
1850 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage2D(width)" );
1851 return;
1852 }
1853 if (height<0) {
1854 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage2D(height)" );
1855 return;
1856 }
1857
1858 teximage = ctx->Texture.Current2D->Image[level];
1859
1860 if (teximage) {
1861 if (xoffset < -((GLint)teximage->Border)) {
1862 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage2D(xoffset)" );
1863 return;
1864 }
1865 if (yoffset < -((GLint)teximage->Border)) {
1866 gl_error( ctx, GL_INVALID_VALUE, "glCopyTexSubImage2D(yoffset)" );
1867 return;
1868 }
1869 /* NOTE: we're adding the border here, not subtracting! */
1870 if (xoffset+width > teximage->Width+teximage->Border) {
1872 "glCopyTexSubImage2D(xoffset+width)" );
1873 return;
1874 }
1875 if (yoffset+height > teximage->Height+teximage->Border) {
1877 "glCopyTexSubImage2D(yoffset+height)" );
1878 return;
1879 }
1880
1881 if (teximage->Data) {
1882 copy_tex_sub_image( ctx, teximage, width, height,
1883 x, y, xoffset, yoffset);
1884 }
1885 }
1886 else {
1887 gl_error( ctx, GL_INVALID_OPERATION, "glCopyTexSubImage2D" );
1888 }
1889}
GLint GLint GLint yoffset
Definition: gl.h:1547
GLuint Height
Definition: types.h:297

Referenced by execute_list(), and init_exec_pointers().

◆ gl_free_texture_image()

void gl_free_texture_image ( struct gl_texture_image teximage)

Definition at line 338 of file teximage.c.

339{
340 if (teximage->Data) {
341 free( teximage->Data );
342 }
343 free( teximage );
344}
#define free
Definition: debug_ros.c:5

Referenced by alloc_proxy_textures(), gl_free_texture_object(), gl_TexImage1D(), gl_TexImage2D(), gl_TexSubImage1D(), gl_TexSubImage2D(), and image_to_texture().

◆ gl_GetTexImage()

void gl_GetTexImage ( GLcontext ctx,
GLenum  target,
GLint  level,
GLenum  format,
GLenum  type,
GLvoid pixels 
)

Definition at line 1213 of file teximage.c.

1215{
1216 gl_problem(ctx, "glGetTexImage not implemented");
1217 /* TODO */
1218}
void gl_problem(const GLcontext *ctx, const char *s)
Definition: context.c:1394

Referenced by init_dlist_pointers(), and init_exec_pointers().

◆ gl_TexImage1D()

void gl_TexImage1D ( GLcontext ctx,
GLenum  target,
GLint  level,
GLint  internalformat,
GLsizei  width,
GLint  border,
GLenum  format,
GLenum  type,
struct gl_image image 
)

Definition at line 1049 of file teximage.c.

1053{
1054 if (INSIDE_BEGIN_END(ctx)) {
1055 gl_error( ctx, GL_INVALID_OPERATION, "glTexImage1D" );
1056 return;
1057 }
1058
1059 if (target==GL_TEXTURE_1D) {
1060 struct gl_texture_image *teximage;
1062 format, type, width, border )) {
1063 /* error in texture image was detected */
1064 return;
1065 }
1066
1067 /* free current texture image, if any */
1068 if (ctx->Texture.Current1D->Image[level]) {
1069 gl_free_texture_image( ctx->Texture.Current1D->Image[level] );
1070 }
1071
1072 /* make new texture from source image */
1073 if (image) {
1075 }
1076 else {
1078 width, 1, 1, border);
1079 }
1080
1081 /* install new texture image */
1082 ctx->Texture.Current1D->Image[level] = teximage;
1083 ctx->Texture.Current1D->Dirty = GL_TRUE;
1084 ctx->Texture.AnyDirty = GL_TRUE;
1085 ctx->NewState |= NEW_TEXTURING;
1086
1087 /* free the source image */
1088 if (image && image->RefCount==0) {
1089 /* if RefCount>0 then image must be in a display list */
1091 }
1092
1093 /* tell driver about change */
1094 if (ctx->Driver.TexImage) {
1095 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_1D,
1096 ctx->Texture.Current1D,
1097 level, internalformat, teximage );
1098 }
1099 }
1100 else if (target==GL_PROXY_TEXTURE_1D) {
1101 /* Proxy texture: check for errors and update proxy state */
1103 format, type, width, border )) {
1104 if (level>=0 && level<MAX_TEXTURE_LEVELS) {
1105 MEMSET( ctx->Texture.Proxy1D->Image[level], 0,
1106 sizeof(struct gl_texture_image) );
1107 }
1108 }
1109 else {
1110 ctx->Texture.Proxy1D->Image[level]->Format = internalformat;
1111 ctx->Texture.Proxy1D->Image[level]->Border = border;
1112 ctx->Texture.Proxy1D->Image[level]->Width = width;
1113 ctx->Texture.Proxy1D->Image[level]->Height = 1;
1114 }
1115 if (image && image->RefCount==0) {
1116 /* if RefCount>0 then image must be in a display list */
1118 }
1119 }
1120 else {
1121 gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(target)" );
1122 return;
1123 }
1124}
void gl_free_image(struct gl_image *image)
Definition: image.c:661
#define NEW_TEXTURING
Definition: types.h:1234
#define GL_TRUE
Definition: gl.h:174
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define GL_PROXY_TEXTURE_1D
Definition: gl.h:726
#define MEMSET(DST, VAL, N)
Definition: macros.h:241
static GLboolean texture_1d_error_check(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLenum format, GLenum type, GLint width, GLint border)
Definition: teximage.c:888
static struct gl_texture_image * make_null_texture(GLcontext *ctx, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border)
Definition: teximage.c:813
void gl_free_texture_image(struct gl_texture_image *teximage)
Definition: teximage.c:338
static struct gl_texture_image * image_to_texture(GLcontext *ctx, const struct gl_image *image, GLenum internalFormat, GLint border)
Definition: teximage.c:357

Referenced by execute_list(), gl_CopyTexImage1D(), and init_exec_pointers().

◆ gl_TexImage2D()

void gl_TexImage2D ( GLcontext ctx,
GLenum  target,
GLint  level,
GLint  internalformat,
GLsizei  width,
GLsizei  height,
GLint  border,
GLenum  format,
GLenum  type,
struct gl_image image 
)

Definition at line 1133 of file teximage.c.

1138{
1139 if (INSIDE_BEGIN_END(ctx)) {
1140 gl_error( ctx, GL_INVALID_OPERATION, "glTexImage2D" );
1141 return;
1142 }
1143
1144 if (target==GL_TEXTURE_2D) {
1145 struct gl_texture_image *teximage;
1147 format, type, width, height, border )) {
1148 /* error in texture image was detected */
1149 return;
1150 }
1151
1152 /* free current texture image, if any */
1153 if (ctx->Texture.Current2D->Image[level]) {
1154 gl_free_texture_image( ctx->Texture.Current2D->Image[level] );
1155 }
1156
1157 /* make new texture from source image */
1158 if (image) {
1160 }
1161 else {
1163 width, height, 1, border);
1164 }
1165
1166 /* install new texture image */
1167 ctx->Texture.Current2D->Image[level] = teximage;
1168 ctx->Texture.Current2D->Dirty = GL_TRUE;
1169 ctx->Texture.AnyDirty = GL_TRUE;
1170 ctx->NewState |= NEW_TEXTURING;
1171
1172 /* free the source image */
1173 if (image && image->RefCount==0) {
1174 /* if RefCount>0 then image must be in a display list */
1176 }
1177
1178 /* tell driver about change */
1179 if (ctx->Driver.TexImage) {
1180 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_2D,
1181 ctx->Texture.Current2D,
1182 level, internalformat, teximage );
1183 }
1184 }
1185 else if (target==GL_PROXY_TEXTURE_2D) {
1186 /* Proxy texture: check for errors and update proxy state */
1188 format, type, width, height, border )) {
1189 if (level>=0 && level<MAX_TEXTURE_LEVELS) {
1190 MEMSET( ctx->Texture.Proxy2D->Image[level], 0,
1191 sizeof(struct gl_texture_image) );
1192 }
1193 }
1194 else {
1195 ctx->Texture.Proxy2D->Image[level]->Format = internalformat;
1196 ctx->Texture.Proxy2D->Image[level]->Border = border;
1197 ctx->Texture.Proxy2D->Image[level]->Width = width;
1198 ctx->Texture.Proxy2D->Image[level]->Height = height;
1199 }
1200 if (image && image->RefCount==0) {
1201 /* if RefCount>0 then image must be in a display list */
1203 }
1204 }
1205 else {
1206 gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" );
1207 return;
1208 }
1209}
#define GL_PROXY_TEXTURE_2D
Definition: gl.h:727
static GLboolean texture_2d_error_check(GLcontext *ctx, GLenum target, GLint level, GLenum internalFormat, GLenum format, GLenum type, GLint width, GLint height, GLint border)
Definition: teximage.c:962

Referenced by execute_list(), gl_CopyTexImage2D(), and init_exec_pointers().

◆ gl_TexSubImage1D()

void gl_TexSubImage1D ( GLcontext ctx,
GLenum  target,
GLint  level,
GLint  xoffset,
GLsizei  width,
GLenum  format,
GLenum  type,
struct gl_image image 
)

Definition at line 1249 of file teximage.c.

1253{
1254 struct gl_texture_image *destTex;
1255
1256 if (target!=GL_TEXTURE_1D) {
1257 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(target)" );
1258 return;
1259 }
1261 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(level)" );
1262 return;
1263 }
1264
1265 destTex = ctx->Texture.Current1D->Image[level];
1266 if (!destTex) {
1267 gl_error( ctx, GL_INVALID_OPERATION, "glTexSubImage1D" );
1268 return;
1269 }
1270
1271 if (xoffset < -((GLint)destTex->Border)) {
1272 gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage1D(xoffset)" );
1273 return;
1274 }
1275 if (xoffset + width > destTex->Width + destTex->Border) {
1276 gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage1D(xoffset+width)" );
1277 return;
1278 }
1279
1280 if (image) {
1281 /* unpacking must have been error-free */
1282 GLint texcomponents = components_in_intformat(destTex->Format);
1283
1284 if (image->Type==GL_UNSIGNED_BYTE && texcomponents==image->Components) {
1285 /* Simple case, just byte copy image data into texture image */
1286 /* row by row. */
1287 GLubyte *dst = destTex->Data + texcomponents * xoffset;
1288 GLubyte *src = (GLubyte *) image->Data;
1289 MEMCPY( dst, src, width * texcomponents );
1290 }
1291 else {
1292 /* General case, convert image pixels into texels, scale, bias, etc */
1293 struct gl_texture_image *subTexImg = image_to_texture(ctx, image,
1294 destTex->IntFormat, destTex->Border);
1295 GLubyte *dst = destTex->Data + texcomponents * xoffset;
1296 GLubyte *src = subTexImg->Data;
1297 MEMCPY( dst, src, width * texcomponents );
1298 gl_free_texture_image(subTexImg);
1299 }
1300
1301 /* if the image's reference count is zero, delete it now */
1302 if (image->RefCount==0) {
1304 }
1305
1306 ctx->Texture.Current1D->Dirty = GL_TRUE;
1307 ctx->Texture.AnyDirty = GL_TRUE;
1308
1309 /* tell driver about change */
1310 if (ctx->Driver.TexSubImage) {
1311 (*ctx->Driver.TexSubImage)( ctx, GL_TEXTURE_1D,
1312 ctx->Texture.Current1D, level,
1313 xoffset,0,width,1,
1314 ctx->Texture.Current1D->Image[level]->IntFormat,
1315 destTex );
1316 }
1317 else {
1318 if (ctx->Driver.TexImage) {
1319 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_1D,
1320 ctx->Texture.Current1D,
1321 level, ctx->Texture.Current1D->Image[level]->IntFormat,
1322 destTex );
1323 }
1324 }
1325 }
1326 else {
1327 /* if no image, an error must have occured, do more testing now */
1329
1330 if (width<0) {
1331 gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage1D(width)" );
1332 return;
1333 }
1335 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(format)" );
1336 return;
1337 }
1341 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(format)" );
1342 return;
1343 }
1345 if (size<=0) {
1346 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(type)" );
1347 return;
1348 }
1349 /* if we get here, probably ran out of memory during unpacking */
1350 gl_error( ctx, GL_OUT_OF_MEMORY, "glTexSubImage1D" );
1351 }
1352}
GLint gl_sizeof_type(GLenum type)
Definition: image.c:163
#define GL_BITMAP
Definition: gl.h:497
#define GL_DEPTH_COMPONENT
Definition: gl.h:307
#define GL_STENCIL_INDEX
Definition: gl.h:458
GLsizeiptr size
Definition: glext.h:5919
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
GLenum Format
Definition: types.h:290
GLenum IntFormat
Definition: types.h:294

Referenced by execute_list(), and init_exec_pointers().

◆ gl_TexSubImage2D()

void gl_TexSubImage2D ( GLcontext ctx,
GLenum  target,
GLint  level,
GLint  xoffset,
GLint  yoffset,
GLsizei  width,
GLsizei  height,
GLenum  format,
GLenum  type,
struct gl_image image 
)

Definition at line 1356 of file teximage.c.

1362{
1363 struct gl_texture_image *destTex;
1364
1365 if (target!=GL_TEXTURE_2D) {
1366 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(target)" );
1367 return;
1368 }
1370 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(level)" );
1371 return;
1372 }
1373
1374 destTex = ctx->Texture.Current2D->Image[level];
1375 if (!destTex) {
1376 gl_error( ctx, GL_INVALID_OPERATION, "glTexSubImage2D" );
1377 return;
1378 }
1379
1380 if (xoffset < -((GLint)destTex->Border)) {
1381 gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(xoffset)" );
1382 return;
1383 }
1384 if (yoffset < -((GLint)destTex->Border)) {
1385 gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(yoffset)" );
1386 return;
1387 }
1388 if (xoffset + width > destTex->Width + destTex->Border) {
1389 gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(xoffset+width)" );
1390 return;
1391 }
1392 if (yoffset + height > destTex->Height + destTex->Border) {
1393 gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(yoffset+height)" );
1394 return;
1395 }
1396
1397 if (image) {
1398 /* unpacking must have been error-free */
1399 GLint texcomponents = components_in_intformat(destTex->Format);
1400
1401 if (image->Type==GL_UNSIGNED_BYTE && texcomponents==image->Components) {
1402 /* Simple case, just byte copy image data into texture image */
1403 /* row by row. */
1404 GLubyte *dst = destTex->Data
1405 + (yoffset * destTex->Width + xoffset) * texcomponents;
1406 GLubyte *src = (GLubyte *) image->Data;
1407 GLint j;
1408 for (j=0;j<height;j++) {
1409 MEMCPY( dst, src, width * texcomponents );
1410 dst += destTex->Width * texcomponents * sizeof(GLubyte);
1411 src += width * texcomponents * sizeof(GLubyte);
1412 }
1413 }
1414 else {
1415 /* General case, convert image pixels into texels, scale, bias, etc */
1416 struct gl_texture_image *subTexImg = image_to_texture(ctx, image,
1417 destTex->IntFormat, destTex->Border);
1418 GLubyte *dst = destTex->Data
1419 + (yoffset * destTex->Width + xoffset) * texcomponents;
1420 GLubyte *src = subTexImg->Data;
1421 GLint j;
1422 for (j=0;j<height;j++) {
1423 MEMCPY( dst, src, width * texcomponents );
1424 dst += destTex->Width * texcomponents * sizeof(GLubyte);
1425 src += width * texcomponents * sizeof(GLubyte);
1426 }
1427 gl_free_texture_image(subTexImg);
1428 }
1429
1430 /* if the image's reference count is zero, delete it now */
1431 if (image->RefCount==0) {
1433 }
1434
1435 ctx->Texture.Current2D->Dirty = GL_TRUE;
1436 ctx->Texture.AnyDirty = GL_TRUE;
1437
1438 /* tell driver about change */
1439 if (ctx->Driver.TexSubImage) {
1440 (*ctx->Driver.TexSubImage)( ctx, GL_TEXTURE_2D, ctx->Texture.Current2D, level,
1442 ctx->Texture.Current2D->Image[level]->IntFormat,
1443 destTex );
1444 }
1445 else {
1446 if (ctx->Driver.TexImage) {
1447 (*ctx->Driver.TexImage)( ctx, GL_TEXTURE_2D, ctx->Texture.Current2D,
1448 level, ctx->Texture.Current2D->Image[level]->IntFormat,
1449 destTex );
1450 }
1451 }
1452 }
1453 else {
1454 /* if no image, an error must have occured, do more testing now */
1456
1457 if (width<0) {
1458 gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(width)" );
1459 return;
1460 }
1461 if (height<0) {
1462 gl_error( ctx, GL_INVALID_VALUE, "glTexSubImage2D(height)" );
1463 return;
1464 }
1466 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage1D(format)" );
1467 return;
1468 }
1472 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(format)" );
1473 return;
1474 }
1476 if (size<=0) {
1477 gl_error( ctx, GL_INVALID_ENUM, "glTexSubImage2D(type)" );
1478 return;
1479 }
1480 /* if we get here, probably ran out of memory during unpacking */
1481 gl_error( ctx, GL_OUT_OF_MEMORY, "glTexSubImage2D" );
1482 }
1483}
GLint gl_components_in_format(GLenum format)
Definition: image.c:193
#define for
Definition: utility.h:88

Referenced by execute_list(), and init_exec_pointers().

◆ gl_unpack_texsubimage()

struct gl_image * gl_unpack_texsubimage ( GLcontext ctx,
GLint  width,
GLint  height,
GLenum  format,
GLenum  type,
const GLvoid pixels 
)

Definition at line 1229 of file teximage.c.

1231{
1233 return NULL;
1234 }
1235
1237 return NULL;
1238 }
1239
1240 if (gl_sizeof_type(type)<=0) {
1241 return NULL;
1242 }
1243
1245}
#define NULL
Definition: types.h:112
struct gl_image * gl_unpack_image(GLcontext *ctx, GLint width, GLint height, GLenum srcFormat, GLenum srcType, const GLvoid *pixels)
Definition: image.c:314
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546

Referenced by _mesa_TexSubImage1D(), and _mesa_TexSubImage2D().

◆ image_to_texture()

static struct gl_texture_image * image_to_texture ( GLcontext ctx,
const struct gl_image image,
GLenum  internalFormat,
GLint  border 
)
static

Definition at line 357 of file teximage.c.

359{
361 struct gl_texture_image *texImage;
362 GLint numPixels, pixel;
363 GLboolean scaleOrBias;
364
365 assert(image);
366 assert(image->Width>0);
367 assert(image->Height>0);
368
369 /* internalFormat = decode_internal_format(internalFormat);*/
371 numPixels = image->Width * image->Height;
372
373 texImage = gl_alloc_texture_image();
374 if (!texImage)
375 return NULL;
376
378 texImage->IntFormat = internalFormat;
379 texImage->Border = border;
380 texImage->Width = image->Width;
381 texImage->Height = image->Height;
382 texImage->WidthLog2 = logbase2(image->Width - 2*border);
383 if (image->Height==1) /* 1-D texture */
384 texImage->HeightLog2 = 0;
385 else
386 texImage->HeightLog2 = logbase2(image->Height - 2*border);
387 texImage->Width2 = 1 << texImage->WidthLog2;
388 texImage->Height2 = 1 << texImage->HeightLog2;
389 texImage->MaxLog2 = MAX2( texImage->WidthLog2, texImage->HeightLog2 );
390 texImage->Data = (GLubyte *) malloc( numPixels * components );
391
392 assert(texImage->WidthLog2>=0);
393 assert(texImage->HeightLog2>=0);
394
395 if (!texImage->Data) {
396 /* out of memory */
397 gl_free_texture_image( texImage );
398 return NULL;
399 }
400
401 /* Determine if scaling and/or biasing is needed */
402 if (ctx->Pixel.RedScale!=1.0F || ctx->Pixel.RedBias!=0.0F ||
403 ctx->Pixel.GreenScale!=1.0F || ctx->Pixel.GreenBias!=0.0F ||
404 ctx->Pixel.BlueScale!=1.0F || ctx->Pixel.BlueBias!=0.0F ||
405 ctx->Pixel.AlphaScale!=1.0F || ctx->Pixel.AlphaBias!=0.0F) {
406 scaleOrBias = GL_TRUE;
407 }
408 else {
409 scaleOrBias = GL_FALSE;
410 }
411
412 switch (image->Type) {
413 case GL_BITMAP:
414 {
415 GLint shift = ctx->Pixel.IndexShift;
416 GLint offset = ctx->Pixel.IndexOffset;
417 /* MapIto[RGBA]Size must be powers of two */
418 GLint rMask = ctx->Pixel.MapItoRsize-1;
419 GLint gMask = ctx->Pixel.MapItoGsize-1;
420 GLint bMask = ctx->Pixel.MapItoBsize-1;
421 GLint aMask = ctx->Pixel.MapItoAsize-1;
422 GLint i, j;
423 GLubyte *srcPtr = (GLubyte *) image->Data;
424
425 assert( image->Format==GL_COLOR_INDEX );
426
427 for (j=0; j<image->Height; j++) {
428 GLubyte bitMask = 128;
429 for (i=0; i<image->Width; i++) {
430 GLint index;
432
433 /* Fetch image color index */
434 index = (*srcPtr & bitMask) ? 1 : 0;
435 bitMask = bitMask >> 1;
436 if (bitMask==0) {
437 bitMask = 128;
438 srcPtr++;
439 }
440 /* apply index shift and offset */
441 if (shift>=0) {
442 index = (index << shift) + offset;
443 }
444 else {
445 index = (index >> -shift) + offset;
446 }
447 /* convert index to RGBA */
448 red = (GLint) (ctx->Pixel.MapItoR[index & rMask] * 255.0F);
449 green = (GLint) (ctx->Pixel.MapItoG[index & gMask] * 255.0F);
450 blue = (GLint) (ctx->Pixel.MapItoB[index & bMask] * 255.0F);
451 alpha = (GLint) (ctx->Pixel.MapItoA[index & aMask] * 255.0F);
452
453 /* store texel (components are GLubytes in [0,255]) */
454 pixel = j * image->Width + i;
455 switch (texImage->Format) {
456 case GL_ALPHA:
457 texImage->Data[pixel] = alpha;
458 break;
459 case GL_LUMINANCE:
460 texImage->Data[pixel] = red;
461 break;
463 texImage->Data[pixel*2+0] = red;
464 texImage->Data[pixel*2+1] = alpha;
465 break;
466 case GL_INTENSITY:
467 texImage->Data[pixel] = red;
468 break;
469 case GL_RGB:
470 texImage->Data[pixel*3+0] = red;
471 texImage->Data[pixel*3+1] = green;
472 texImage->Data[pixel*3+2] = blue;
473 break;
474 case GL_RGBA:
475 texImage->Data[pixel*4+0] = red;
476 texImage->Data[pixel*4+1] = green;
477 texImage->Data[pixel*4+2] = blue;
478 texImage->Data[pixel*4+3] = alpha;
479 break;
480 default:
481 gl_problem(ctx,"Bad format in image_to_texture");
482 return NULL;
483 }
484 }
485 if (bitMask!=128) {
486 srcPtr++;
487 }
488 }
489 }
490 break;
491
492 case GL_UNSIGNED_BYTE:
493 for (pixel=0; pixel<numPixels; pixel++) {
495 switch (image->Format) {
496 case GL_COLOR_INDEX:
498 /* a paletted texture */
499 GLint index = ((GLubyte*)image->Data)[pixel];
500 red = index;
501 }
502 else {
503 /* convert color index to RGBA */
504 GLint index = ((GLubyte*)image->Data)[pixel];
505 red = 255.0F * ctx->Pixel.MapItoR[index];
506 green = 255.0F * ctx->Pixel.MapItoG[index];
507 blue = 255.0F * ctx->Pixel.MapItoB[index];
508 alpha = 255.0F * ctx->Pixel.MapItoA[index];
509 }
510 break;
511 case GL_RGB:
512 /* Fetch image RGBA values */
513 red = ((GLubyte*) image->Data)[pixel*3+0];
514 green = ((GLubyte*) image->Data)[pixel*3+1];
515 blue = ((GLubyte*) image->Data)[pixel*3+2];
516 alpha = 255;
517 break;
518 case GL_BGR_EXT:
519 blue = ((GLubyte*) image->Data)[pixel*3+0];
520 green = ((GLubyte*) image->Data)[pixel*3+1];
521 red = ((GLubyte*) image->Data)[pixel*3+2];
522 alpha = 255;
523 break;
524 case GL_RGBA:
525 red = ((GLubyte*) image->Data)[pixel*4+0];
526 green = ((GLubyte*) image->Data)[pixel*4+1];
527 blue = ((GLubyte*) image->Data)[pixel*4+2];
528 alpha = ((GLubyte*) image->Data)[pixel*4+3];
529 break;
530 case GL_BGRA_EXT:
531 blue = ((GLubyte*) image->Data)[pixel*4+0];
532 green = ((GLubyte*) image->Data)[pixel*4+1];
533 red = ((GLubyte*) image->Data)[pixel*4+2];
534 alpha = ((GLubyte*) image->Data)[pixel*4+3];
535 break;
536 case GL_RED:
537 red = ((GLubyte*) image->Data)[pixel];
538 green = 0;
539 blue = 0;
540 alpha = 255;
541 break;
542 case GL_GREEN:
543 red = 0;
544 green = ((GLubyte*) image->Data)[pixel];
545 blue = 0;
546 alpha = 255;
547 break;
548 case GL_BLUE:
549 red = 0;
550 green = 0;
551 blue = ((GLubyte*) image->Data)[pixel];
552 alpha = 255;
553 break;
554 case GL_ALPHA:
555 red = 0;
556 green = 0;
557 blue = 0;
558 alpha = ((GLubyte*) image->Data)[pixel];
559 break;
560 case GL_LUMINANCE:
561 red = ((GLubyte*) image->Data)[pixel];
562 green = red;
563 blue = red;
564 alpha = 255;
565 break;
567 red = ((GLubyte*) image->Data)[pixel*2+0];
568 green = red;
569 blue = red;
570 alpha = ((GLubyte*) image->Data)[pixel*2+1];
571 break;
572 default:
573 gl_problem(ctx,"Bad format (2) in image_to_texture");
574 return NULL;
575 }
576
577 if (scaleOrBias || ctx->Pixel.MapColorFlag) {
578 /* Apply RGBA scale and bias */
579 GLfloat r = red * (1.0F/255.0F);
580 GLfloat g = green * (1.0F/255.0F);
581 GLfloat b = blue * (1.0F/255.0F);
582 GLfloat a = alpha * (1.0F/255.0F);
583 if (scaleOrBias) {
584 /* r,g,b,a now in [0,1] */
585 r = r * ctx->Pixel.RedScale + ctx->Pixel.RedBias;
586 g = g * ctx->Pixel.GreenScale + ctx->Pixel.GreenBias;
587 b = b * ctx->Pixel.BlueScale + ctx->Pixel.BlueBias;
588 a = a * ctx->Pixel.AlphaScale + ctx->Pixel.AlphaBias;
589 r = CLAMP( r, 0.0F, 1.0F );
590 g = CLAMP( g, 0.0F, 1.0F );
591 b = CLAMP( b, 0.0F, 1.0F );
592 a = CLAMP( a, 0.0F, 1.0F );
593 }
594 /* Apply pixel maps */
595 if (ctx->Pixel.MapColorFlag) {
596 GLint ir = (GLint) (r*ctx->Pixel.MapRtoRsize);
597 GLint ig = (GLint) (g*ctx->Pixel.MapGtoGsize);
598 GLint ib = (GLint) (b*ctx->Pixel.MapBtoBsize);
599 GLint ia = (GLint) (a*ctx->Pixel.MapAtoAsize);
600 r = ctx->Pixel.MapRtoR[ir];
601 g = ctx->Pixel.MapGtoG[ig];
602 b = ctx->Pixel.MapBtoB[ib];
603 a = ctx->Pixel.MapAtoA[ia];
604 }
605 red = (GLint) (r * 255.0F);
606 green = (GLint) (g * 255.0F);
607 blue = (GLint) (b * 255.0F);
608 alpha = (GLint) (a * 255.0F);
609 }
610
611 /* store texel (components are GLubytes in [0,255]) */
612 switch (texImage->Format) {
613 case GL_COLOR_INDEX:
614 texImage->Data[pixel] = red; /* really an index */
615 break;
616 case GL_ALPHA:
617 texImage->Data[pixel] = alpha;
618 break;
619 case GL_LUMINANCE:
620 texImage->Data[pixel] = red;
621 break;
623 texImage->Data[pixel*2+0] = red;
624 texImage->Data[pixel*2+1] = alpha;
625 break;
626 case GL_INTENSITY:
627 texImage->Data[pixel] = red;
628 break;
629 case GL_RGB:
630 texImage->Data[pixel*3+0] = red;
631 texImage->Data[pixel*3+1] = green;
632 texImage->Data[pixel*3+2] = blue;
633 break;
634 case GL_RGBA:
635 texImage->Data[pixel*4+0] = red;
636 texImage->Data[pixel*4+1] = green;
637 texImage->Data[pixel*4+2] = blue;
638 texImage->Data[pixel*4+3] = alpha;
639 break;
640 default:
641 gl_problem(ctx,"Bad format (3) in image_to_texture");
642 return NULL;
643 }
644 }
645 break;
646
647 case GL_FLOAT:
648 for (pixel=0; pixel<numPixels; pixel++) {
650 switch (texImage->Format) {
651 case GL_COLOR_INDEX:
653 /* a paletted texture */
654 GLint index = (GLint) ((GLfloat*) image->Data)[pixel];
655 red = index;
656 }
657 else {
658 GLint shift = ctx->Pixel.IndexShift;
659 GLint offset = ctx->Pixel.IndexOffset;
660 /* MapIto[RGBA]Size must be powers of two */
661 GLint rMask = ctx->Pixel.MapItoRsize-1;
662 GLint gMask = ctx->Pixel.MapItoGsize-1;
663 GLint bMask = ctx->Pixel.MapItoBsize-1;
664 GLint aMask = ctx->Pixel.MapItoAsize-1;
665 /* Fetch image color index */
666 GLint index = (GLint) ((GLfloat*) image->Data)[pixel];
667 /* apply index shift and offset */
668 if (shift>=0) {
669 index = (index << shift) + offset;
670 }
671 else {
672 index = (index >> -shift) + offset;
673 }
674 /* convert index to RGBA */
675 red = ctx->Pixel.MapItoR[index & rMask];
676 green = ctx->Pixel.MapItoG[index & gMask];
677 blue = ctx->Pixel.MapItoB[index & bMask];
678 alpha = ctx->Pixel.MapItoA[index & aMask];
679 }
680 break;
681 case GL_RGB:
682 /* Fetch image RGBA values */
683 red = ((GLfloat*) image->Data)[pixel*3+0];
684 green = ((GLfloat*) image->Data)[pixel*3+1];
685 blue = ((GLfloat*) image->Data)[pixel*3+2];
686 alpha = 1.0;
687 break;
688 case GL_RGBA:
689 red = ((GLfloat*) image->Data)[pixel*4+0];
690 green = ((GLfloat*) image->Data)[pixel*4+1];
691 blue = ((GLfloat*) image->Data)[pixel*4+2];
692 alpha = ((GLfloat*) image->Data)[pixel*4+3];
693 break;
694 case GL_RED:
695 red = ((GLfloat*) image->Data)[pixel];
696 green = 0.0;
697 blue = 0.0;
698 alpha = 1.0;
699 break;
700 case GL_GREEN:
701 red = 0.0;
702 green = ((GLfloat*) image->Data)[pixel];
703 blue = 0.0;
704 alpha = 1.0;
705 break;
706 case GL_BLUE:
707 red = 0.0;
708 green = 0.0;
709 blue = ((GLfloat*) image->Data)[pixel];
710 alpha = 1.0;
711 break;
712 case GL_ALPHA:
713 red = 0.0;
714 green = 0.0;
715 blue = 0.0;
716 alpha = ((GLfloat*) image->Data)[pixel];
717 break;
718 case GL_LUMINANCE:
719 red = ((GLfloat*) image->Data)[pixel];
720 green = red;
721 blue = red;
722 alpha = 1.0;
723 break;
725 red = ((GLfloat*) image->Data)[pixel*2+0];
726 green = red;
727 blue = red;
728 alpha = ((GLfloat*) image->Data)[pixel*2+1];
729 break;
730 default:
731 gl_problem(ctx,"Bad format (4) in image_to_texture");
732 return NULL;
733 }
734
735 if (image->Format!=GL_COLOR_INDEX) {
736 /* Apply RGBA scale and bias */
737 if (scaleOrBias) {
738 red = red * ctx->Pixel.RedScale + ctx->Pixel.RedBias;
739 green = green * ctx->Pixel.GreenScale + ctx->Pixel.GreenBias;
740 blue = blue * ctx->Pixel.BlueScale + ctx->Pixel.BlueBias;
741 alpha = alpha * ctx->Pixel.AlphaScale + ctx->Pixel.AlphaBias;
742 red = CLAMP( red, 0.0F, 1.0F );
743 green = CLAMP( green, 0.0F, 1.0F );
744 blue = CLAMP( blue, 0.0F, 1.0F );
745 alpha = CLAMP( alpha, 0.0F, 1.0F );
746 }
747 /* Apply pixel maps */
748 if (ctx->Pixel.MapColorFlag) {
749 GLint ir = (GLint) (red *ctx->Pixel.MapRtoRsize);
750 GLint ig = (GLint) (green*ctx->Pixel.MapGtoGsize);
751 GLint ib = (GLint) (blue *ctx->Pixel.MapBtoBsize);
752 GLint ia = (GLint) (alpha*ctx->Pixel.MapAtoAsize);
753 red = ctx->Pixel.MapRtoR[ir];
754 green = ctx->Pixel.MapGtoG[ig];
755 blue = ctx->Pixel.MapBtoB[ib];
756 alpha = ctx->Pixel.MapAtoA[ia];
757 }
758 }
759
760 /* store texel (components are GLubytes in [0,255]) */
761 switch (texImage->Format) {
762 case GL_COLOR_INDEX:
763 /* a paletted texture */
764 texImage->Data[pixel] = (GLint) (red * 255.0F);
765 break;
766 case GL_ALPHA:
767 texImage->Data[pixel] = (GLint) (alpha * 255.0F);
768 break;
769 case GL_LUMINANCE:
770 texImage->Data[pixel] = (GLint) (red * 255.0F);
771 break;
773 texImage->Data[pixel*2+0] = (GLint) (red * 255.0F);
774 texImage->Data[pixel*2+1] = (GLint) (alpha * 255.0F);
775 break;
776 case GL_INTENSITY:
777 texImage->Data[pixel] = (GLint) (red * 255.0F);
778 break;
779 case GL_RGB:
780 texImage->Data[pixel*3+0] = (GLint) (red * 255.0F);
781 texImage->Data[pixel*3+1] = (GLint) (green * 255.0F);
782 texImage->Data[pixel*3+2] = (GLint) (blue * 255.0F);
783 break;
784 case GL_RGBA:
785 texImage->Data[pixel*4+0] = (GLint) (red * 255.0F);
786 texImage->Data[pixel*4+1] = (GLint) (green * 255.0F);
787 texImage->Data[pixel*4+2] = (GLint) (blue * 255.0F);
788 texImage->Data[pixel*4+3] = (GLint) (alpha * 255.0F);
789 break;
790 default:
791 gl_problem(ctx,"Bad format (5) in image_to_texture");
792 return NULL;
793 }
794 }
795 break;
796
797 default:
798 gl_problem(ctx, "Bad image type in image_to_texture");
799 return NULL;
800 }
801
802 return texImage;
803}
#define index(s, c)
Definition: various.h:29
#define malloc
Definition: debug_ros.c:4
#define assert(x)
Definition: debug.h:53
#define GL_FLOAT
Definition: gl.h:183
#define GL_BLUE
Definition: gl.h:482
#define GL_RED
Definition: gl.h:480
#define GL_FALSE
Definition: gl.h:173
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
unsigned char GLboolean
Definition: gl.h:151
#define GL_GREEN
Definition: gl.h:481
#define GL_BGR_EXT
Definition: glext.h:3114
GLuint index
Definition: glext.h:6031
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean g
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLenum internalFormat
Definition: glext.h:8404
GLintptr offset
Definition: glext.h:5920
#define GL_BGRA_EXT
Definition: glext.h:3115
#define MAX2(A, B)
Definition: macros.h:163
#define shift
Definition: input.c:1755
GLuint MaxLog2
Definition: types.h:302
GLuint Height2
Definition: types.h:299
GLuint Width2
Definition: types.h:298
GLuint WidthLog2
Definition: types.h:300
GLuint HeightLog2
Definition: types.h:301
struct gl_texture_image * gl_alloc_texture_image(void)
Definition: teximage.c:331
static int logbase2(int n)
Definition: teximage.c:166
#define CLAMP(f, min, max)
Definition: tif_color.c:177

Referenced by gl_TexImage1D(), gl_TexImage2D(), gl_TexSubImage1D(), and gl_TexSubImage2D().

◆ logbase2()

static int logbase2 ( int  n)
static

Definition at line 166 of file teximage.c.

167{
168 GLint i = 1;
169 GLint log2 = 0;
170
171 if (n<0) {
172 return -1;
173 }
174
175 while ( n > i ) {
176 i *= 2;
177 log2++;
178 }
179 if (i != n) {
180 return -1;
181 }
182 else {
183 return log2;
184 }
185}
GLdouble n
Definition: glext.h:7729
_Check_return_ __CRT_INLINE double log2(_In_ double x)
Definition: math.h:301

Referenced by image_to_texture(), make_null_texture(), texture_1d_error_check(), and texture_2d_error_check().

◆ make_null_texture()

static struct gl_texture_image * make_null_texture ( GLcontext ctx,
GLenum  internalFormat,
GLsizei  width,
GLsizei  height,
GLsizei  depth,
GLint  border 
)
static

Definition at line 813 of file teximage.c.

815{
817 struct gl_texture_image *texImage;
818 GLint numPixels;
819
820 /*internalFormat = decode_internal_format(internalFormat);*/
822 numPixels = width * height * depth;
823
824 texImage = gl_alloc_texture_image();
825 if (!texImage)
826 return NULL;
827
829 texImage->IntFormat = internalFormat;
830 texImage->Border = border;
831 texImage->Width = width;
832 texImage->Height = height;
833 texImage->WidthLog2 = logbase2(width - 2*border);
834 if (height==1) /* 1-D texture */
835 texImage->HeightLog2 = 0;
836 else
837 texImage->HeightLog2 = logbase2(height - 2*border);
838 texImage->Width2 = 1 << texImage->WidthLog2;
839 texImage->Height2 = 1 << texImage->HeightLog2;
840 texImage->MaxLog2 = MAX2( texImage->WidthLog2, texImage->HeightLog2 );
841
842 /* XXX should we really allocate memory for the image or let it be NULL? */
843 /*texImage->Data = NULL;*/
844
845 texImage->Data = (GLubyte *) malloc( numPixels * components );
846
847 /*
848 * Let's see if anyone finds this. If glTexImage2D() is called with
849 * a NULL image pointer then load the texture image with something
850 * interesting instead of leaving it indeterminate.
851 */
852 if (texImage->Data) {
853 char message[8][32] = {
854 " X X XXXXX XXX X ",
855 " XX XX X X X X X ",
856 " X X X X X X X ",
857 " X X XXXX XXX XXXXX ",
858 " X X X X X X ",
859 " X X X X X X X ",
860 " X X XXXXX XXX X X ",
861 " "
862 };
863
864 GLubyte *imgPtr = texImage->Data;
865 GLint i, j, k;
866 for (i=0;i<height;i++) {
867 GLint srcRow = 7 - i % 8;
868 for (j=0;j<width;j++) {
869 GLint srcCol = j % 32;
870 GLubyte texel = (message[srcRow][srcCol]=='X') ? 255 : 70;
871 for (k=0;k<components;k++) {
872 *imgPtr++ = texel;
873 }
874 }
875 }
876 }
877
878 return texImage;
879}
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
int k
Definition: mpi.c:3369
Definition: tftpd.h:60

Referenced by gl_TexImage1D(), and gl_TexImage2D().

◆ read_color_image()

static struct gl_image * read_color_image ( GLcontext ctx,
GLint  x,
GLint  y,
GLsizei  width,
GLsizei  height,
GLint  format 
)
static

Definition at line 1493 of file teximage.c.

1496{
1497 struct gl_image *image;
1498 GLubyte *imgptr;
1500 GLint i, j;
1501
1503
1504 /*
1505 * Allocate image struct and image data buffer
1506 */
1507 image = (struct gl_image *) malloc( sizeof(struct gl_image) );
1508 if (image) {
1509 image->Width = width;
1510 image->Height = height;
1511 image->Components = components;
1512 image->Format = format;
1513 image->Type = GL_UNSIGNED_BYTE;
1514 image->RefCount = 0;
1515 image->Data = (GLubyte *) malloc( width * height * components );
1516 if (!image->Data) {
1517 free(image);
1518 return NULL;
1519 }
1520 }
1521 else {
1522 return NULL;
1523 }
1524
1525 imgptr = (GLubyte *) image->Data;
1526
1527 /* Select buffer to read from */
1528 (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Pixel.ReadBuffer );
1529
1530 for (j=0;j<height;j++) {
1534
1535 if (!ctx->Visual->EightBitColor) {
1536 /* scale red, green, blue, alpha values to range [0,255] */
1537 GLfloat rscale = 255.0f * ctx->Visual->InvRedScale;
1538 GLfloat gscale = 255.0f * ctx->Visual->InvGreenScale;
1539 GLfloat bscale = 255.0f * ctx->Visual->InvBlueScale;
1540 GLfloat ascale = 255.0f * ctx->Visual->InvAlphaScale;
1541 for (i=0;i<width;i++) {
1542 red[i] = (GLubyte) (GLint) (red[i] * rscale);
1543 green[i] = (GLubyte) (GLint) (green[i] * gscale);
1544 blue[i] = (GLubyte) (GLint) (blue[i] * bscale);
1545 alpha[i] = (GLubyte) (GLint) (alpha[i] * ascale);
1546 }
1547 }
1548
1549 switch (format) {
1550 case GL_ALPHA:
1551 for (i=0;i<width;i++) {
1552 *imgptr++ = alpha[i];
1553 }
1554 break;
1555 case GL_LUMINANCE:
1556 for (i=0;i<width;i++) {
1557 *imgptr++ = red[i];
1558 }
1559 break;
1560 case GL_LUMINANCE_ALPHA:
1561 for (i=0;i<width;i++) {
1562 *imgptr++ = red[i];
1563 *imgptr++ = alpha[i];
1564 }
1565 break;
1566 case GL_INTENSITY:
1567 for (i=0;i<width;i++) {
1568 *imgptr++ = red[i];
1569 }
1570 break;
1571 case GL_RGB:
1572 for (i=0;i<width;i++) {
1573 *imgptr++ = red[i];
1574 *imgptr++ = green[i];
1575 *imgptr++ = blue[i];
1576 }
1577 break;
1578 case GL_RGBA:
1579 for (i=0;i<width;i++) {
1580 *imgptr++ = red[i];
1581 *imgptr++ = green[i];
1582 *imgptr++ = blue[i];
1583 *imgptr++ = alpha[i];
1584 }
1585 break;
1586 } /*switch*/
1587
1588 } /*for*/
1589
1590 /* Restore drawing buffer */
1591 (void) (*ctx->Driver.SetBuffer)( ctx, ctx->Color.DrawBuffer );
1592
1593 return image;
1594}
GLeglImageOES image
Definition: gl.h:2204

Referenced by gl_CopyTexImage1D(), and gl_CopyTexImage2D().

◆ texture_1d_error_check()

static GLboolean texture_1d_error_check ( GLcontext ctx,
GLenum  target,
GLint  level,
GLenum  internalFormat,
GLenum  format,
GLenum  type,
GLint  width,
GLint  border 
)
static

Definition at line 888 of file teximage.c.

892{
893 GLint iformat;
895 gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D" );
896 return GL_TRUE;
897 }
899 gl_error( ctx, GL_INVALID_VALUE, "glTexImage1D(level)" );
900 return GL_TRUE;
901 }
903 if (iformat<0) {
904 gl_error( ctx, GL_INVALID_VALUE, "glTexImage1D(internalFormat)" );
905 return GL_TRUE;
906 }
907 if (border!=0 && border!=1) {
909 gl_error( ctx, GL_INVALID_VALUE, "glTexImage1D(border)" );
910 }
911 return GL_TRUE;
912 }
915 gl_error( ctx, GL_INVALID_VALUE, "glTexImage1D(width)" );
916 }
917 return GL_TRUE;
918 }
919 if (logbase2( width-2*border )<0) {
921 "glTexImage1D(width != 2^k + 2*border)");
922 return GL_TRUE;
923 }
924 switch (format) {
925 case GL_COLOR_INDEX:
926 case GL_RED:
927 case GL_GREEN:
928 case GL_BLUE:
929 case GL_ALPHA:
930 case GL_RGB:
931 case GL_BGR_EXT:
932 case GL_RGBA:
933 case GL_BGRA_EXT:
934 case GL_LUMINANCE:
936 /* OK */
937 break;
938 default:
939 gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(format)" );
940 return GL_TRUE;
941 }
942 switch (type) {
943 case GL_UNSIGNED_BYTE:
944 case GL_BYTE:
946 case GL_SHORT:
947 case GL_FLOAT:
948 /* OK */
949 break;
950 default:
951 gl_error( ctx, GL_INVALID_ENUM, "glTexImage1D(type)" );
952 return GL_TRUE;
953 }
954 return GL_FALSE;
955}
#define GL_UNSIGNED_SHORT
Definition: gl.h:180
#define GL_BYTE
Definition: gl.h:177
#define GL_SHORT
Definition: gl.h:179

Referenced by gl_TexImage1D().

◆ texture_2d_error_check()

static GLboolean texture_2d_error_check ( GLcontext ctx,
GLenum  target,
GLint  level,
GLenum  internalFormat,
GLenum  format,
GLenum  type,
GLint  width,
GLint  height,
GLint  border 
)
static

Definition at line 962 of file teximage.c.

967{
968 GLint iformat;
970 gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(target)" );
971 return GL_TRUE;
972 }
974 gl_error( ctx, GL_INVALID_VALUE, "glTexImage2D(level)" );
975 return GL_TRUE;
976 }
978 if (iformat<0) {
979 gl_error( ctx, GL_INVALID_VALUE, "glTexImage2D(internalFormat)" );
980 return GL_TRUE;
981 }
982 if (border!=0 && border!=1) {
984 gl_error( ctx, GL_INVALID_VALUE, "glTexImage2D(border)" );
985 }
986 return GL_TRUE;
987 }
990 gl_error( ctx, GL_INVALID_VALUE, "glTexImage2D(width)" );
991 }
992 return GL_TRUE;
993 }
996 gl_error( ctx, GL_INVALID_VALUE, "glTexImage2D(height)" );
997 }
998 return GL_TRUE;
999 }
1000 if (logbase2( width-2*border )<0) {
1002 "glTexImage2D(width != 2^k + 2*border)");
1003 return GL_TRUE;
1004 }
1005 if (logbase2( height-2*border )<0) {
1007 "glTexImage2D(height != 2^k + 2*border)");
1008 return GL_TRUE;
1009 }
1010 switch (format) {
1011 case GL_COLOR_INDEX:
1012 case GL_RED:
1013 case GL_GREEN:
1014 case GL_BLUE:
1015 case GL_ALPHA:
1016 case GL_RGB:
1017 case GL_BGR_EXT:
1018 case GL_RGBA:
1019 case GL_BGRA_EXT:
1020 case GL_LUMINANCE:
1021 case GL_LUMINANCE_ALPHA:
1022 /* OK */
1023 break;
1024 default:
1025 gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(format)" );
1026 return GL_TRUE;
1027 }
1028 switch (type) {
1029 case GL_UNSIGNED_BYTE:
1030 case GL_BYTE:
1031 case GL_UNSIGNED_SHORT:
1032 case GL_SHORT:
1033 case GL_UNSIGNED_INT:
1034 case GL_INT:
1035 case GL_FLOAT:
1036 /* OK */
1037 break;
1038 default:
1039 gl_error( ctx, GL_INVALID_ENUM, "glTexImage2D(type)" );
1040 return GL_TRUE;
1041 }
1042 return GL_FALSE;
1043}
#define GL_INT
Definition: gl.h:181
#define GL_UNSIGNED_INT
Definition: gl.h:182

Referenced by gl_TexImage2D().