Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor|Client: Continued splitting up gl_texmanager.h/cpp
  • Loading branch information
danij-deng committed Nov 21, 2013
1 parent 5b82e14 commit ec70eba
Show file tree
Hide file tree
Showing 8 changed files with 757 additions and 727 deletions.
1 change: 1 addition & 0 deletions doomsday/client/client.pro
Expand Up @@ -625,6 +625,7 @@ SOURCES += \
src/gl/gl_model.cpp \
src/gl/gl_tex.cpp \
src/gl/gl_texmanager.cpp \
src/gl/texturecontent.cpp \
src/gl/svg.cpp \
src/gl/sys_opengl.cpp \
src/hedge.cpp \
Expand Down
50 changes: 33 additions & 17 deletions doomsday/client/include/gl/gl_defer.h
@@ -1,6 +1,6 @@
/**
* @file gl_defer.h
* Deferred GL tasks. @ingroup gl
/** @file gl_defer.h Deferred GL tasks.
*
* @ingroup gl
*
* GL is only available from the main thread. When accessed from other threads,
* the operations need to be deferred for processing later in the main thread.
Expand All @@ -23,37 +23,44 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_GL_DEFERRED_H
#define LIBDENG_GL_DEFERRED_H
#ifndef DENG_CLIENT_GL_DEFERRED_H
#define DENG_CLIENT_GL_DEFERRED_H

#include "api_gl.h"
#include "sys_opengl.h"

#ifdef __cplusplus
extern "C" {
#endif
namespace de
{
namespace gl
{
enum UploadMethod {
Immediate, ///< Upload the data immediately.
Deferred ///< Defer the data upload until convenient.
};
}
}

struct texturecontent_s;

/**
* Initializes the deferred tasks module.
*/
void GL_InitDeferredTask(void);
void GL_InitDeferredTask();

/**
* Shuts down the deferred tasks.
*/
void GL_ShutdownDeferredTask(void);
void GL_ShutdownDeferredTask();

/**
* Clears the currently queued GL tasks. They will not be executed.
*/
void GL_PurgeDeferredTasks(void);
void GL_PurgeDeferredTasks();

/**
* @return Number of GL tasks waiting to be carried out.
*/
int GL_DeferredTaskCount(void);
int GL_DeferredTaskCount();

/**
* Processes deferred GL tasks. This must be called from the main thread.
Expand All @@ -63,22 +70,31 @@ int GL_DeferredTaskCount(void);
*/
void GL_ProcessDeferredTasks(uint timeOutMilliSeconds);

DGLuint GL_GetReservedTextureName(void);
DGLuint GL_GetReservedTextureName();

void GL_ReserveNames();

void GL_ReserveNames(void);
void GL_ReleaseReservedNames();

void GL_ReleaseReservedNames(void);
/**
* Returns the chosen method for uploading the given texture @a content.
*/
de::gl::UploadMethod GL_ChooseUploadMethod(struct texturecontent_s const *content);

/**
* Adds a new deferred texture upload task to the queue.
*
* @param content Texture content to upload. Caller can free its copy of the content;
* a copy is made for the deferred task.
*/
void GL_DeferTextureUpload(const struct texturecontent_s* content);
void GL_DeferTextureUpload(struct texturecontent_s const *content);

void GL_DeferSetVSync(boolean enableVSync);

#ifdef __cplusplus
extern "C" {
#endif

// Deferring functions for various function signatures.
#define LIBDENG_GL_DEFER1(form, x) void GL_Defer_##form(void (GL_CALL *ptr)(x), x)
#define LIBDENG_GL_DEFER2(form, x, y) void GL_Defer_##form(void (GL_CALL* ptr)(x, y), x, y)
Expand All @@ -95,4 +111,4 @@ LIBDENG_GL_DEFER2(uintArray, GLsizei count, const GLuint* values);
} // extern "C"
#endif

#endif /* LIBDENG_GL_DEFERRED_H */
#endif // DENG_CLIENT_GL_DEFERRED_H
46 changes: 1 addition & 45 deletions doomsday/client/include/gl/gl_texmanager.h
Expand Up @@ -31,6 +31,7 @@

#include "sys_opengl.h"

