static int lite3d_shader_program_simple_uniform_set(
    lite3d_shader_program *program, lite3d_shader_parameter_container *p)
{
    SDL_assert(program);
    SDL_assert(program->success == LITE3D_TRUE);
    
    if (p->location == -1)
    {
        p->location = glGetUniformLocation(program->programID, p->parameter->name);
        if (p->location < 0)
        {
            p->location = -2; // not found 
            SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
                "%s: uniform '%s' not found in program %p",
                LITE3D_CURRENT_FUNCTION, p->parameter->name, (void *)program);
            return LITE3D_FALSE;
        }
    }
    else if (p->location == -2) // not found in past
        return LITE3D_FALSE;

    switch (p->parameter->type)
    {
        case LITE3D_SHADER_PARAMETER_INT:
            glUniform1i(p->location, p->parameter->parameter.valint);
            break;
        case LITE3D_SHADER_PARAMETER_FLOAT:
            glUniform1f(p->location, p->parameter->parameter.valfloat);
            break;
        case LITE3D_SHADER_PARAMETER_FLOATV3:
            glUniform3fv(p->location, 1, &p->parameter->parameter.valvec3.x);
            break;
        case LITE3D_SHADER_PARAMETER_FLOATV4:
            glUniform4fv(p->location, 1, &p->parameter->parameter.valvec4.x);
            break;
        case LITE3D_SHADER_PARAMETER_FLOATM3:
            glUniformMatrix3fv(p->location, 1, GL_FALSE, p->parameter->parameter.valmat3.mat);
            break;
        case LITE3D_SHADER_PARAMETER_FLOATM4:
            glUniformMatrix4fv(p->location, 1, GL_FALSE, p->parameter->parameter.valmat4.mat);
            break;
        default:
        {
            SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
                "%s: unknown type for parameter %s",
                LITE3D_CURRENT_FUNCTION, p->parameter->name);
            return LITE3D_FALSE;
        }
    }

    return LITE3D_TRUE;
}
Exemple #2
0
SDL_bool
KMSDRM_GLES_SetupCrtc(_THIS, SDL_Window * window) {
    SDL_WindowData *wdata = ((SDL_WindowData *) window->driverdata);
    SDL_DisplayData *displaydata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
    SDL_VideoData *vdata = ((SDL_VideoData *)_this->driverdata);
    KMSDRM_FBInfo *fb_info;

    if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, wdata->egl_surface))) {
	SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed on CRTC setup");
	return SDL_FALSE;
    }

    wdata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs);
    if (wdata->next_bo == NULL) {
	SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer on CRTC setup");
	return SDL_FALSE;
    }

    fb_info = KMSDRM_FBFromBO(_this, wdata->next_bo);
    if (fb_info == NULL) {
	return SDL_FALSE;
    }

    if(KMSDRM_drmModeSetCrtc(vdata->drm_fd, displaydata->crtc_id, fb_info->fb_id,
			    0, 0, &vdata->saved_conn_id, 1, &displaydata->cur_mode) != 0) {
       SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC to a GBM buffer");
       return SDL_FALSE;

    }
    
    wdata->crtc_ready = SDL_TRUE;
    return SDL_TRUE;
}
static int lite3d_shader_program_ubo_set(
    lite3d_shader_program *program, lite3d_shader_parameter_container *p)
{
    SDL_assert(program);
    SDL_assert(program->success == LITE3D_TRUE);
    SDL_assert(p->parameter->parameter.vbo);

    /* -1  mean what location unknown yet */
    if (p->location == -1)
    {
        p->location = glGetUniformBlockIndex(program->programID, p->parameter->name);
        if (p->location < 0)
        {
            p->location = -2;
            SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
                "%s: resource block '%s' not found in program %p",
                LITE3D_CURRENT_FUNCTION, p->parameter->name, (void *)program);
            return LITE3D_FALSE;
        }
    }
    else if (p->location == -2)
        return LITE3D_FALSE;
    
    if (p->binding < 0)
    {
        p->binding = p->bindContext->blockBindingsCount++;
        glUniformBlockBinding(program->programID, p->location, p->binding);
    }
    
    glBindBufferBase(GL_UNIFORM_BUFFER, p->binding, p->parameter->parameter.vbo->vboID);
    return LITE3D_TRUE;
}
static int lite3d_shader_program_sampler_set(
    lite3d_shader_program *program, lite3d_shader_parameter_container *p)
{
    SDL_assert(program);
    SDL_assert(program->success == LITE3D_TRUE);
    SDL_assert(p->parameter->parameter.texture);
    /* -1  mean what location unknown yet */
    if (p->location == -1)
    {
        p->location = glGetUniformLocation(program->programID, p->parameter->name);
        if (p->location < 0)
        {
            p->location = -2;
            SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
                "%s: sampler '%s' not found in program %p",
                LITE3D_CURRENT_FUNCTION, p->parameter->name, (void *)program);
            return LITE3D_FALSE;
        }
    }
    else if (p->location == -2)
        return LITE3D_FALSE;
    
    if (p->binding < 0)
        p->binding = p->bindContext->textureBindingsCount++;
    
    glUniform1i(p->location, p->binding);
    lite3d_texture_unit_bind(p->parameter->parameter.texture, p->binding);
    return LITE3D_TRUE;
}
static int
MIR_Available()
{
    int available = 0;

    if (SDL_MIR_LoadSymbols()) {

        /* Lets ensure we can connect to the mir server */
        MirConnection* connection = MIR_mir_connect_sync(NULL, __PRETTY_FUNCTION__);

        if (!MIR_mir_connection_is_valid(connection)) {
            SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Unable to connect to the mir server %s",
                MIR_mir_connection_get_error_message(connection));

            return available;
        }

        MIR_mir_connection_release(connection);

        available = 1;
        SDL_MIR_UnloadSymbols();
    }

    return available;
}
Exemple #6
0
void *load_opengl_command(const char *cmd) {
    void *r = SDL_GL_GetProcAddress(cmd);
    if (r == NULL) {
        SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Failed to load %s command.", cmd);
    }

    return r;
}
Exemple #7
0
int lite3d_vao_technique_init(void)
{
    instancingSupport = LITE3D_TRUE;

    if (!lite3d_check_vertex_array_object())
    {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
            "%s: GL_ARB_vertex_array_object not supported..", LITE3D_CURRENT_FUNCTION);
        return LITE3D_FALSE;
    }

    if (!lite3d_check_instanced_arrays())
    {
        SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
            "%s: GL_ARB_instanced_arrays not supported..", LITE3D_CURRENT_FUNCTION);
        instancingSupport = LITE3D_FALSE;
    }

    return LITE3D_TRUE;
}
Exemple #8
0
void Log::vsnprint(LogLevel logLevel, LogCategory category, const char* msg, va_list args) {
	char buf[1024];
	const char *categoryStr = LogTypes[static_cast<int>(category)];
	SDL_vsnprintf(buf, sizeof(buf), msg, args);
	buf[sizeof(buf) - 1] = '\0';

	switch (logLevel) {
		case LogLevel::LEVEL_INFO:
			SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, ANSI_COLOR_GREEN "(%s): %s" ANSI_COLOR_RESET "\n", categoryStr, buf);
			for (ConsolesConstIter i = _consoles.begin(); i != _consoles.end(); ++i) {
				(*i)->logInfo(buf);
			}
			break;
		case LogLevel::LEVEL_WARN:
			SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, ANSI_COLOR_YELLOW "(%s): %s" ANSI_COLOR_RESET "\n", categoryStr, buf);
			for (ConsolesConstIter i = _consoles.begin(); i != _consoles.end(); ++i) {
				(*i)->logInfo(buf);
			}
			break;
		case LogLevel::LEVEL_ERROR:
			SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, ANSI_COLOR_RED "(%s): %s" ANSI_COLOR_RESET "\n", categoryStr, buf);
			for (ConsolesConstIter i = _consoles.begin(); i != _consoles.end(); ++i) {
				(*i)->logError(buf);
			}
			break;
		case LogLevel::LEVEL_DEBUG:
			SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, ANSI_COLOR_BLUE "(%s): %s" ANSI_COLOR_RESET "\n", categoryStr, buf);
			for (ConsolesConstIter i = _consoles.begin(); i != _consoles.end(); ++i) {
				(*i)->logDebug(buf);
			}
			break;
		case LogLevel::LEVEL_TRACE:
			SDL_LogVerbose(SDL_LOG_CATEGORY_APPLICATION, ANSI_COLOR_CYAN "(%s): %s" ANSI_COLOR_RESET "\n", categoryStr, buf);
			for (ConsolesConstIter i = _consoles.begin(); i != _consoles.end(); ++i) {
				(*i)->logTrace(buf);
			}
			break;
		default:
			break;
	}
}
Exemple #9
0
int btn_Create( Vector2 position, Vector2 size, const char* text, int fontID, int normalImg, int focusedImg, int clickedImg,
	unsigned int camFlags, char layer, ButtonResponse pressResponse, ButtonResponse releaseResponse )
{
	int newIdx;

	newIdx = 0;
	while( ( newIdx < MAX_BUTTONS ) && ( buttons[newIdx].inUse == 1 ) ) {
		++newIdx;
	}

	if( newIdx >= MAX_BUTTONS ) {
		SDL_LogWarn( SDL_LOG_CATEGORY_SYSTEM, "Unable to create new button, no open slots." );
		return -1;
	}

	vec2_Scale( &size, 0.5f, &( buttons[newIdx].halfSize ) );
	buttons[newIdx].position = position;
	
	buttons[newIdx].normalImgId = normalImg;
	buttons[newIdx].focusImgId = focusedImg;
	buttons[newIdx].clickedImdId = clickedImg;
	buttons[newIdx].layer = layer;
	buttons[newIdx].inUse = 1;
	buttons[newIdx].pressResponse = pressResponse;
	buttons[newIdx].releaseResponse = releaseResponse;
	buttons[newIdx].state = BS_NORMAL;
	buttons[newIdx].camFlags = camFlags;
	buttons[newIdx].fontID = fontID;

	if( text != NULL ) {
		strncpy( buttons[newIdx].text, text, BUTTON_TEXT_LEN );
		buttons[newIdx].text[BUTTON_TEXT_LEN] = 0;
	} else {
		memset( buttons[newIdx].text, 0, sizeof( buttons[newIdx].text ) );
	}

	return newIdx;
}
Exemple #10
0
void
KMSDRM_VideoQuit(_THIS)
{
    SDL_VideoData *vdata = ((SDL_VideoData *)_this->driverdata);

    SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_VideoQuit()");

    if (_this->gl_config.driver_loaded) {
        SDL_GL_UnloadLibrary();
    }

    if(vdata->saved_crtc != NULL) {
        if(vdata->drm_fd > 0 && vdata->saved_conn_id > 0) {
            /* Restore saved CRTC settings */
            drmModeCrtc *crtc = vdata->saved_crtc;
            if(KMSDRM_drmModeSetCrtc(vdata->drm_fd, crtc->crtc_id, crtc->buffer_id,
                                     crtc->x, crtc->y, &vdata->saved_conn_id, 1,
                                     &crtc->mode) != 0) {
                SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not restore original CRTC mode");
            }
        }
        KMSDRM_drmModeFreeCrtc(vdata->saved_crtc);
        vdata->saved_crtc = NULL;
    }
    if (vdata->gbm != NULL) {
        KMSDRM_gbm_device_destroy(vdata->gbm);
        vdata->gbm = NULL;
    }
    if (vdata->drm_fd >= 0) {
        close(vdata->drm_fd);
        SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Closed DRM FD %d", vdata->drm_fd);
        vdata->drm_fd = -1;
    }
#ifdef SDL_INPUT_LINUXEV
    SDL_EVDEV_Quit();
#endif
}
Exemple #11
0
Frame* CreateFramesFromJSON(json_t* root)
{
	if (!json_is_array(root))
	{
		SDL_LogError(
				SDL_LOG_CATEGORY_APPLICATION,
				"Frames is not JSON array"
				);
		return NULL;
	}

	Frame* frames = NULL;
	Frame** frameIter = &frames;
	uint32_t i = 0;

	for (i = 0; i < json_array_size(root); i++)
	{
		json_t* frameNode;

		frameNode = json_array_get(root, i);
		if (!json_is_object(frameNode))
		{
			SDL_LogWarn(
				SDL_LOG_CATEGORY_APPLICATION,
				"Frame is invalid JSON type. Expected object.\n"
			);
			continue;
		}

		while (*frameIter != NULL)
			frameIter = &((*frameIter)->next);

		*frameIter = CreateFrameFromJSON(frameNode);
	}

	return frames;
}
Exemple #12
0
Frame* CreateFrameFromJSON(json_t* root)
{
	if (!json_is_object(root))
	{
		SDL_LogError(
			SDL_LOG_CATEGORY_APPLICATION,
			"Frame is invalid JSON type. Expected object.\n"
		);

		return NULL;
	}

	json_t* name = NULL;
	json_t *x,*y,*width,*height;
	Frame* frame = NULL;

	name = json_object_get(root, "name");
	if (!json_is_string(name))
	{
		SDL_LogError(
			SDL_LOG_CATEGORY_APPLICATION,
			"Could not find name for frame.\n"
		);

		return NULL;
	}

	frame = CreateFrame();
	if (frame == NULL)
		return NULL;

	size_t size = strlen(json_string_value(name));
	frame->name = malloc(size + 1);
	strcpy(frame->name, json_string_value(name));

	x = json_object_get(root, "x");
	if (!json_is_integer(x))
	{
		SDL_LogWarn(
				SDL_LOG_CATEGORY_APPLICATION,
				"Could not get x value for frame '%s'",
				frame->name
				);
	}
	else
		frame->rect.x = json_integer_value(x);

	y = json_object_get(root, "y");
	if (!json_is_integer(y))
	{
		SDL_LogWarn(
				SDL_LOG_CATEGORY_APPLICATION,
				"Could not get y value for frame '%s'",
				frame->name
				);
	}
	else
		frame->rect.y = json_integer_value(y);

	width = json_object_get(root, "width");
	if (!json_is_integer(width))
	{
		SDL_LogWarn(
				SDL_LOG_CATEGORY_APPLICATION,
				"Could not get width value for frame '%s'",
				frame->name
				);
	}
	else
		frame->rect.w = json_integer_value(width);

	height = json_object_get(root, "height");
	if (!json_is_integer(height))
	{
		SDL_LogWarn(
				SDL_LOG_CATEGORY_APPLICATION,
				"Could not get height value for frame '%s'",
				frame->name
				);
	}
	else
		frame->rect.h = json_integer_value(height);

	return frame;
}
void packScanDir( const char* path, list_t* dirList )
{
  struct dirent *pent;
  struct stat st;
  char* buf=malloc(sizeof(char)*2048);
  DIR *pdir= opendir( path );

  if(pdir)
  {
    while( (pent=readdir(pdir)) )
    {
      //We're not going to read hidden files or . / ..
      if(pent->d_name[0] != '.')
      {
        sprintf(buf, "%s/%s",path,pent->d_name);
        if(stat(buf, &st)==0)
        {
          if( (st.st_mode&S_IFDIR)==S_IFDIR )
          {
            //Ignore the "wizznic" directory since it's allready added.
            if(strcmp( buf, "packs/000_wizznic" ) != 0)
            {
              char* pdstr = malloc( sizeof(char)*strlen(buf)+1 );
              strcpy( pdstr, buf );
              listAppendData( dirList, (void*)pdstr );
            }
          } else if(  (st.st_mode&S_IFREG) )
          {
            //It's a file, let's try and see if it's a bundle.
            int l = strlen(buf);
            if( l > 4 && strcasecmp( &buf[l-4] ,".wiz" )==0 )
            {

              l = debundle( buf, getUsrPackDir() );

              if( l == BUNDLE_SUCCESS )
              {
                SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Installed bundle '%s'.\n", buf);
                char* pdstr = malloc( sizeof(char)*strlen(buf)+1 );
                strcpy( pdstr, bundlePath() );
                listAppendData( dirList, (void*)pdstr );
                unlink( buf );
              } else if( l == BUNDLE_FAIL_CORRUPT )
              {
                SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "The bundle file '%s' is corrupt, deleting it.\n", buf);
                unlink( buf );
              } else if( l == BUNDLE_FAIL_UNSUPPORTED_VERSION )
              {
                SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "The bundle file '%s' is not supported by this version of Wizznic, please try and update Wizznic.\n", buf);
              } else if( l == BUNDLE_FAIL_DIR_EXISTS )
              {
                SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "The bundle file '%s' has already been installed.\n", buf);
              }

              bundlePathReset();
            }

          }
        } else {
          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "packScanDir(); Error: stat('%s') failed!\n", buf);
        }
      }
    }
    closedir(pdir);
  }

  free(buf);
}
int packAdd(const char* packDir, int isDLC)
{
  char* buf = malloc(sizeof(char)*2048);
  char* buf2= malloc(sizeof(char)*1024);
  char* val = malloc(sizeof(char)*1024);
  char* set = malloc(sizeof(char)*1024);

  //This block is for playlists
  list_t* playList=0;
  listItem* li=0;
  playListItem* pli=0;
  int i; //Counter

  FILE* f=0;
  packInfoType* ti = malloc(sizeof(packInfoType));
  ti->lives=3; //Default 3 lives, if pack do not define another number.
  ti->isDLC=isDLC;

  //Any levels? (Packs are invalid without a levels folder and atleast one level)
  sprintf(buf, "%s/levels/level000.wzp", packDir);

  //Initialize list for playlist
  playList = listInit(_freePlaylistItem);

  //Open packs/packname/info.ini
  sprintf(buf, "%s/info.ini", packDir);
  f = android_fopen(buf, "r");
  if(f)
  {
    while( fgets(buf, 128, f) )
    {
      stripNewLine(buf);
      if(splitVals('=',buf,set,val))
      {
        if(strcmp("author", set)==0)
        {
          ti->author = malloc( sizeof(char)*(strlen(val)+1+3) );
          sprintf(ti->author, "By %s", val);
        } else
        if(strcmp("packname", set)==0)
        {
          ti->name = malloc( sizeof(char)*(strlen(val)+1) );
          strcpy(ti->name,val);
        } else
        if(strcmp("comment", set)==0)
        {
          ti->comment = malloc( sizeof(char)*(strlen(val)+1+1) );
          sprintf(ti->comment, "-%s", val);
        } else
        if(strcmp("mus", set)==0)
        {
          //mus=00,song
          if( splitVals(',',val, buf,set ) && splitVals('-',buf,val,buf2) )
          {
              //val= from buf2=to set=song name
              pli = malloc( sizeof( playListItem ) );
              pli->from=atoi(val);
              pli->to=atoi(buf2);
              pli->song=malloc(sizeof(char)*strlen(set)+1);
              strcpy( pli->song, set );
              listAppendData( playList, (void*)pli );
          } else {
            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "   Playlist entry format is mus=XX-XX,song name.ogg where XX-XX is a level range.\n");
          }
        } else
        if(strcmp("lives", set)==0)
        {
          ti->lives = atoi(val);
        }
      } //Found =
    } //reading file

    //Close the info file.
    fclose(f);
  } else {
    //Fall back if no file was found.
    SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: '%s' not found, using defaults.\n",buf);
    ti->author = malloc( sizeof(char)* 20 );
    strcpy(ti->author, "info.ini not found");
    ti->comment=ti->author;
    ti->name = malloc( sizeof(char)*(strlen(packDir)+1) );
    strcpy(ti->name, packDir);
  }


  //Set path
  ti->path = malloc( sizeof(char)*(strlen(packDir)+1) );
  strcpy(ti->path,packDir);

  //Set pack icon
  sprintf(buf, "%s/icon.png", packDir);
  ti->icon = loadImg(buf);
  if(!ti->icon)
  {
    ti->icon = loadImg( "data/noicon.png" );
  }

  //Check if pack have a "finished" icon.
  sprintf(buf, "%s/finished.png", packDir);

  //Set ps.cp before entering makeLevelist, it makes use of packGetFile
  ps.cp = ti;

  //Add levels.
  ti->levels=0;
  ti->levels=makeLevelList(packDir); //makeLevelList looks in packDir/levels/

  //set number of levels in pack
  ti->numLevels = ti->levels->count - 1  ; //The last level does not count (because it is just a "completed" screen).


  //Add to list of packages
  listAppendData( ps.packs, (void*)ti );

  //Increase number of available packages
  ps.numPacks++;

  //Put playlist songs into levelfiles.
  li=&playList->begin;
  while( LISTFWD(playList,li) )
  {
    pli=(playListItem*)li->data;

    for(i=0; i<ti->numLevels;i++)
    {
      if(i >= pli->from && i <= pli->to)
      {
        levelInfo(i)->musicFile = malloc( sizeof(char)*strlen(pli->song)+1 );
        strcpy(levelInfo(i)->musicFile, pli->song);
      }
    }
  }

  //Clear playlist data
  listFree( playList );

  free(buf);
  free(buf2);
  free(val);
  free(set);

  return(ps.numPacks-1);
}
Exemple #15
0
int lite3d_main(const lite3d_global_settings *settings)
{
    int ret = LITE3D_FALSE;

    gGlobalSettings = *settings;

    /* begin lite3d initialization */

    /* setup memory */
    lite3d_memory_init(&gGlobalSettings.userAllocator);

    /* cleanup engine memory at exit */
    atexit(lite3d_memory_cleanup);

    /* setup logger */
    if(settings->logFile[0] == 0)
    {
        lite3d_logger_setup_stdout();
    }
    else
    {
        lite3d_logger_setup_file(settings->logFile);
    }

    lite3d_logger_set_logParams(
        gGlobalSettings.logLevel,
        gGlobalSettings.logFlushAlways,
        gGlobalSettings.logMuteStd);

    if (!lite3d_metrics_global_init())
    {
        goto ret_release_logger;
    }

    SDL_LogInfo(
        SDL_LOG_CATEGORY_APPLICATION,
        "====== lite3d %s ======",
        LITE3D_FULL_VERSION);

    /* setup SDL */
    if (!sdl_init())
    {
        goto ret_metrics;
    }

    if (SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH))
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "Could not insrease thread priority %s",
            SDL_GetError());
    }

    /* setup video */
    if (!lite3d_video_open(
          &gGlobalSettings.videoSettings,
          settings->logMuteStd))
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "Could not setup video");

        goto ret_sdl_quit;
    }

    /* setup textures technique */
    if (!lite3d_texture_technique_init(&gGlobalSettings.textureSettings))
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "Could not setup textures technique "
            "(lite3d_texture_technique_init)");

        goto ret_video_close;
    }

    /* setup textures technique */
    if (!lite3d_vbo_technique_init())
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "Could not setup VBO technique");
        goto ret_texture_shut;
    }

    /* setup vao technique */
    if (!lite3d_vao_technique_init())
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "Could not setup VAO technique");

        goto ret_texture_shut;
    }

    /* setup shaders technique */
    if (!lite3d_shader_program_technique_init())
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "Could not setup shaders technique");

        goto ret_texture_shut;
    }

    if (!lite3d_timer_technique_init())
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "Could not setup timer technique");

        goto ret_texture_shut;
    }

    /* init shader global parameters */
    lite3d_shader_global_parameters_init();

    if (!lite3d_framebuffer_technique_init())
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "Could not setup framebuffer techique");

        goto ret_texture_shut;
    }

    /* start main loop */
    lite3d_render_loop(&gGlobalSettings.renderLisneters);
    ret = LITE3D_TRUE;

