static int setup_program(SceneData* sceneData, SceneObject* so, SoData* soData, GLuint* programHandle) { GLuint vShaderHandle; GLuint fShaderHandle; if ( -1 == setup_shaders( sceneData, so, soData, &vShaderHandle, &fShaderHandle ) ) return -1; char progKey[KEYSIZE]; snprintf (progKey, KEYSIZE, "%p,%p", &so->vShader, &so->fShader); GLuint program = (GLuint)hashmap_find(progKey, sceneData->mapShaderShader2Handle); size_t programUsers; if (program) { *programHandle = program; programUsers = (size_t)hashmap_find ( progKey, sceneData->countProgramUsers ); hashmap_insert ( progKey, (void*)(programUsers+1), sceneData->countProgramUsers ); } else { program = create_program( so->vShader, so->fShader, vShaderHandle, fShaderHandle ); if ( -1 == program ) return -1; list_add ( (void*)program, sceneData->listPrograms ); hashmap_insert ( progKey, (void*)program, sceneData->mapShaderShader2Handle ); hashmap_insert ( progKey, (void*)1, sceneData->countProgramUsers ); *programHandle = program; } return 0; }
static GLboolean test() { GLint prog, location; GLboolean pass = GL_TRUE; int i; float color[4] = {0, 0, 0, 1}; float DEGREES_30 = 0.523598776; prog = setup_shaders(); location = glGetUniformLocation(prog, "a"); for (i = 0; i <= 50; i++) { glUniform1f(location, (i - 25) * DEGREES_30); piglit_draw_rect((i % 10) * 10, (i / 10) * 10, 10, 10); } if (!piglit_check_gl_error(GL_NO_ERROR)) piglit_report_result(PIGLIT_FAIL); for (i = 0; i <= 50; i++) { color[0] = color[1] = sin((i - 25) * DEGREES_30) * 0.5 + 0.5; pass = piglit_probe_pixel_rgb((i % 10) * 10 + 5, (i / 10) * 10 + 5, color) && pass; } return pass; }
int initTexExt(int bcdev_id, tex_buffer_info_t *binfo) { PFNGLGETTEXSTREAMDEVICEATTRIBUTEIVIMGPROC glGetTexAttrIMG = NULL; PFNGLGETTEXSTREAMDEVICENAMEIMGPROC glGetTexDeviceIMG = NULL; const GLubyte *glext; const GLubyte *dev_name; if (!binfo) return -5; if (!(glext = glGetString(GL_EXTENSIONS))) return -1; #ifdef GLES_20 if (!strstr((char *)glext, "GL_IMG_texture_stream2")) #else if (!strstr((char *)glext, "GL_IMG_texture_stream")) #endif return -2; glTexBindStreamIMG = (PFNGLTEXBINDSTREAMIMGPROC)eglGetProcAddress("glTexBindStreamIMG"); glGetTexAttrIMG = (PFNGLGETTEXSTREAMDEVICEATTRIBUTEIVIMGPROC) eglGetProcAddress("glGetTexStreamDeviceAttributeivIMG"); glGetTexDeviceIMG = (PFNGLGETTEXSTREAMDEVICENAMEIMGPROC) eglGetProcAddress("glGetTexStreamDeviceNameIMG"); if (!glTexBindStreamIMG || !glGetTexAttrIMG || !glGetTexDeviceIMG) return -3; dev_name = glGetTexDeviceIMG(bcdev_id); if (!dev_name) return -4; glGetTexAttrIMG(bcdev_id, GL_TEXTURE_STREAM_DEVICE_NUM_BUFFERS_IMG, &binfo->n); glGetTexAttrIMG(bcdev_id, GL_TEXTURE_STREAM_DEVICE_WIDTH_IMG, &binfo->w); glGetTexAttrIMG(bcdev_id, GL_TEXTURE_STREAM_DEVICE_HEIGHT_IMG, &binfo->h); glGetTexAttrIMG(bcdev_id, GL_TEXTURE_STREAM_DEVICE_FORMAT_IMG, &binfo->fmt); #ifdef GLES_20 if (setup_shaders(bcdev_id, binfo->n)) return -5; #endif printf("\ndevice: %s num: %d, width: %d, height: %d, format: 0x%x\n", dev_name, binfo->n, binfo->w, binfo->h, binfo->fmt); return 0; }
struct renderer * renderer_create(struct vg_context *owner) { VGint i; struct renderer *renderer = CALLOC_STRUCT(renderer); if (!renderer) return NULL; renderer->owner = owner; renderer->pipe = owner->pipe; renderer->cso = owner->cso_context; setup_shaders(renderer); /* init vertex data that doesn't change */ for (i = 0; i < 4; i++) { renderer->vertices[i][0][3] = 1.0f; /* w */ renderer->vertices[i][1][2] = 0.0f; /* r */ renderer->vertices[i][1][3] = 1.0f; /* q */ } return renderer; }
void gpu_init(H264Context *h) { GPUH264Context * const g = &h->gpu; MpegEncContext * const s = &h->s; int pic_width = 16*s->mb_width, pic_height = 16*s->mb_height; int i; tp_3d.texTarget = GL_TEXTURE_3D; tp_3d.texInternalFormat = GL_LUMINANCE8; tp_3d.texFormat = GL_LUMINANCE; if(g->init) { printf("gpu_init called twice (Why?)\n"); return; } //screenWidth = 1920, screenHeight = 1088; screenWidth = pic_width, screenHeight = pic_height; printf("Initializing GPU Context\n"); initGPU(screenWidth, screenHeight); initGPGPU(screenWidth, screenHeight); glEnable(tp_3d.texTarget); //RUDD TEMP DPB is fixed at 64 for now //Nearest Power of 2? g->dpb_tex = createTexture(screenWidth, screenHeight, 16, tp_3d); g->dpb_free = ~0x0; //RUDD TEST for comparison g->lum_residual = av_mallocz(s->linesize * s->mb_height * 16 * sizeof(short)); g->cr_residual = av_mallocz(s->uvlinesize * s->mb_height * 8 * sizeof(short)); g->cb_residual = av_mallocz(s->uvlinesize * s->mb_height * 8 * sizeof(short)); //RUDD TODO size? g->block_buffer = av_mallocz(9000*sizeof(H264mb)); g->init = 1; setup_shaders(g); }
static GLboolean test() { GLint prog, location; GLboolean pass = GL_TRUE; int i; float color[4] = {0, 0, 0, 1}; float DEGREES_30 = 0.523598776; prog = setup_shaders(); location = glGetUniformLocation(prog, "a"); for (i = 0; i <= 50; i++) { glUniform1f(location, (i - 25) * DEGREES_30); piglit_draw_rect((i % 10) * 10, (i / 10) * 10, 10, 10); } assert(glGetError() == 0); for (i = 0; i <= 50; i++) { color[0] = color[1] = sin((i - 25) * DEGREES_30) * 0.5 + 0.5; pass = piglit_probe_pixel_rgb((i % 10) * 10 + 5, (i / 10) * 10 + 5, color) && pass; } return pass; }
static GLboolean test() { GLboolean pass = GL_TRUE; /* Prepare the shaders */ GLint prog = setup_shaders(); GLint uPixelSize = glGetUniformLocation(prog, "pixelSize"); GLint uTexUnit = glGetUniformLocation(prog, "texUnit"); GLuint scratchTex; int i; /* Pixel sizes in texture coordinates for the horizontal and vertical passes */ const float horizontal[2] = { 1.0 / piglit_width, 0 }; const float vertical[2] = { 0, 1.0 / piglit_height }; /* Texture and vertex coordinates */ const float tc[] = { 0,1, 1,1, 0,0, 0,0, 1,1, 1,0 }; const float vc[] = { -1,1, 1,1, -1,-1, -1,-1, 1,1, 1,-1 }; /* Draw the rectangle that we're going to blur */ piglit_draw_rect(-.5, -.5, 1, 1); /* Create a scratch texture */ glGenTextures(1, &scratchTex); glBindTexture(GL_TEXTURE_2D, scratchTex); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, piglit_width, piglit_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0); glUseProgram(prog); glUniform1i(uTexUnit, 0); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, tc); glVertexPointer(2, GL_FLOAT, 0, vc); /* Horizontal pass */ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, piglit_width, piglit_height); glUniform2fv(uPixelSize, 1, horizontal); glDrawArrays(GL_TRIANGLES, 0, 6); /* Vertical pass */ glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, piglit_width, piglit_height); glUniform2fv(uPixelSize, 1, vertical); glDrawArrays(GL_TRIANGLES, 0, 6); /* Clean up */ glUseProgram(0); glBindTexture(GL_TEXTURE_2D, 0); glDeleteTextures(1, &scratchTex); glDeleteProgram(prog); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); assert(glGetError() == 0); /* Test the sides */ for (i = 0; i < 26; i++) { float color[3]; color[0] = expected_edge[i] / 255.; color[1] = color[0]; color[2] = color[0]; pass = piglit_probe_pixel_rgb(50, 12 + i, color) && pass; pass = piglit_probe_pixel_rgb(50, piglit_height - 13 - i, color) && pass; pass = piglit_probe_pixel_rgb(12 + i, 50, color) && pass; pass = piglit_probe_pixel_rgb(piglit_width - 13 - i, 50, color) && pass; } /* Test the corners */ for (i = 0; i < 22; i++) { float color[3]; color[0] = expected_corner[i] / 255.; color[1] = color[0]; color[2] = color[0]; pass = piglit_probe_pixel_rgb(16 + i, 16 + i, color) && pass; pass = piglit_probe_pixel_rgb(16 + i, piglit_height - 17 - i, color) && pass; pass = piglit_probe_pixel_rgb(piglit_width - 17 - i, 16 + i, color) && pass; pass = piglit_probe_pixel_rgb(piglit_width - 17 - i, piglit_height - 17 - i, color) && pass; } return pass; }
void piglit_init(int argc, char **argv) { setup_shaders(); }