You are on page 1of 9

void gltSetFrameBuffer(const GLint x, const GLint y, const GLint width, const GLint height) { //****Performance Checking**** //Color, Depth,

Stencil, 4Byte for each element; ctx->c_perfo.local_memory = width * height * 3 * 4; //**************************** //! Set the frame buffers size(Color, Stencil, and Depth buffer). SetFrameBuffer_size(width,height); SetDepthBuffer_size(width,height); SetStencilBuffer_size(width,height); //stencil : , SetScreen_coord(x,y); SetScreen_W_H(width,height); } //! Open the frame buffer. //!Through the system call, mmap(), to open the framebuffer-device. void gltOpenFrameBuffer(void) { SC_info.fbfd = open("/dev/fb0", O_RDWR); init_buffer_set(); // fb.c } //! Initial all default value of state machine. void gltInit(void) { //Set initial stack of Marix //Initial parameter of Lightting //Initial parameter of material //Initial parameter of light model //Initial the normalize opperation!! //glEnable and glDisable function //Texture Initialize //Fog Initialize //glPolygonOffset //glSampleCoverage }

glGenTextures(6, texture_objs); >> ioctl( ctx->fd, SYS_3D_create_slot, &ctx->gen_texture_t); //Ask the driver to create a texture table as a lined list void APIENTRY glGenTextures (GLsizei n, GLuint *textures) { struct context* ctx = &mycontext; //*****************GLtrace***************** #ifdef GLtrace FILE *fp; if((fp = fopen("./GLtrace/GLtrace.txt", "a+"))!=NULL){ fprintf(fp,"glGenTextures(%d, %d)\n", n,*textures); S } fclose(fp); #endif //***************************************** unsigned int i; for (i=0; i<n; i++) textures[i] = GetNextTexID(); ctx->gen_texture_t.gen_add=textures; //---------Texture mmp for HW----ctx->gen_texture_t.gen_num=n; ioctl( ctx->fd, SYS_3D_create_slot, &ctx->gen_texture_t); n=n-ctx->FreeNumTextures; printf("SYS_3D_create_slot::&gen_texture_t=%d ",&ctx->gen_texture_t); printf("Gen = %d,Free # = %d\n",n,ctx->FreeNumTextures); } glBindTexture(GL_TEXTURE_2D, texture_objs[0]); >> ioctl(ctx->fd, SYS_3D_bind_texture, texture); //Ask the driver to set the specific texture as active

void APIENTRY glBindTexture (GLenum target, GLuint texture) { struct context* ctx = &mycontext; //*****************GLtrace***************** #ifdef GLtrace FILE *fp; if((fp = fopen("./GLtrace/GLtrace.txt", "a+"))!=NULL){ if (target==GL_TEXTURE_2D){ fprintf(fp,"glBindTexture(GL_TEXTURE_2D, %d)\n",target,texture); } } fclose(fp); #endif //***************************************** if (target!=GL_TEXTURE_2D) { printf("error: BindTexture: unsupported Target!\n"); return; } if (IsTexture(texture)) // TEXTURE OBJ ALREADY EXISTS OR DEFAULT TEXTURE (0) { ctx->Texture_units[ctx->iCurrentBoundUnit].iCurrentBoundtex = ctx->iCurrentBoundTexture = texture; } else printf("error: BindTexture: invalid TexID (must use GenTextures)!\n"); // ---------Texture mmp for HW----ioctl( ctx->fd, SYS_3D_bind_texture, texture); printf("SYS_3D_bind_texture::textures=%d\n",texture); printf("id = %d\n",texture); } unsigned char *Texture = LoadPPM("./pic/fs1005-sc.ppm"); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 254, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, Texture); >> ioctl( ctx->fd, SYS_3D_create_texture, &ctx->tex_mmp_hw);

//Ask the driver to copy texture data from user-space to kernel-space //Update texture_addr of an entry in the texture table free(Texture);

// lighting_vertex lighting_fragment compiler API data char *vsSource = file2string("../lighting_vertex"); char *fsSource = file2string("../lighting_fragment"); // shader GLSL program program ctx->shader[100] // GL function GLSL_ES_function.c vertexshader = glCreateShader(GL_VERTEX_SHADER); fragmentshader = glCreateShader(GL_FRAGMENT_SHADER); GLuint glCreateShader(GLint type) { struct context *ctx = &mycontext; //printf("shadercount =%d\n",ctx->shader_count); int vacant_shader; //check the first vacant seat at shader obj[100] for(vacant_shader = 1; vacant_shader<100; vacant_shader++) //search the first vacant seat { if(ctx->shader[vacant_shader].count==0) break; } //printf("space =%d\n",vacant_shader); //!Vertex_shader or fragment_shader switch(type) { case GL_VERTEX_SHADER: ctx->shader_count++; ctx->shader[vacant_shader].type = "vertex_shader"; ctx->shader[vacant_shader].count = vacant_shader; break;

case GL_FRAGMENT_SHADER: ctx->shader_count++; ctx->shader[vacant_shader].type = "fragment_shader"; ctx->shader[vacant_shader].count = vacant_shader; break; default: printf("shader type error\n"); break; } return vacant_shader; }