#ifdef LITE3D_WITH_METRICS
    lite3d_metrics_global_write_to_log();
#endif

ret_texture_shut:
    lite3d_texture_technique_shut();

ret_video_close:
    lite3d_video_close();

ret_sdl_quit:
    SDL_Quit();

ret_metrics:
    lite3d_metrics_global_purge();

ret_release_logger:
    lite3d_logger_release();

    return ret;
}
Exemple #16
0
int
SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display, EGLenum platform)
{
    void *dll_handle = NULL, *egl_dll_handle = NULL; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
    const char *path = NULL;
    int egl_version_major = 0, egl_version_minor = 0;
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
    const char *d3dcompiler;
#endif

    if (_this->egl_data) {
        return SDL_SetError("OpenGL ES context already created");
    }

    _this->egl_data = (struct SDL_EGL_VideoData *) SDL_calloc(1, sizeof(SDL_EGL_VideoData));
    if (!_this->egl_data) {
        return SDL_OutOfMemory();
    }

#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_WINRT
    d3dcompiler = SDL_GetHint(SDL_HINT_VIDEO_WIN_D3DCOMPILER);
    if (!d3dcompiler) {
        if (WIN_IsWindowsVistaOrGreater()) {
            d3dcompiler = "d3dcompiler_46.dll";
        } else {
            d3dcompiler = "d3dcompiler_43.dll";
        }
    }
    if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
        if (SDL_LoadObject(d3dcompiler) == NULL) {
            SDL_ClearError();
        }
    }
