Path: blob/21.2-virgl/src/glx/indirect_vertex_program.c
4558 views
/*1* (C) Copyright IBM Corporation 20052* 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* the rights to use, copy, modify, merge, publish, distribute, sub license,8* and/or sell copies of the Software, and to permit persons to whom the9* 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* IBM,19* AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,20* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF21* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE22* SOFTWARE.23*/2425#include <inttypes.h>26#include <GL/gl.h>27#include "indirect.h"28#include "glxclient.h"29#include "indirect_vertex_array.h"30#include <GL/glxproto.h>3132#if !defined(__GNUC__)33# define __builtin_expect(x, y) x34#endif3536static void37do_vertex_attrib_enable(GLuint index, GLboolean val)38{39struct glx_context *gc = __glXGetCurrentContext();40__GLXattribute *state = (__GLXattribute *) (gc->client_state_private);4142if (!__glXSetArrayEnable(state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB,43index, val)) {44__glXSetError(gc, GL_INVALID_ENUM);45}46}474849void50__indirect_glEnableVertexAttribArray(GLuint index)51{52do_vertex_attrib_enable(index, GL_TRUE);53}545556void57__indirect_glDisableVertexAttribArray(GLuint index)58{59do_vertex_attrib_enable(index, GL_FALSE);60}616263static void64get_parameter(unsigned opcode, unsigned size, GLenum target, GLuint index,65void *params)66{67struct glx_context *const gc = __glXGetCurrentContext();68Display *const dpy = gc->currentDpy;69const GLuint cmdlen = 12;7071if (__builtin_expect(dpy != NULL, 1)) {72GLubyte const *pc = __glXSetupVendorRequest(gc,73X_GLXVendorPrivateWithReply,74opcode, cmdlen);7576*((GLenum *) (pc + 0)) = target;77*((GLuint *) (pc + 4)) = index;78*((GLuint *) (pc + 8)) = 0;7980(void) __glXReadReply(dpy, size, params, GL_FALSE);81UnlockDisplay(dpy);82SyncHandle();83}84return;85}868788void89__indirect_glGetProgramEnvParameterfvARB(GLenum target, GLuint index,90GLfloat * params)91{92get_parameter(1296, 4, target, index, params);93}949596void97__indirect_glGetProgramEnvParameterdvARB(GLenum target, GLuint index,98GLdouble * params)99{100get_parameter(1297, 8, target, index, params);101}102103104void105__indirect_glGetProgramLocalParameterfvARB(GLenum target, GLuint index,106GLfloat * params)107{108get_parameter(1305, 4, target, index, params);109}110111112void113__indirect_glGetProgramLocalParameterdvARB(GLenum target, GLuint index,114GLdouble * params)115{116get_parameter(1306, 8, target, index, params);117}118119120void121__indirect_glGetVertexAttribPointerv(GLuint index, GLenum pname,122GLvoid ** pointer)123{124struct glx_context *const gc = __glXGetCurrentContext();125__GLXattribute *state = (__GLXattribute *) (gc->client_state_private);126127if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB) {128__glXSetError(gc, GL_INVALID_ENUM);129}130131if (!__glXGetArrayPointer(state, GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB,132index, pointer)) {133__glXSetError(gc, GL_INVALID_VALUE);134}135}136137138/**139* Get the selected attribute from the vertex array state vector.140*141* \returns142* On success \c GL_TRUE is returned. Otherwise, \c GL_FALSE is returned.143*/144static GLboolean145get_attrib_array_data(__GLXattribute * state, GLuint index, GLenum cap,146GLintptr * data)147{148GLboolean retval = GL_FALSE;149const GLenum attrib = GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB;150151switch (cap) {152case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:153retval = __glXGetArrayEnable(state, attrib, index, data);154break;155156case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:157retval = __glXGetArraySize(state, attrib, index, data);158break;159160case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:161retval = __glXGetArrayStride(state, attrib, index, data);162break;163164case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:165retval = __glXGetArrayType(state, attrib, index, data);166break;167168case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:169retval = __glXGetArrayNormalized(state, attrib, index, data);170break;171}172173174return retval;175}176177178static void179get_vertex_attrib(struct glx_context * gc, unsigned vop,180GLuint index, GLenum pname, xReply * reply)181{182Display *const dpy = gc->currentDpy;183GLubyte *const pc = __glXSetupVendorRequest(gc,184X_GLXVendorPrivateWithReply,185vop, 8);186187*((uint32_t *) (pc + 0)) = index;188*((uint32_t *) (pc + 4)) = pname;189190(void) _XReply(dpy, reply, 0, False);191}192193194void195__indirect_glGetVertexAttribiv(GLuint index, GLenum pname, GLint * params)196{197struct glx_context *const gc = __glXGetCurrentContext();198Display *const dpy = gc->currentDpy;199__GLXattribute *state = (__GLXattribute *) (gc->client_state_private);200xGLXSingleReply reply;201202203get_vertex_attrib(gc, 1303, index, pname, (xReply *) & reply);204205if (reply.size != 0) {206GLintptr data;207208209if (get_attrib_array_data(state, index, pname, &data)) {210*params = (GLint) data;211}212else {213if (reply.size == 1) {214*params = (GLint) reply.pad3;215}216else {217_XRead(dpy, (void *) params, 4 * reply.size);218}219}220}221222UnlockDisplay(dpy);223SyncHandle();224}225226227void228__indirect_glGetVertexAttribfv(GLuint index, GLenum pname,229GLfloat * params)230{231struct glx_context *const gc = __glXGetCurrentContext();232Display *const dpy = gc->currentDpy;233__GLXattribute *state = (__GLXattribute *) (gc->client_state_private);234xGLXSingleReply reply;235236237get_vertex_attrib(gc, 1302, index, pname, (xReply *) & reply);238239if (reply.size != 0) {240GLintptr data;241242243if (get_attrib_array_data(state, index, pname, &data)) {244*params = (GLfloat) data;245}246else {247if (reply.size == 1) {248(void) memcpy(params, &reply.pad3, sizeof(GLfloat));249}250else {251_XRead(dpy, (void *) params, 4 * reply.size);252}253}254}255256UnlockDisplay(dpy);257SyncHandle();258}259260261void262__indirect_glGetVertexAttribdv(GLuint index, GLenum pname,263GLdouble * params)264{265struct glx_context *const gc = __glXGetCurrentContext();266Display *const dpy = gc->currentDpy;267__GLXattribute *state = (__GLXattribute *) (gc->client_state_private);268xGLXSingleReply reply;269270271get_vertex_attrib(gc, 1301, index, pname, (xReply *) & reply);272273if (reply.size != 0) {274GLintptr data;275276277if (get_attrib_array_data(state, index, pname, &data)) {278*params = (GLdouble) data;279}280else {281if (reply.size == 1) {282(void) memcpy(params, &reply.pad3, sizeof(GLdouble));283}284else {285_XRead(dpy, (void *) params, 8 * reply.size);286}287}288}289290UnlockDisplay(dpy);291SyncHandle();292}293294295