Skip to content

Commit

Permalink
Refactor|Resources: Moved texture resources to libdoomsday (big commit)
Browse files Browse the repository at this point in the history
This commit splits Texture to the generic res::Texture and
client-specific ClientTexture. Other classes moved to libdoomsday
include TextureScheme, TextureManifest, PatchName, and CompositeTexture.

All the texture-related objects are now owned by the Textures class,
which in turn owned by libdoomsday's Resources.

Also fixed a couple of errors in the implementation:

- Retaining references to TextureVariantSpec without any kind of
  reference counting, leading to use-after-free errors during engine
  reset.
- Pointers to owning TextureSchemes are now kept as direct pointers,
  which avoids problems during teardown (trying to iterate partially
  deleted scheme lists).
  • Loading branch information
skyjake committed Jul 10, 2016
1 parent e849f0e commit 331e2fe
Show file tree
Hide file tree
Showing 77 changed files with 2,259 additions and 1,960 deletions.
1 change: 1 addition & 0 deletions doomsday/apps/client/include/ClientTexture
@@ -0,0 +1 @@
#include "resource/clienttexture.h"
1 change: 0 additions & 1 deletion doomsday/apps/client/include/Texture

This file was deleted.

4 changes: 2 additions & 2 deletions doomsday/apps/client/include/gl/gl_main.h
Expand Up @@ -35,7 +35,7 @@

#include "gl/gltextureunit.h"
#include "render/viewports.h"
#include "Texture"
#include "ClientTexture"
#include <de/Matrix>