#endif

#ifndef SDL_VIDEO_STATIC_ANGLE
    /* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
    path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
    if (path != NULL) {
        egl_dll_handle = SDL_LoadObject(path);
    }

    if (egl_dll_handle == NULL) {
        if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
            if (_this->gl_config.major_version > 1) {
                path = DEFAULT_OGL_ES2;
                egl_dll_handle = SDL_LoadObject(path);
#ifdef ALT_OGL_ES2
                if (egl_dll_handle == NULL) {
                    path = ALT_OGL_ES2;
                    egl_dll_handle = SDL_LoadObject(path);
                }
#endif

            } else {
                path = DEFAULT_OGL_ES;
                egl_dll_handle = SDL_LoadObject(path);
                if (egl_dll_handle == NULL) {
                    path = DEFAULT_OGL_ES_PVR;
                    egl_dll_handle = SDL_LoadObject(path);
                }
            }
        }
#ifdef DEFAULT_OGL         
        else {
            path = DEFAULT_OGL;
            egl_dll_handle = SDL_LoadObject(path);
        }
#endif        
    }
    _this->egl_data->egl_dll_handle = egl_dll_handle;

    if (egl_dll_handle == NULL) {
        return SDL_SetError("Could not initialize OpenGL / GLES library");
    }

    /* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
    if (egl_path != NULL) {
        dll_handle = SDL_LoadObject(egl_path);
    }   
    /* Try loading a EGL symbol, if it does not work try the default library paths */
    if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
        if (dll_handle != NULL) {
            SDL_UnloadObject(dll_handle);
        }
        path = SDL_getenv("SDL_VIDEO_EGL_DRIVER");
        if (path == NULL) {
            path = DEFAULT_EGL;
        }
        dll_handle = SDL_LoadObject(path);

