Beispiel #1
0
	int gl_ShaderBinary(State& state){
		if (state.stack->is<LUA_TTABLE>(1) && state.stack->is<LUA_TNUMBER>(2) && state.stack->is<LUA_TSTRING>(3)){
			vector<unsigned int> shaders;
			size_t count = getArray<unsigned int>(state, 1, shaders);
			GLenum binaryFormat = state.stack->to<int>(2);
			string binary = state.stack->toLString(3);

			glShaderBinary(count, shaders.data(), binaryFormat, binary.c_str(), binary.length());
		}
		return 0;
	}
Beispiel #2
0
GLuint LoadShaderBinary(GLenum type, const void *shaderSrc, int size)
{
	GLuint shader;

	// Create the shader object
	shader = glCreateShader(type);
	if(shader == 0)
		return 0;
	// Load the shader source
	glShaderBinary(1, &shader, (GLenum)0, shaderSrc, size);

	return shader;
}
/*!***************************************************************************
 @Function		ShaderLoadBinaryFromMemory
 @Input			ShaderData		shader compiled binary data
 @Input			Size			size of shader binary data in bytes
 @Input			Type			type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
 @Input			Format			shader binary format
 @Output		pObject			the resulting shader object
 @Output		pReturnError	the error message if it failed
 @Return		SUCCESS on success and FAIL on failure (also fills the str string)
 @Description	Takes a shader binary from memory and passes it to the GL.
*****************************************************************************/
unsigned int ShaderLoadBinaryFromMemory(	const void* const ShaderData, 
											const size_t Size, 
											const GLenum Type, 
											const GLenum Format, 
											GLuint* const pObject) 
											//char* const pReturnError)
{
	// Create and compile the shader object
    *pObject = glCreateShader(Type);
    glShaderBinary(1, pObject, Format, ShaderData, (GLint)Size);
    if (glGetError() != GL_NO_ERROR)
    {
    	//*pReturnError = CString("Failed to load binary shader\n");
    	glDeleteShader(*pObject);
    	return FAIL;
    }
    return SUCCESS;
}
Beispiel #4
0
/*!***************************************************************************
 @Function		PVRTShaderLoadBinaryFromMemory
 @Input			ShaderData		shader compiled binary data
 @Input			Size			size of shader binary data in bytes
 @Input			Type			type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
 @Input			Format			shader binary format
 @Output		pObject			the resulting shader object
 @Output		pReturnError	the error message if it failed
 @Return		PVR_SUCCESS on success and PVR_FAIL on failure (also fills the str string)
 @Description	Takes a shader binary from memory and passes it to the GL.
*****************************************************************************/
EPVRTError PVRTShaderLoadBinaryFromMemory(	const void* const ShaderData,
											const size_t Size,
											const GLenum Type,
											const GLenum Format,
											GLuint* const pObject,
											CPVRTString* const pReturnError)
{
	/* Create and compile the shader object */
    *pObject = glCreateShader(Type);

    // Get the list of supported binary formats
    // and if (more then 0) find given Format among them
    GLint numFormats = 0;
    GLint *listFormats;
    int i;
    glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS,&numFormats);
    if(numFormats != 0) {
        listFormats = new GLint[numFormats];
        for(i=0;i<numFormats;++i)
            listFormats[i] = 0;
        glGetIntegerv(GL_SHADER_BINARY_FORMATS,listFormats);
        for(i=0;i<numFormats;++i) {
            if(listFormats[i] == (int) Format) {
                glShaderBinary(1, pObject, Format, ShaderData, (GLint)Size);
                if (glGetError() != GL_NO_ERROR)
                {
                    *pReturnError = CPVRTString("Failed to load binary shader\n");
                    glDeleteShader(*pObject);
                    return PVR_FAIL;
                }
                return PVR_SUCCESS;
            }
        }
        delete [] listFormats;
    }
    *pReturnError = CPVRTString("Failed to load binary shader\n");
    glDeleteShader(*pObject);
    return PVR_FAIL;
}
Beispiel #5
0
void ctr_rend_shader_init() {
	//manually create the program so we can use id 0
	GLuint prog_id = 0;
	shaderProgram_s *shaderprogram = (shaderProgram_s *)malloc(sizeof(*shaderprogram));
	if (shaderprogram == 0) {
		return;
	}
	ctr_handle_set(CTR_HANDLE_PROGRAM, prog_id, shaderprogram);

#ifdef _3DS
	shaderProgramInit(shaderprogram);
	//manually create the shader so we can use id 0
	GLuint vsh_id = 0;
	glShaderBinary(1, &vsh_id, 0, vshader_shbin, vshader_shbin_size);
	glAttachShader(prog_id, vsh_id);
	glLinkProgram(prog_id);

	// Get the location of the uniforms
	uLoc_projection = glGetUniformLocation(prog_id, "projection");
	uLoc_modelView = glGetUniformLocation(prog_id, "modelView");
	/*uLoc_lightVec = glGetUniformLocation(prog_id, "lightVec");
	uLoc_lightHalfVec = glGetUniformLocation(prog_id, "lightHalfVec");
	uLoc_lightClr = glGetUniformLocation(prog_id, "lightClr");
	uLoc_material = glGetUniformLocation(prog_id, "material");*/

	//set the default shader
	shaderProgramUse(shaderprogram);

	/*glUniformMatrix4fv(uLoc_material, 1, 0, material.m);
	glUniform4fv(uLoc_lightVec, 1, (float[]){ 0.0f, -1.0f, 0.0f, 0.0f });
	glUniform4fv(uLoc_lightHalfVec, 1, (float[]){ 0.0f, -1.0f, 0.0f, 0.0f });
	glUniform4fv(uLoc_lightClr, 1, (float[]){ 1.0f, 1.0f, 1.0f, 1.0f });*/
#endif

	ctr_state.bound_program = prog_id;

}
Beispiel #6
0
 void shader_binary(gl::sizei_t count, const  gl::uint_t * shaders, gl::enum_t binaryformat, const  void * binary, gl::sizei_t length) {
   glShaderBinary(count, shaders, binaryformat, binary, length);
 }