struct ColorRawf_s;
Expand Down Expand Up @@ -227,7 +227,7 @@ void GL_SetRawImage(lumpnum_t lumpNum, de::gl::Wrapping wrapS, de::gl::Wrapping
*
* @param tex Texture::Variant object which represents the GL texture to be bound.
*/
void GL_BindTexture(de::Texture::Variant *tex);
void GL_BindTexture(ClientTexture::Variant *tex);

void GL_BindTextureUnmanaged(GLuint texname, de::gl::Wrapping wrapS = de::gl::Repeat,
de::gl::Wrapping wrapT = de::gl::Repeat, de::gl::Filter = de::gl::Linear);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/include/gl/gltextureunit.h
Expand Up @@ -21,7 +21,7 @@
#ifndef DENG_CLIENT_GLTEXTUREUNIT_H
#define DENG_CLIENT_GLTEXTUREUNIT_H

#include "Texture"
#include "ClientTexture"
#include <de/GLTexture>
#include <de/Vector>

Expand Down
10 changes: 6 additions & 4 deletions doomsday/apps/client/include/gl/texturecontent.h
Expand Up @@ -23,7 +23,7 @@

#include "api_gl.h"
#include "gl/gl_defer.h"
#include "TextureManifest"
#include <doomsday/res/TextureManifest>

/**
* @defgroup textureContentFlags Texture Content Flags
Expand Down Expand Up @@ -81,9 +81,11 @@ void GL_DestroyTextureContent(texturecontent_t *content);
* @param textureManifest Manifest for the logical texture being prepared.
* (for informational purposes, i.e., logging)
*/
void GL_PrepareTextureContent(texturecontent_t &c, GLuint glTexName,
image_t &image, TextureVariantSpec const &spec,
de::TextureManifest const &textureManifest);
void GL_PrepareTextureContent(texturecontent_t &c,
GLuint glTexName,
image_t &image,
TextureVariantSpec const &spec,
res::TextureManifest const &textureManifest);

/**
* @param method GL upload method. By default the upload is deferred.
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/include/render/lumobj.h
Expand Up @@ -26,7 +26,7 @@
#include <de/Vector>

#include "MapObject"
#include "Texture"
#include "ClientTexture"

/**
* Luminous object. @ingroup render
Expand Down Expand Up @@ -194,7 +194,7 @@ class Lumobj : public world::MapObject
*
* @see setLightmap()
*/
de::Texture *lightmap(LightmapSemantic semantic) const;
ClientTexture *lightmap(LightmapSemantic semantic) const;

/**
* Change an attributed lightmap to the texture specified.
Expand All @@ -204,7 +204,7 @@ class Lumobj : public world::MapObject
*
* @see lightmap()
*/
Lumobj &setLightmap(LightmapSemantic semantic, de::Texture *newTexture);
Lumobj &setLightmap(LightmapSemantic semantic, ClientTexture *newTexture);

/**
* Returns the current flare size of the lumobj.
Expand Down
8 changes: 4 additions & 4 deletions doomsday/apps/client/include/render/r_draw.h
Expand Up @@ -23,7 +23,7 @@
#ifndef DENG_CLIENT_RENDER_MISC_H
#define DENG_CLIENT_RENDER_MISC_H

#include "Texture"
#include "ClientTexture"
#include "TextureVariantSpec"
#include <de/GLTexture>

Expand All @@ -38,10 +38,10 @@ void R_DrawViewBorder();
TextureVariantSpec const &Rend_PatchTextureSpec(int flags = 0,
de::gl::Wrapping wrapS = de::gl::ClampToEdge, de::gl::Wrapping wrapT = de::gl::ClampToEdge);

void R_DrawPatch(de::Texture &texture, int x, int y);
void R_DrawPatch(de::Texture &texture, int x, int y, int w, int h, bool useOffsets = true);
void R_DrawPatch(ClientTexture &texture, int x, int y);
void R_DrawPatch(ClientTexture &texture, int x, int y, int w, int h, bool useOffsets = true);

void R_DrawPatchTiled(de::Texture &texture, int x, int y, int w, int h,
void R_DrawPatchTiled(ClientTexture &texture, int x, int y, int w, int h,
de::gl::Wrapping wrapS, de::gl::Wrapping wrapT);

#endif // DENG_CLIENT_RENDER_MISC_H
12 changes: 6 additions & 6 deletions doomsday/apps/client/include/resource/animgroup.h
Expand Up @@ -22,7 +22,7 @@
#define DENG_RESOURCE_ANIMATIONGROUP_H

#include "dd_types.h"
#include "TextureManifest"
#include <doomsday/res/TextureManifest>
#include <QList>

namespace de {
Expand All @@ -44,7 +44,7 @@ class AnimGroup
/**
* Returns the texture manifest for the frame.
*/
TextureManifest &textureManifest() const;
res::TextureManifest &textureManifest() const;

/**
* Returns the duration of the frame in tics.
Expand All @@ -59,9 +59,9 @@ class AnimGroup
friend class AnimGroup;

private:
Frame(TextureManifest &textureManifest, ushort tics, ushort randomTics);
Frame(res::TextureManifest &textureManifest, ushort tics, ushort randomTics);

TextureManifest *_textureManifest;
res::TextureManifest *_textureManifest;
ushort _tics;
ushort _randomTics;
};
Expand Down Expand Up @@ -93,7 +93,7 @@ class AnimGroup
*
* @see frames()
*/
bool hasFrameFor(TextureManifest const &textureManifest) const;
bool hasFrameFor(res::TextureManifest const &textureManifest) const;

/**
* Append a new frame to the animation.
Expand All @@ -104,7 +104,7 @@ class AnimGroup
*
* @return The new frame.
*/
Frame &newFrame(TextureManifest &textureManifest, ushort tics,
Frame &newFrame(res::TextureManifest &textureManifest, ushort tics,
ushort randomTics = 0);

/**
Expand Down
220 changes: 220 additions & 0 deletions doomsday/apps/client/include/resource/clienttexture.h
@@ -0,0 +1,220 @@
/** @file texture.h Logical texture resource.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef DENG_RESOURCE_CLIENTTEXTURE_H
#define DENG_RESOURCE_CLIENTTEXTURE_H

#include "resource/image.h" // res::Source
#include "TextureVariantSpec"

#include <doomsday/res/Texture>

/**
* Logical texture resource.
*
* @ingroup resource
*/
class ClientTexture : public res::Texture
{
public:
/**
* Context-specialized variant. Encapsulates all context variant values
* and logics pertaining to a specialized version of the @em superior
* Texture instance.
*
* @see TextureVariantSpec
*/
class Variant
{
public:
enum Flag
{
/// Texture contains alpha.
/// @todo Does not belong here (is actually a source image analysis).
Masked = 0x1
};
Q_DECLARE_FLAGS(Flags, Flag)

/**
* @param texture Base Texture from which the draw-context variant is derived.
* @param spec Draw-context variant specification.
*/
Variant(ClientTexture &texture, TextureVariantSpec const &spec);

public:
/**
* Returns the base Texture for the draw-context variant.
*/
ClientTexture &base() const;

/// Returns @c true if the variant is "prepared".
inline bool isPrepared() const { return glName() != 0; }

/// Returns @c true if the variant is flagged as "masked".
inline bool isMasked() const { return isFlagged(Masked); }

/**
* Prepare the texture variant for render.
*
* @note If a cache miss occurs texture content data may need to be
* (re-)uploaded to GL. However, the actual upload will be deferred
* if possible. This has the side effect that although the variant
* is considered "prepared", attempts to render using the associated
* GL texture will result in "uninitialized" white texels being used
* instead.
*
* @return GL-name of the uploaded texture.
*/
uint prepare();

/**
* Release any uploaded GL-texture and clear the associated GL-name
* for the variant.
*/
void release();

/**
* Returns the specification used to derive the variant.
*/
TextureVariantSpec const &spec() const;

/**
* Returns the source of the image used to prepare the uploaded GL-texture
* for the variant.
*/
res::Source source() const;

/**
* Returns a textual description of the source of the variant.
*
* @return Human-friendly description of the source of the variant.
*/
de::String sourceDescription() const;

/**
* Returns the flags for the variant.
*/
Flags flags() const;

/**
* Returns @c true if the variant is flagged @a flagsToTest.
*/
inline bool isFlagged(Flags flagsToTest) const
{
return (flags() & flagsToTest) != 0;
}

/**
* Returns the GL-name of the uploaded texture content for the variant;
* otherwise @c 0 (not uploaded).
*/
uint glName() const;

/**
* Returns the prepared GL-texture coordinates for the variant.
*
* @param s S axis coordinate.
* @param t T axis coordinate.
*/
void glCoords(float *s, float *t) const;

private:
DENG2_PRIVATE(d)
};

/// A list of variants.
typedef QList<Variant *> Variants;

/**
* Logics for selecting a texture variant instance from the candidates.
*
* @see chooseVariant()
*/
enum ChooseVariantMethod
{
/// The variant specification of the candidate must match exactly.
MatchSpec,

/// The variant specification of the candidate must match however
/// certain properties may vary (e.g., quality arguments) if it means
/// we can avoid creating a new variant.
//FuzzyMatchSpec
};

public:
ClientTexture(res::TextureManifest &manifest);

void release() override;
de::String description() const override;

/**
* Destroys all derived variants for the texture.
*/
void clearVariants();

/**
* Choose/create a variant of the texture which fulfills @a spec.
*
* @param method Method of selection.
* @param spec Texture specialization specification.
* @param canCreate @c true= Create a new variant if no suitable one exists.
*
* @return Chosen variant; otherwise @c NULL if none suitable and not creating.
*/
Variant *chooseVariant(ChooseVariantMethod method,
TextureVariantSpec const &spec,
bool canCreate = false);

/**
* Choose/create a variant of the texture which fulfills @a spec and then
* immediately prepare it for render.
*
* @note A convenient shorthand of the call tree:
* <pre>
* chooseVariant(MatchSpec, @a spec, true)->prepareVariant();
* </pre>
*
* @param spec Specification for the derivation of the texture.
*
* @return The prepared texture variant if successful; otherwise @c 0.
*
* @see chooseVariant()
*/
Variant *prepareVariant(TextureVariantSpec const &spec);

/**
* Provides access to the list of variant instances for efficent traversal.
*/
Variants const &variants() const;

/**
* Returns the number of variants for the texture.
*/
uint variantCount() const;

private:
DENG2_PRIVATE(d)
};

Q_DECLARE_OPERATORS_FOR_FLAGS(ClientTexture::Flags)

typedef ClientTexture::Variant TextureVariant;

#endif // DENG_RESOURCE_CLIENTTEXTURE_H

0 comments on commit 331e2fe

Please sign in to comment.