#ifdef ALT_EGL
        if (dll_handle == NULL) {
            path = ALT_EGL;
            dll_handle = SDL_LoadObject(path);
        }
#endif

        if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
            if (dll_handle != NULL) {
                SDL_UnloadObject(dll_handle);
            }
            return SDL_SetError("Could not load EGL library");
        }
        SDL_ClearError();
    }
#endif

    _this->egl_data->dll_handle = dll_handle;

    /* Load new function pointers */
    LOAD_FUNC(eglGetDisplay);
    LOAD_FUNC(eglInitialize);
    LOAD_FUNC(eglTerminate);
    LOAD_FUNC(eglGetProcAddress);
    LOAD_FUNC(eglChooseConfig);
    LOAD_FUNC(eglGetConfigAttrib);
    LOAD_FUNC(eglCreateContext);
    LOAD_FUNC(eglDestroyContext);
    LOAD_FUNC(eglCreateWindowSurface);
    LOAD_FUNC(eglDestroySurface);
    LOAD_FUNC(eglMakeCurrent);
    LOAD_FUNC(eglSwapBuffers);
    LOAD_FUNC(eglSwapInterval);
    LOAD_FUNC(eglWaitNative);
    LOAD_FUNC(eglWaitGL);
    LOAD_FUNC(eglBindAPI);
    LOAD_FUNC(eglQueryString);
    LOAD_FUNC(eglGetError);

    if (_this->egl_data->eglQueryString) {
        /* EGL 1.5 allows querying for client version */
        const char *egl_version = _this->egl_data->eglQueryString(EGL_NO_DISPLAY, EGL_VERSION);
        if (egl_version != NULL) {
            if (SDL_sscanf(egl_version, "%d.%d", &egl_version_major, &egl_version_minor) != 2) {
                egl_version_major = 0;
                egl_version_minor = 0;
                SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "Could not parse EGL version string: %s", egl_version);
            }
        }
    }

    if (egl_version_major == 1 && egl_version_minor == 5) {
        LOAD_FUNC(eglGetPlatformDisplay);
    }

    _this->egl_data->egl_display = EGL_NO_DISPLAY;