static GLES2_ShaderCacheEntry *
GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, SDL_BlendMode blendMode)
{
    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
    const GLES2_Shader *shader;
    const GLES2_ShaderInstance *instance = NULL;
    GLES2_ShaderCacheEntry *entry = NULL;
    GLint compileSuccessful = GL_FALSE;
    int i, j;

    /* Find the corresponding shader */
    shader = GLES2_GetShader(type, blendMode);
    if (!shader)
    {
        SDL_SetError("No shader matching the requested characteristics was found");
        return NULL;
    }
    
    /* Find a matching shader instance that's supported on this hardware */
    for (i = 0; i < shader->instance_count && !instance; ++i)
    {
        for (j = 0; j < rdata->shader_format_count && !instance; ++j)
        {
            if (!shader->instances)
                continue;
            if (!shader->instances[i])
                continue;
            if (shader->instances[i]->format != rdata->shader_formats[j])
                continue;
            instance = shader->instances[i];
        }
    }
    if (!instance)
    {
        SDL_SetError("The specified shader cannot be loaded on the current platform");
        return NULL;
    }

    /* Check if we've already cached this shader */
    entry = rdata->shader_cache.head;
    while (entry)
    {
        if (entry->instance == instance)
            break;
        entry = entry->next;
    }
    if (entry)
        return entry;

    /* Create a shader cache entry */
    entry = (GLES2_ShaderCacheEntry *)SDL_calloc(1, sizeof(GLES2_ShaderCacheEntry));
    if (!entry)
    {
        SDL_OutOfMemory();
        return NULL;
    }
    entry->type = type;
    entry->instance = instance;

    /* Compile or load the selected shader instance */
    glGetError();
    entry->id = glCreateShader(instance->type);
    if (instance->format == (GLenum)-1)
    {
        glShaderSource(entry->id, 1, (const char **)&instance->data, NULL);
        glCompileShader(entry->id);
        glGetShaderiv(entry->id, GL_COMPILE_STATUS, &compileSuccessful);
    }
    else
    {
        glShaderBinary(1, &entry->id, instance->format, instance->data, instance->length);
        compileSuccessful = GL_TRUE;
    }
    if (glGetError() != GL_NO_ERROR || !compileSuccessful)
    {
        char *info = NULL;
        int length;

        glGetShaderiv(entry->id, GL_INFO_LOG_LENGTH, &length);
        if (length > 0) {
            info = SDL_stack_alloc(char, length);
            if (info) {
                glGetShaderInfoLog(entry->id, length, &length, info);
            }
        }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL41_nglShaderBinary(JNIEnv *env, jclass clazz, jint count, jlong shaders, jint binaryformat, jlong binary, jint length, jlong function_pointer) {
	const GLuint *shaders_address = (const GLuint *)(intptr_t)shaders;
	const GLvoid *binary_address = (const GLvoid *)(intptr_t)binary;
	glShaderBinaryPROC glShaderBinary = (glShaderBinaryPROC)((intptr_t)function_pointer);
	glShaderBinary(count, shaders_address, binaryformat, binary_address, length);
}
Beispiel #9
0
static void
gears_init(void)
{
   GLuint v, f, program;
   const char *p;
   char msg[512];

   glEnable(GL_CULL_FACE);
   glEnable(GL_DEPTH_TEST);

   /* Compile the vertex shader */
   p = vertex_shader;
   v = glCreateShader(GL_VERTEX_SHADER);
   //glShaderSource(v, 1, &p, NULL);
   //glCompileShader(v);
   glShaderBinary(1,&v,0,rsxglgears_vpo,rsxglgears_vpo_size);
   glGetShaderInfoLog(v, sizeof msg, NULL, msg);
   printf("vertex shader info: %s\n", msg);

   /* Compile the fragment shader */
   p = fragment_shader;
   f = glCreateShader(GL_FRAGMENT_SHADER);
   //glShaderSource(f, 1, &p, NULL);
   //glCompileShader(f);
   glShaderBinary(1,&f,0,rsxglgears_fpo,rsxglgears_fpo_size);
   glGetShaderInfoLog(f, sizeof msg, NULL, msg);
   printf("fragment shader info: %s\n", msg);

   /* Create and link the shader program */
   program = glCreateProgram();
   glAttachShader(program, v);
   glAttachShader(program, f);

   glBindAttribLocation(program, 0, "position");
   glBindAttribLocation(program, 1, "normal");

   glLinkProgram(program);
   glGetProgramInfoLog(program, sizeof msg, NULL, msg);
   printf("info: %s\n", msg);
   
   summarize_program("rsxglgears",program);

   /* Enable the shaders */
   glUseProgram(program);

   /* Get the locations of the uniforms so we can access them */
   ModelViewProjectionMatrix_location = glGetUniformLocation(program, "ModelViewProjectionMatrix");
   NormalMatrix_location = glGetUniformLocation(program, "NormalMatrix");
   LightSourcePosition_location = glGetUniformLocation(program, "LightSourcePosition");
   MaterialColor_location = glGetUniformLocation(program, "MaterialColor");

   printf("locations: %i %i %i %i\n",
	  ModelViewProjectionMatrix_location,
	  NormalMatrix_location,
	  LightSourcePosition_location,
	  MaterialColor_location);

   /* Set the LightSourcePosition uniform which is constant throught the program */
   glUniform4fv(LightSourcePosition_location, 1, LightSourcePosition);

   /* make the gears */
   gear1 = create_gear(1.0, 4.0, 1.0, 20, 0.7);
   gear2 = create_gear(0.5, 2.0, 2.0, 10, 0.7);
   gear3 = create_gear(1.3, 2.0, 0.5, 10, 0.7);
}
Beispiel #10
0
void
rsxgltest_init(int argc,const char ** argv)
{
  tcp_printf("%s\n",__PRETTY_FUNCTION__);

  // Set up us the program:
  shaders[0] = glCreateShader(GL_VERTEX_SHADER);
  shaders[1] = glCreateShader(GL_FRAGMENT_SHADER);

  program = glCreateProgram();

  glAttachShader(program,shaders[0]);
  glAttachShader(program,shaders[1]);

  // Supply shader binaries:
  glShaderBinary(1,shaders,0,textures_vpo,textures_vpo_size);
  glShaderBinary(1,shaders + 1,0,textures_fpo,textures_fpo_size);

  // Link the program for real:
  glLinkProgram(program);
  glValidateProgram(program);

  GLint
    vertex_location = glGetAttribLocation(program,"vertex"),
    texcoord_location = glGetAttribLocation(program,"texcoord");
  tcp_printf("vertex_location: %i\n",vertex_location);
  tcp_printf("texcoord_location: %i\n",texcoord_location);

  ProjMatrix_location = glGetUniformLocation(program,"ProjMatrix");
  TransMatrix_location = glGetUniformLocation(program,"TransMatrix");
  c_location = glGetUniformLocation(program,"c");
  texture_location = glGetUniformLocation(program,"texture");
  tcp_printf("ProjMatrix_location: %i TransMatrix_location: %i c_location: %i texture_location: %i\n",
	     ProjMatrix_location,TransMatrix_location,c_location,texture_location);

  // Report on attributes:
  {
    GLint num_attribs = 0, attrib_name_length = 0;
    glGetProgramiv(program,GL_ACTIVE_ATTRIBUTES,&num_attribs);
    glGetProgramiv(program,GL_ACTIVE_ATTRIBUTE_MAX_LENGTH,&attrib_name_length);
    tcp_printf("%u attribs, name max length: %u\n",num_attribs,attrib_name_length);
    char szName[attrib_name_length + 1];

    for(size_t i = 0;i < num_attribs;++i) {
      GLint size = 0;
      GLenum type = 0;
      GLint location = 0;
      glGetActiveAttrib(program,i,attrib_name_length + 1,0,&size,&type,szName);
      location = glGetAttribLocation(program,szName);
      tcp_printf("\t%u: %s %u %u %u\n",i,szName,(unsigned int)location,(unsigned int)size,(unsigned int)type);
    }
  }

  // Report on uniforms:
  {
    GLint num_uniforms = 0, uniform_name_length = 0;
    glGetProgramiv(program,GL_ACTIVE_UNIFORMS,&num_uniforms);
    glGetProgramiv(program,GL_ACTIVE_UNIFORM_MAX_LENGTH,&uniform_name_length);
    tcp_printf("%u uniforms, name max length: %u\n",num_uniforms,uniform_name_length);
    char szName[uniform_name_length + 1];

    for(size_t i = 0;i < num_uniforms;++i) {
      GLint size = 0;
      GLenum type = 0;
      GLint location = 0;
      glGetActiveUniform(program,i,uniform_name_length + 1,0,&size,&type,szName);
      location = glGetUniformLocation(program,szName);
      tcp_printf("\t%u: %s %u %u %u\n",i,szName,(unsigned int)location,(unsigned int)size,(unsigned int)type);
    }
  }

  glUseProgram(program);

  const float identity[4][4] = { {1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1} };
  glUniformMatrix4fv(ProjMatrix_location,1,GL_FALSE,(const GLfloat *)identity);
  glUniformMatrix4fv(TransMatrix_location,1,GL_FALSE,(const GLfloat *)identity);

  glUniform1i(texture_location,0);

  // Set up us the vertex data:
  float geometry[] = {
    0, 0, 0, 1,
    0,0,

    1.0, 0, 0, 1,
    1,0,

    0.0, 1.0, 0, 1,
    0,1,

    1.0, 0, 0, 1,
    1,0,

    1.0, 1.0, 0, 1,
    1,1,

    0.0, 1.0, 0, 1,
    0,1
  };

  glGenBuffers(1,&buffer);
  glBindBuffer(GL_ARRAY_BUFFER,buffer);
  glBufferData(GL_ARRAY_BUFFER,sizeof(float) * 6 * 6,geometry,GL_STATIC_DRAW);
  glEnableVertexAttribArray(vertex_location);
  glEnableVertexAttribArray(texcoord_location);
  glVertexAttribPointer(vertex_location,4,GL_FLOAT,GL_FALSE,sizeof(float) * 6,0);
  glVertexAttribPointer(texcoord_location,2,GL_FLOAT,GL_FALSE,sizeof(float) * 6,(const GLvoid *)(sizeof(float) * 4));

  glBindBuffer(GL_ARRAY_BUFFER,0);

  // Textures:
  dice = loadPng(dice_bin);
  tcp_printf("dice size: %u %u\n",dice.width,dice.height);
  GLuint dice_buffer = 0;
  glGenBuffers(1,&dice_buffer);
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER,dice_buffer);
  glBufferData(GL_PIXEL_UNPACK_BUFFER,4 * dice.width * dice.height,dice.data,GL_STATIC_DRAW);
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER,0);

  uint8_t checkerboard_bgra[] = {
    255,0,0,255, 0,255,0,255,
    0,0,255,255, 255,255,255,255
  };

  uint8_t test_bgra[] = {
    192,128,64,255, 192,128,64,255,
    192,128,64,255, 192,128,64,255
  };

  glActiveTexture(GL_TEXTURE0);

  glGenTextures(1,&texture);
  glBindTexture(GL_TEXTURE_2D,texture);
  tcp_printf("texture name: %u\n",texture);

  //glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,2,2,0,GL_BGRA,GL_UNSIGNED_BYTE,checkerboard_bgra);
  //glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,2,2,0,GL_BGRA,GL_UNSIGNED_BYTE,0);
  //glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,dice.width,dice.height,0,GL_BGRA,GL_UNSIGNED_BYTE,dice.data);
  //glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,dice.width,dice.height,0,GL_BGRA,GL_UNSIGNED_BYTE,0);

  glTexStorage2D(GL_TEXTURE_2D,1,GL_RGBA,dice.width,dice.height);

  //glTexSubImage2D(GL_TEXTURE_2D,0,0,0,dice.width,dice.height,GL_BGRA,GL_UNSIGNED_BYTE,dice.data);

  glBindBuffer(GL_PIXEL_UNPACK_BUFFER,dice_buffer);
  glTexSubImage2D(GL_TEXTURE_2D,0,0,0,dice.width,dice.height,GL_BGRA,GL_UNSIGNED_BYTE,0);
  glBindBuffer(GL_PIXEL_UNPACK_BUFFER,0);

  report_glerror("glTexImage2D");

  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
Beispiel #11
0
	void cShader<S>::Load(const cBlob& zBlob, GLenum zBinaryFormat)
	{
		unsigned id[1] = {Id()};
		glShaderBinary(1, id,zBinaryFormat,zBlob.Data(), zBlob.Length());
		Compile();
	}
Beispiel #12
0
static int
_evas_gl_common_shader_program_source_init(Evas_GL_Program *p,
                                           Evas_GL_Program_Source *vert,
                                           Evas_GL_Program_Source *frag,
                                           const char *name)
{
   GLint ok;

   p->vert = glCreateShader(GL_VERTEX_SHADER);
   p->frag = glCreateShader(GL_FRAGMENT_SHADER);
#if defined (GLES_VARIETY_S3C6410)
   glShaderBinary(1, &(p->vert), 0, vert->bin, vert->bin_size);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   glShaderBinary(1, &(p->frag), 0, frag->bin, frag->bin_size);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
#else
   glShaderSource(p->vert, 1,
                  (const char **)&(vert->src), NULL);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   glCompileShader(p->vert);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   ok = 0;
   glGetShaderiv(p->vert, GL_COMPILE_STATUS, &ok);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   if (!ok)
     {
        gl_compile_link_error(p->vert, "compile vertex shader");
        ERR("Abort compile of shader vert (%s): %s", name, vert->src);
        return 0;
     }
   glShaderSource(p->frag, 1,
                        (const char **)&(frag->src), NULL);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   glCompileShader(p->frag);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   ok = 0;
   glGetShaderiv(p->frag, GL_COMPILE_STATUS, &ok);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   if (!ok)
     {
        gl_compile_link_error(p->frag, "compile fragment shader");
        ERR("Abort compile of shader frag (%s): %s", name, frag->src);
        return 0;
     }
#endif
   p->prog = glCreateProgram();
#if defined(GLES_VARIETY_S3C6410) || defined(GLES_VARIETY_SGX)
#else
   if ((glsym_glGetProgramBinary) && (glsym_glProgramParameteri))
      glsym_glProgramParameteri(p->prog, GL_PROGRAM_BINARY_RETRIEVABLE_HINT,
                                GL_TRUE);
#endif
   glAttachShader(p->prog, p->vert);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   glAttachShader(p->prog, p->frag);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");

   glBindAttribLocation(p->prog, SHAD_VERTEX, "vertex");
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   glBindAttribLocation(p->prog, SHAD_COLOR,  "color");
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   glBindAttribLocation(p->prog, SHAD_TEXUV,  "tex_coord");
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   glBindAttribLocation(p->prog, SHAD_TEXUV2, "tex_coord2");
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   glBindAttribLocation(p->prog, SHAD_TEXUV3, "tex_coord3");
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   glBindAttribLocation(p->prog, SHAD_TEXM, "tex_coordm");
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");

   glLinkProgram(p->prog);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   ok = 0;
   glGetProgramiv(p->prog, GL_LINK_STATUS, &ok);
   GLERR(__FUNCTION__, __FILE__, __LINE__, "");
   if (!ok)
     {
        gl_compile_link_error(p->prog, "link fragment and vertex shaders");
        ERR("Abort compile of shader frag (%s): %s", name, frag->src);
        ERR("Abort compile of shader vert (%s): %s", name, vert->src);
        return 0;
     }
   return 1;
}