#include "gl/gl_defer.h"
#include "gl/texturecontent.h"
#include "resource/image.h"
#include "resource/rawtexture.h"
Expand Down Expand Up @@ -149,51 +150,6 @@ boolean GL_UploadTexture(int glFormat, int loadFormat, uint8_t const *pixels,
boolean GL_UploadTextureGrayMipmap(int glFormat, int loadFormat, uint8_t const *pixels,
int width, int height, float grayFactor);

/**
* Methods of uploading GL data.
*
* @ingroup GL
*/
enum GLUploadMethod
{
/// Upload the data immediately.
Immediate,

/// Defer the data upload until convenient.
Deferred
};

/**
* Returns the chosen method for uploading the given texture @a content.
*/
GLUploadMethod GL_ChooseUploadMethod(texturecontent_t const &content);

/**
* Prepare the texture content @a c, using the given image in accordance with
* the supplied specification. The image data will be transformed in-place.
*
* @param c Texture content to be completed.
* @param glTexName GL name for the texture we intend to upload.
* @param image Source image containing the pixel data to be prepared.
* @param spec Specification describing any transformations which
* should be applied to the image.
*
* @param textureManifest Manifest for the logical texture being prepared.
* (for informational purposes, i.e., logging)
*/
void GL_PrepareTextureContent(texturecontent_t &c, DGLuint glTexName,
image_t &image, texturevariantspecification_t const &spec,
de::TextureManifest const &textureManifest);

/**
* @param method GL upload method. By default the upload is deferred.
*
* @note Can be rather time-consuming due to forced scaling operations and
* the generation of mipmaps.
*/
void GL_UploadTextureContent(texturecontent_t const &content,
GLUploadMethod method = Deferred);

/**
* Prepare a TextureVariantSpecification according to usage context. If incomplete
* context information is supplied, suitable defaults are chosen in their place.
Expand Down
47 changes: 33 additions & 14 deletions doomsday/client/include/gl/texturecontent.h
@@ -1,8 +1,7 @@
/**
* @file texturecontent.h Texture Content
/** @file texturecontent.h GL-texture content.
*
* @author Copyright &copy; 2006-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright &copy; 2006-2013 Daniel Swanson <danij@dengine.net>
* @author Copyright © 2006-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @author Copyright © 2006-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -19,14 +18,12 @@
* 02110-1301 USA</small>
*/

#ifndef LIBDENG_TEXTURECONTENT_H
#define LIBDENG_TEXTURECONTENT_H
#ifndef DENG_CLIENT_GL_TEXTURECONTENT_H
#define DENG_CLIENT_GL_TEXTURECONTENT_H

#include "api_gl.h"

#ifdef __cplusplus
extern "C" {
#endif
#include "gl/gl_defer.h"
#include "TextureManifest"

/**
* @defgroup textureContentFlags Texture Content Flags
Expand Down Expand Up @@ -71,8 +68,30 @@ texturecontent_t *GL_ConstructTextureContentCopy(texturecontent_t const *other);

void GL_DestroyTextureContent(texturecontent_t *content);

#ifdef __cplusplus
} // extern "C"
#endif
/**
* Prepare the texture content @a c, using the given image in accordance with
* the supplied specification. The image data will be transformed in-place.
*
* @param c Texture content to be completed.
* @param glTexName GL name for the texture we intend to upload.
* @param image Source image containing the pixel data to be prepared.
* @param spec Specification describing any transformations which
* should be applied to the image.
*
* @param textureManifest Manifest for the logical texture being prepared.
* (for informational purposes, i.e., logging)
*/
void GL_PrepareTextureContent(texturecontent_t &c, DGLuint glTexName,
image_t &image, texturevariantspecification_t const &spec,
de::TextureManifest const &textureManifest);

/**
* @param method GL upload method. By default the upload is deferred.
*
* @note Can be rather time-consuming due to forced scaling operations and
* the generation of mipmaps.
*/
void GL_UploadTextureContent(texturecontent_t const &content,
de::gl::UploadMethod method = de::gl::Deferred);

#endif /* LIBDENG_TEXTURECONTENT_H */
#endif // DENG_CLIENT_GL_TEXTURECONTENT_H
17 changes: 16 additions & 1 deletion doomsday/client/src/gl/gl_defer.cpp
Expand Up @@ -34,6 +34,8 @@

#include "gl/texturecontent.h"

using namespace de;

#define NUM_RESERVED_TEXTURENAMES 512

typedef enum {
Expand Down Expand Up @@ -207,7 +209,7 @@ static void processTask(deferredtask_t *task)
case DTT_UPLOAD_TEXTURECONTENT:
DENG2_ASSERT(task->data);
GL_UploadTextureContent(*reinterpret_cast<texturecontent_t *>(task->data),
Immediate);
gl::Immediate);
break;

case DTT_SET_VSYNC:
Expand Down Expand Up @@ -433,6 +435,19 @@ void GL_ProcessDeferredTasks(uint timeOutMilliSeconds)
GL_ReserveNames();
}

gl::UploadMethod GL_ChooseUploadMethod(struct texturecontent_s const *content)
{
DENG2_ASSERT(content != 0);

// Must the operation be carried out immediately?
if((content->flags & TXCF_NEVER_DEFER) || !BusyMode_Active())
{
return gl::Immediate;
}
// We can defer.
return gl::Deferred;
}

void GL_DeferTextureUpload(struct texturecontent_s const *content)
{
if(novideo) return;
Expand Down

0 comments on commit ec70eba

Please sign in to comment.