#if !defined(__WINRT__)
    if (platform) {
        if (egl_version_major == 1 && egl_version_minor == 5) {
            _this->egl_data->egl_display = _this->egl_data->eglGetPlatformDisplay(platform, (void *)(size_t)native_display, NULL);
        } else {
            if (SDL_EGL_HasExtension(_this, SDL_EGL_CLIENT_EXTENSION, "EGL_EXT_platform_base")) {
                _this->egl_data->eglGetPlatformDisplayEXT = SDL_EGL_GetProcAddress(_this, "eglGetPlatformDisplayEXT");
                if (_this->egl_data->eglGetPlatformDisplayEXT) {
                    _this->egl_data->egl_display = _this->egl_data->eglGetPlatformDisplayEXT(platform, (void *)(size_t)native_display, NULL);
                }
            }
        }
    }
    /* Try the implementation-specific eglGetDisplay even if eglGetPlatformDisplay fails */
    if (_this->egl_data->egl_display == EGL_NO_DISPLAY) {
        _this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
    }
    if (_this->egl_data->egl_display == EGL_NO_DISPLAY) {
        return SDL_SetError("Could not get EGL display");
    }
    
    if (_this->egl_data->eglInitialize(_this->egl_data->egl_display, NULL, NULL) != EGL_TRUE) {
        return SDL_SetError("Could not initialize EGL");
    }
