summaryrefslogtreecommitdiffstats
path: root/src/VBox/GuestHost/OpenGL/packer/pack_swap_pixelmap.c
blob: 2336e8f8058c4a4244019a5c4bb31bde005b890f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Copyright (c) 2001, Stanford University
 * All rights reserved
 *
 * See the file LICENSE.txt for information on redistributing this software.
 */

#include "packer.h"

static unsigned char * __gl_HandlePixelMapData( GLenum map, GLsizei mapsize, int size_of_value, const GLvoid *values )
{
    int i;

    int packet_length = 
        sizeof( map ) + 
        sizeof( mapsize ) + 
        mapsize*size_of_value;
    unsigned char *data_ptr = (unsigned char *) crPackAlloc( packet_length );

    WRITE_DATA( 0, GLenum, SWAP32(map) );
    WRITE_DATA( 4, GLsizei, SWAP32(mapsize) );

    for (i = 0 ; i < mapsize ; i++)
    {
        switch( size_of_value )
        {
            case 2:
                WRITE_DATA( 8 + i*sizeof(GLshort), GLshort, SWAP16(*((GLshort *)values + i) ));
                break;
            case 4:
                WRITE_DATA( 8 + i*sizeof(GLint), GLint, SWAP32(*((GLint *)values + i) ));
                break;
        }
    }
    return data_ptr;
}

void PACK_APIENTRY crPackPixelMapfvSWAP(GLenum map, GLsizei mapsize, 
        const GLfloat *values )
{
    unsigned char *data_ptr = __gl_HandlePixelMapData( map, mapsize, sizeof( *values ), values );

    crHugePacket( CR_PIXELMAPFV_OPCODE, data_ptr );
    crPackFree( data_ptr );
}

void PACK_APIENTRY crPackPixelMapuivSWAP(GLenum map, GLsizei mapsize, 
        const GLuint *values )
{
    unsigned char *data_ptr = __gl_HandlePixelMapData( map, mapsize, sizeof( *values ), values );

    crHugePacket( CR_PIXELMAPUIV_OPCODE, data_ptr );
    crPackFree( data_ptr );
}

void PACK_APIENTRY crPackPixelMapusvSWAP(GLenum map, GLsizei mapsize, 
        const GLushort *values )
{
    unsigned char *data_ptr = __gl_HandlePixelMapData( map, mapsize, sizeof( *values ), values );

    crHugePacket( CR_PIXELMAPUSV_OPCODE, data_ptr );
    crPackFree( data_ptr );
}