glShaderSource(vertexshader, 1, &vsSource, NULL); glShaderSource(fragmentshader, 1, &fsSource, NULL); void glShaderSource(GLuint shader, GLsizei count, const char **string, const GLint *length) { struct context *ctx = &mycontext; int i; for(i=1;i<100;i++) { if(ctx->shader[i].count==shader) { /*if(ctx->shader[i].pointer) // add chck and free by Robarter@20121120(ref mesa,see main\shaderapi.c#{ln702}) { free((void *) ctx->shader[i].pointer); }*/ ctx->shader[i].pointer=string; ctx->shader[i].CompileStatus = GL_FALSE; Robarter@20121120 }

// add by

} }

ctx->shader[vertexshader].pointer = vsSource; ctx->shader[fragmentshader].pointer= fsSource; //glCompileShader Compiler_and_Linker-patch GLCompiler.cpp myglCompileShader function function Sub3y1_LLVM.c //Compile the OpenGL shading language glCompileShader(vertexshader); glCompileShader(fragmentshader); free(vsSource); free(fsSource);

GLuint progHandle; progHandle = glCreateProgram(); GLuint glCreateProgram() { struct context *ctx = &mycontext; int vacant_program; //check the first vacant seat at programobject program[50] for(vacant_program = 1; vacant_program<50; vacant_program++) //search the first vacant seat

{ if(ctx->program[vacant_program].programobject_count==0) break; } int i; ctx->program[vacant_program].shaders[0]=NULL; ctx->program[vacant_program].shaders[1]=NULL; for(i=0;i<256;i++) ctx->program[vacant_program].uniform[i].data_ptr=NULL; ctx->program_count++; ctx->program[ctx->program_count].programobject_count = vacant_program; return vacant_program; }

glAttachShader(progHandle, vertexshader); glAttachShader(progHandle, fragmentshader); void glAttachShader(GLuint program1, GLuint shader1) { /*if(programshader > 1){ printf("Error in AttachShader\n"); return; }*/ struct context *ctx = &mycontext; //!Attach the vertex_shader at array[0] and fragment shader at array[1] in program if(strcmp(ctx->shader[shader1].type, "vertex_shader") == 0){ if(ctx->program[program1].shaders[0] == NULL) ctx->program[program1].shaders[0] = &ctx->shader[shader1]; else return; }

else if(strcmp(ctx->shader[shader1].type, "fragment_shader") == 0){ if(ctx->program[program1].shaders[1] == NULL) ctx->program[program1].shaders[1] = &ctx->shader[shader1]; else return; } else{ printf("Shader type error in AttachShader\n"); } }

glBindAttribLocation(progHandle, 0, "rm_Vertex"); glBindAttribLocation(progHandle, 1, "rm_Normal"); glBindAttribLocation(progHandle, 2, "texcoord"); void glBindAttribLocation(GLuint program1, GLint index, char* string) { struct context *ctx = &mycontext; if(index < 8){ ctx->program[program1].attribute_name[index] = string; //ctx->program[program1].attribute[index] = GL_TRUE; ctx->Bind_count++; }else{ printf("Over attribute number\n"); } //printf("ctx->program[program1]->attribute_name[index] = %s\n",ctx->program[program1].attribute_name[index]); }

lighting_vertex gl_Position VOB FIFO FS register

You might also like