#endif

    if (path) {
        SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
    } else {
        *_this->gl_config.driver_path = '\0';
    }
    
    return 0;
}
Exemple #17
0
int
KMSDRM_CreateWindow(_THIS, SDL_Window * window)
{
    SDL_WindowData *wdata;
    SDL_VideoDisplay *display;
    SDL_VideoData *vdata = ((SDL_VideoData *)_this->driverdata);
    Uint32 surface_fmt, surface_flags;

    /* Allocate window internal data */
    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
    if (wdata == NULL) {
        SDL_OutOfMemory();
        goto error;
    }

    wdata->waiting_for_flip = SDL_FALSE;
    display = SDL_GetDisplayForWindow(window);

    /* Windows have one size for now */
    window->w = display->desktop_mode.w;
    window->h = display->desktop_mode.h;

    /* Maybe you didn't ask for a fullscreen OpenGL window, but that's what you get */
    window->flags |= (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);

    surface_fmt = GBM_FORMAT_XRGB8888;
    surface_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;

    if (!KMSDRM_gbm_device_is_format_supported(vdata->gbm, surface_fmt, surface_flags)) {
        SDL_LogWarn(SDL_LOG_CATEGORY_VIDEO, "GBM surface format not supported. Trying anyway.");
    }
    wdata->gs = KMSDRM_gbm_surface_create(vdata->gbm, window->w, window->h, surface_fmt, surface_flags);

#if SDL_VIDEO_OPENGL_EGL
    if (!_this->egl_data) {
        if (SDL_GL_LoadLibrary(NULL) < 0) {
            goto error;
        }
    }
    wdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) wdata->gs);

    if (wdata->egl_surface == EGL_NO_SURFACE) {
        SDL_SetError("Could not create EGL window surface");
        goto error;
    }
