Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8459361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:18:37+00:00 2026-06-10T13:18:37+00:00

I’m currently working on a project that involves setting an enormous amount of vertex

  • 0

I’m currently working on a project that involves setting an enormous amount of vertex data using VertexPositionTextures. This ends up eating up a lot of memory, and while there’s some optimization I can do as far as what is currently in memory and what can be offloaded to the hard-drive, I would like to optimize in every way possible.

My question then: is there a way I can rewrite the VertexPositionTexture struct such that it uses my custom IntVector classes to use less space? Would this require modifications to DrawPrimitives and DrawUserPrimitives as well?

I ask this because I’m not using a texture atlas, so my UV coordinates are always (0,0),(0,1),(1,0),(1,1) which can be represented without floats, and my vertex positions can be easily represented by integers as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:18:38+00:00Added an answer on June 10, 2026 at 1:18 pm

    Yes, you can do this. You just have to define a custom vertex format and XNA will do the rest.

    The most important thing to keep in mind is that you are limited to using elements in the available VertexElementFormats (MSDN) – noting that the HalfVector formats are not available in the Reach profile (info).

    You probably don’t need to create your own vector types, because XNA already provides implementations for all usable formats in Microsoft.Xna.Framework.Graphics.PackedVector (MSDN) or in the main library. If you do want to create your own type, it needs to be a struct (or loose fields in your vertex) that packs in the same way.

    Finally, it’s worth pointing out that there is no 32-bit int data type. And there would be no benefit, either, because a float (a Single) is the same size at 32 bits. (And some GPUs operate in single-precision, so you wouldn’t get to keep the extra precision anyway.)


    So we’re starting with a VertexPositionTexture containing a Vector3 position (96 bits) and a Vector2 texture coordinate (64 bits) for a total of 160 bits.

    Let’s turn that into a custom IntVertexPositionTexture that contains a Short4 position (64 bits) and a NormalizedShort2 texture coordinate (32 bits) for a total of 96 bits (40% size reduction).

    (If you’re working in 2D, you could use Short2 instead of Short4 and save another 32 bits. There is no Short3.)

    Here’s the code for this vertex type, which is really just a case of knowing what the API expects:

    struct IntVertexPositionTexture : IVertexType
    {
        public Short4 Position;
        public NormalizedShort2 TextureCoordinate;
    
        public IntVertexPositionTexture(Short4 position, NormalizedShort2 textureCoordinate)
        {
            this.Position = position;
            this.TextureCoordinate = textureCoordinate;
        }
    
        public static readonly VertexDeclaration VertexDeclaration = new VertexDeclaration(new VertexElement[]
        {
            new VertexElement(0, VertexElementFormat.Short4, VertexElementUsage.Position, 0),
            new VertexElement(8, VertexElementFormat.NormalizedShort2, VertexElementUsage.TextureCoordinate, 0),
        });
    
        VertexDeclaration IVertexType.VertexDeclaration
        {
            get { return IntVertexPositionTexture.VertexDeclaration; }
        }
    }
    

    The important thing when creating a custom vertex type is to make sure the fields match the order and layout that you specify in the VertexDeclaration (MSDN). How you create your VertexDeclaration should be self-explanatory – just have a look at the MSDN page for VertexElement‘s constructor. The offset of each field is specified in bytes.

    The elementUsage and usageIndex match up to vertex shader semantics in HLSL. So in this custom format we have POSITION0 and TEXCOORD0.

    The use of IVertexType is optional, as you can also pass a VertexDeclaration directly to (for example) a VertexBuffer constructor instead.


    That should be all the info you need if you want to make a different vertex format to the one I’ve provided. For more info, there is a blog post by Shawn Hargreaves that goes into more detail about the API.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.