#endif /* SDL_VIDEO_OPENGL_EGL */

    /* In case we want low-latency, double-buffer video, we take note here */
    wdata->double_buffer = SDL_FALSE;
    if (SDL_GetHintBoolean(SDL_HINT_VIDEO_DOUBLE_BUFFER, SDL_FALSE)) {
        wdata->double_buffer = SDL_TRUE;
    }

    /* Window is created, but we have yet to set up CRTC to one of the GBM buffers if we want
       drmModePageFlip to work, and we can't do it until EGL is completely setup, because we
       need to do eglSwapBuffers so we can get a valid GBM buffer object to call
       drmModeSetCrtc on it. */
    wdata->crtc_ready = SDL_FALSE;

    /* Setup driver data for this window */
    window->driverdata = wdata;

    /* One window, it always has focus */
    SDL_SetMouseFocus(window);
    SDL_SetKeyboardFocus(window);

    /* Window has been successfully created */
    return 0;

error:
    if (wdata != NULL) {
#if SDL_VIDEO_OPENGL_EGL
        if (wdata->egl_surface != EGL_NO_SURFACE)
            SDL_EGL_DestroySurface(_this, wdata->egl_surface);
#endif /* SDL_VIDEO_OPENGL_EGL */
        if (wdata->gs != NULL)
            KMSDRM_gbm_surface_destroy(wdata->gs);
        SDL_free(wdata);
    }
    return -1;
}
Exemple #18
0
static int init_platform_gl_extensions(lite3d_video_settings *settings)
{
    SDL_SysWMinfo wminfo;
    SDL_VERSION(&wminfo.version);
    if (!SDL_GetWindowWMInfo(gRenderWindow, &wminfo))
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "SDL_GetWindowWMInfo: %s",
            SDL_GetError());

        return LITE3D_FALSE;
    }

#ifndef GLES
# ifdef PLATFORM_Windows

    if (!WGLEW_ARB_extensions_string)
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "SDL_GetWindowWMInfo: %s",
            SDL_GetError());

        return LITE3D_FALSE;
    }

    SDL_LogDebug(
        SDL_LOG_CATEGORY_APPLICATION,
        "%s: WGL Extensions %s",
        LITE3D_CURRENT_FUNCTION,
        (char *) wglGetExtensionsStringARB(GetDC(wminfo.info.win.window)));

# elif defined PLATFORM_Linux

    if (!GLXEW_VERSION_1_3)
    {
        SDL_LogCritical(
            SDL_LOG_CATEGORY_APPLICATION,
            "%s: GLX v1.3 not supported..",
            LITE3D_CURRENT_FUNCTION);

        return LITE3D_FALSE;
    }

    SDL_LogDebug(
        SDL_LOG_CATEGORY_APPLICATION,
        "%s: GLX Client %s",
        LITE3D_CURRENT_FUNCTION,
        (char *) glXGetClientString(wminfo.info.x11.display, 1));

    SDL_LogDebug(
        SDL_LOG_CATEGORY_APPLICATION,
        "%s: GLX Server %s",
        LITE3D_CURRENT_FUNCTION,
        (char *) glXQueryServerString(wminfo.info.x11.display, 0, 1));

    SDL_LogDebug(
        SDL_LOG_CATEGORY_APPLICATION,
        "%s: GLX Extensions %s",
        LITE3D_CURRENT_FUNCTION,
        (char *) glXQueryExtensionsString(wminfo.info.x11.display, 0));

# endif
#endif

    return LITE3D_TRUE;
}
Exemple #19
0
int lite3d_video_open(lite3d_video_settings *settings, int hideConsole)
{
    uint32_t windowFlags;
    SDL_DisplayMode displayMode;

    SDL_assert(settings);

#ifdef PLATFORM_Windows
    if (hideConsole)
    {
        FreeConsole();
    }
#endif

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, settings->colorBits > 24 ? 8 : 0);

    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 16);

    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

#ifndef GLES
    /* Specify openGL context */
    if (settings->FSAA > 1)
    {
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, settings->FSAA);
    }

    if (settings->glProfile == LITE3D_GL_PROFILE_CORE)
    {
      SDL_LogInfo(
          SDL_LOG_CATEGORY_APPLICATION,
          "Setting Core OpenGL Profile");

      SDL_GL_SetAttribute(
          SDL_GL_CONTEXT_PROFILE_MASK,
          SDL_GL_CONTEXT_PROFILE_CORE);

      set_opengl_version(settings);
    }
    else if (settings->glProfile == LITE3D_GL_PROFILE_COMPATIBILITY)
    {
      SDL_LogInfo(
          SDL_LOG_CATEGORY_APPLICATION,
          "Setting Compatibility OpenGL Profile");

      SDL_GL_SetAttribute(
          SDL_GL_CONTEXT_PROFILE_MASK,
          SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);

      set_opengl_version(settings);
    }
    else
    {
      SDL_LogInfo(
          SDL_LOG_CATEGORY_APPLICATION,
          "Using Default OpenGL Profile");

      SDL_LogInfo(
          SDL_LOG_CATEGORY_APPLICATION,
          "Using Default OpenGL Version");
    }
#endif

#ifdef WITH_GLES2
    SDL_GL_SetAttribute(
        SDL_GL_CONTEXT_PROFILE_MASK,
        SDL_GL_CONTEXT_PROFILE_ES);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

#elif WITH_GLES3
    SDL_GL_SetAttribute(
        SDL_GL_CONTEXT_PROFILE_MASK,
        SDL_GL_CONTEXT_PROFILE_ES);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#endif

    windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;
    if (settings->fullscreen)
    {
        windowFlags |= SDL_WINDOW_FULLSCREEN;
        windowFlags |= SDL_WINDOW_BORDERLESS;
    }

    if (settings->screenWidth == 0 || settings->screenHeight == 0)
    {
        if (!lite3d_video_get_display_size(
              &settings->screenWidth,
              &settings->screenHeight))
        {
          SDL_LogWarn(
              SDL_LOG_CATEGORY_APPLICATION,
              "lite3d_video_get_display_size failed");

            return LITE3D_FALSE;
        }
    }

    /* setup render window */
    gRenderWindow = SDL_CreateWindow(
        settings->caption,
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        settings->screenWidth,
        settings->screenHeight,
        windowFlags);

    if (!gRenderWindow)
    {
        SDL_LogCritical(
            SDL_LOG_CATEGORY_APPLICATION,
            "%s: SDL_CreateWindow failed..",
            LITE3D_CURRENT_FUNCTION);

        return LITE3D_FALSE;
    }

    SDL_LogInfo(
        SDL_LOG_CATEGORY_APPLICATION,
        "%s: render window created %dx%d (%s)",
        LITE3D_CURRENT_FUNCTION,
        settings->screenWidth,
        settings->screenHeight,
        settings->fullscreen ? "fullscreen" : "windowed");

    /* Create an OpenGL context associated with the window. */
    gGLContext = SDL_GL_CreateContext(gRenderWindow);
    if (!gGLContext)
    {
        SDL_LogCritical(
            SDL_LOG_CATEGORY_APPLICATION,
            "%s: GL Context create failed..",
            LITE3D_CURRENT_FUNCTION);

        return LITE3D_FALSE;
    }

    /* set gl context */
    SDL_GL_MakeCurrent(gRenderWindow, gGLContext);

    SDL_GetWindowDisplayMode(gRenderWindow, &displayMode);
    SDL_LogInfo(
        SDL_LOG_CATEGORY_APPLICATION,
        "%s: selected pixel format: %d bpp, %s",
        LITE3D_CURRENT_FUNCTION,
        SDL_BITSPERPIXEL(displayMode.format),
        SDL_GetPixelFormatName(displayMode.format));

    SDL_GL_SetSwapInterval(settings->vsync ? 1 : 0);

    if (!init_gl_extensions(settings))
    {
        SDL_LogWarn(
            SDL_LOG_CATEGORY_APPLICATION,
            "init_gl_extensions failed");

        lite3d_video_close();

        return LITE3D_FALSE;
    }

    if (!settings->hidden)
    {
        SDL_ShowWindow(gRenderWindow);
    }

    return LITE3D_TRUE;
}